Skip to content

Commit

Permalink
Correct "default" profile flaw introduced in
Browse files Browse the repository at this point in the history
3186268

Closes #216
  • Loading branch information
monde committed Jul 8, 2024
1 parent f7f2cb0 commit 63de4a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func init() {
{
Name: config.ProfileFlag,
Short: "p",
Value: "default",
Value: "",
Usage: "AWS Profile",
EnvVar: config.ProfileEnvVar,
},
Expand Down
19 changes: 10 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,17 @@ func readConfig() (Attributes, error) {
}
}

// config loading order
// 1) command line flags 2) environment variables, 3) .env file
awsProfile := viper.GetString(ProfileFlag)
// mimic AWS CLI behavior, if profile value is not set by flag check
// the ENV VAR, else set to "default"
if awsProfile == "" {
awsProfile = viper.GetString(downCase(ProfileEnvVar))
}
if awsProfile == "" {
awsProfile = "default"
}

attrs := Attributes{
AllProfiles: viper.GetBool(getFlagNameFromProfile(awsProfile, AllProfilesFlag)),
Expand Down Expand Up @@ -437,15 +447,6 @@ func readConfig() (Attributes, error) {
attrs.Format = EnvVarFormat
}

// mimic AWS CLI behavior, if profile value is not set by flag check
// the ENV VAR, else set to "default"
if attrs.Profile == "" {
attrs.Profile = viper.GetString(downCase(ProfileEnvVar))
}
if attrs.Profile == "" {
attrs.Profile = "default"
}

// Viper binds ENV VARs to a lower snake version, set the configs with them
// if they haven't already been set by cli flag binding.
if attrs.OrgDomain == "" {
Expand Down

0 comments on commit 63de4a8

Please sign in to comment.