Skip to content

Commit

Permalink
Fix command line arguments and non-AWS profile scoped arguments when …
Browse files Browse the repository at this point in the history
…an AWS profile is not present in the config.

viper.Get() returns an empty string when an AWS profile exists in the config, but has not been set.
viper.Get() returns nil when the AWS profile does not exist in the config or the config file does not exist.
viper.IsSet() returns will return false when the config/profile does not exist, but always returns true when the profile exists (irelevant of whether the actual key is defined).
Combining these two means that:
 * When a config file does not exist or profile is not present in the config, IsSet will return false and the original key is returned.
 * When a config file does exist and the profile exists, but the config key does not exist, Get will return an empty string and the key is returned.
 * When a config file does exist, the profile exists and the key exists, IsSet returns true, Get returns non-empty string and the '<profile>.<config>' key is returned.

Fixes #194

Addresses issue in #192
  • Loading branch information
MatthewJohn committed Feb 27, 2024
1 parent 3981a31 commit 7569bf2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func NewConfig(attrs *Attributes) (*Config, error) {

func getFlagNameFromProfile(awsProfile string, flag string) string {
profileKey := fmt.Sprintf("%s.%s", awsProfile, flag)
if awsProfile != "" && viper.Get(profileKey) != "" {
if awsProfile != "" && viper.IsSet(profileKey) && viper.Get(profileKey) != "" {
// NOTE: If the flag was from a multiple profiles keyed by aws profile
// name i.e. `staging.oidc-client-id`, set the base value to that as
// well, `oidc-client-id`, such that input validation is satisfied.
Expand Down

0 comments on commit 7569bf2

Please sign in to comment.