Skip to content

Commit

Permalink
chore: don’t set default value always
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishagp committed May 19, 2023
1 parent 5346af1 commit 1f0e28f
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,23 @@ func initApplicationConfiguration(config configuration.Configuration) {
config.AddAlternativeKeys(configuration.API_URL, []string{"endpoint"})
config.AddAlternativeKeys(configuration.ADD_TRUSTED_CA_FILE, []string{"NODE_EXTRA_CA_CERTS"})

config.AddDefaultValue(configuration.FF_OAUTH_AUTH_FLOW_ENABLED, func(existingValue any) any {
// if the CONFIG_KEY_OAUTH_TOKEN is specified as env var, we don't apply any additional logic
_, ok := os.LookupEnv(auth.CONFIG_KEY_OAUTH_TOKEN)
if !ok {
alternativeBearerKeys := config.GetAlternativeKeys(configuration.AUTHENTICATION_BEARER_TOKEN)
for _, key := range alternativeBearerKeys {
hasPrefix := strings.HasPrefix(key, "snyk_")
if hasPrefix {
formattedKey := strings.ToUpper(key)
_, ok := os.LookupEnv(formattedKey)
if ok {
debugLogger.Printf("Found environment variable %s, disabling OAuth flow", formattedKey)
return false
}
// if the CONFIG_KEY_OAUTH_TOKEN is specified as env var, we don't apply any additional logic
_, ok := os.LookupEnv(auth.CONFIG_KEY_OAUTH_TOKEN)
if !ok {
alternativeBearerKeys := config.GetAlternativeKeys(configuration.AUTHENTICATION_BEARER_TOKEN)
for _, key := range alternativeBearerKeys {
hasPrefix := strings.HasPrefix(key, "snyk_")
if hasPrefix {
formattedKey := strings.ToUpper(key)
_, ok := os.LookupEnv(formattedKey)
if ok {
debugLogger.Printf("Found environment variable %s, disabling OAuth flow", formattedKey)
config.Set(configuration.FF_OAUTH_AUTH_FLOW_ENABLED, false)
break
}
}
}
return existingValue
})
}
}

func getFullCommandString(cmd *cobra.Command) string {
Expand Down

0 comments on commit 1f0e28f

Please sign in to comment.