MCPcopy Create free account
hub / github.com/SignTools/SignTools / parseEnvProfile

Function parseEnvProfile

src/storage/profile_env.go:41–76  ·  view source on GitHub ↗
(cfg *config.EnvProfile)

Source from the content-addressed store, hash-verified

39}
40
41func parseEnvProfile(cfg *config.EnvProfile) (*envProfile, error) {
42 // cfg is empty, no envvars were set
43 if reflect.DeepEqual(cfg, &config.EnvProfile{}) {
44 return nil, os.ErrNotExist
45 }
46 requiredMap := map[string]string{
47 cfg.Name: "name",
48 cfg.CertBase64: "certificate",
49 cfg.CertPass: "certificate password"}
50 for k, v := range requiredMap {
51 if k == "" {
52 return nil, &MissingData{v}
53 }
54 }
55 if cfg.ProvBase64 != "" {
56 log.Info().Msg("importing prov profile from envvars")
57 certBytes, err := decodeVar(cfg.CertBase64)
58 if err != nil {
59 return nil, errors.WithMessage(err, "decode cert base64")
60 }
61 provBytes, err := decodeVar(cfg.ProvBase64)
62 if err != nil {
63 return nil, errors.WithMessage(err, "decode prov base64")
64 }
65 return newEnvProfileProv(uuid.NewString(), cfg, certBytes, provBytes), nil
66 } else if cfg.AccountName != "" && cfg.AccountPass != "" {
67 log.Info().Msg("importing account profile from envvars")
68 certBytes, err := decodeVar(cfg.CertBase64)
69 if err != nil {
70 return nil, errors.WithMessage(err, "decode cert base64")
71 }
72 return newEnvProfileAccount(uuid.NewString(), cfg, certBytes), nil
73 } else {
74 return nil, &MissingData{"provisioning profile or account name and password"}
75 }
76}
77
78func decodeVar(dataStr string) ([]byte, error) {
79 data, err := base64.StdEncoding.DecodeString(dataStr)

Callers 1

newEnvProfileFunction · 0.85

Calls 3

decodeVarFunction · 0.85
newEnvProfileProvFunction · 0.85
newEnvProfileAccountFunction · 0.85

Tested by

no test coverage detected