fix loading of environment variables for managing aws waiters

This commit is contained in:
Megan Marsh 2018-07-11 13:10:38 -07:00
parent 12f1b2421d
commit 8e22803099
1 changed files with 17 additions and 12 deletions

View File

@ -260,6 +260,20 @@ func getWaiterOptions() []request.WaiterOption {
return waitOpts
}
func getOverride(varInfo envInfo) envInfo {
override := os.Getenv(varInfo.envKey)
if override != "" {
n, err := strconv.Atoi(override)
if err != nil {
log.Printf("Invalid %s '%s', using default", varInfo.envKey, override)
} else {
varInfo.overridden = true
varInfo.Val = n
}
}
return varInfo
}
func getEnvOverrides() overridableWaitVars {
// Load env vars from environment, and use them to override defaults
envValues := overridableWaitVars{
@ -268,18 +282,9 @@ func getEnvOverrides() overridableWaitVars {
envInfo{"AWS_TIMEOUT_SECONDS", 300, false},
}
for _, varInfo := range []envInfo{envValues.awsPollDelaySeconds, envValues.awsMaxAttempts, envValues.awsTimeoutSeconds} {
override := os.Getenv(varInfo.envKey)
if override != "" {
n, err := strconv.Atoi(override)
if err != nil {
log.Printf("Invalid %s '%s', using default", varInfo.envKey, override)
} else {
varInfo.overridden = true
varInfo.Val = n
}
}
}
envValues.awsMaxAttempts = getOverride(envValues.awsMaxAttempts)
envValues.awsPollDelaySeconds = getOverride(envValues.awsPollDelaySeconds)
envValues.awsTimeoutSeconds = getOverride(envValues.awsTimeoutSeconds)
return envValues
}