Skip to content

Commit

Permalink
Tool 838 dont ignore err in envmanrun (#699)
Browse files Browse the repository at this point in the history
* refactor: secret key-value extraction to function

* log warning if error getting secret key-value pair
  • Loading branch information
lszucs authored Feb 10, 2020
1 parent 9934e80 commit 70d75ce
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,22 @@ func EnvmanClear(envstorePth string) error {
return nil
}

func getSecretValues(secrets []envmanModels.EnvironmentItemModel) []string {
var secretValues []string
for _, secret := range secrets {
key, value, err := secret.GetKeyValuePair()
if err != nil || len(value) < 1 || IsBuiltInFlagTypeKey(key) {
if err != nil {
log.Warnf("Error getting key-value pair from secret (%v): %s", secret, err)
}
continue
}
secretValues = append(secretValues, value)
}

return secretValues
}

// EnvmanRun runs a command through envman.
func EnvmanRun(envstorePth, workDirPth string, cmdArgs []string, timeout time.Duration, secrets []envmanModels.EnvironmentItemModel) (int, error) {
logLevel := log.GetLevel().String()
Expand All @@ -351,16 +367,8 @@ func EnvmanRun(envstorePth, workDirPth string, cmdArgs []string, timeout time.Du
outWriter = os.Stdout
errWriter = os.Stderr
} else {
var secretValues []string
for _, secret := range secrets {
key, value, err := secret.GetKeyValuePair()
if err != nil || len(value) < 1 || IsBuiltInFlagTypeKey(key) {
continue
}
secretValues = append(secretValues, value)
}

outWriter = filterwriter.New(secretValues, os.Stdout)
outWriter = filterwriter.New(getSecretValues(secrets), os.Stdout)
errWriter = outWriter
}

Expand Down

0 comments on commit 70d75ce

Please sign in to comment.