Skip to content

Commit

Permalink
Load default profile from ~/.aws/config (#159)
Browse files Browse the repository at this point in the history
* load default profile as well

* exclude failed profiles from the list

Co-authored-by: Joshua Wilkes <[email protected]>
  • Loading branch information
chrnorm and JoshuaWilkes authored May 8, 2022
1 parent 29f2e0b commit 586c20a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/cfaws/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/bigkevmcd/go-configparser"
"github.com/common-fate/granted/pkg/debug"
"github.com/fatih/color"
)

Expand Down Expand Up @@ -64,7 +65,7 @@ func GetProfilesFromDefaultSharedConfig(ctx context.Context) (CFSharedConfigs, e
continue
}
// Check if the section is prefixed with 'profile ' and that the profile has a name
if strings.HasPrefix(section, "profile ") && len(section) > 8 {
if (strings.HasPrefix(section, "profile ") && len(section) > 8) || section == "default" {
name := strings.TrimPrefix(section, "profile ")
illegalChars := "\\][;'\"" // These characters break the config file format and should not be usable for profile names
if strings.ContainsAny(name, illegalChars) {
Expand All @@ -91,7 +92,13 @@ func GetProfilesFromDefaultSharedConfig(ctx context.Context) (CFSharedConfigs, e

initialisedProfiles := make(map[string]*CFSharedConfig)
for k, profile := range profiles {
initialisedProfiles[k] = profile.CFSharedConfig
// if the profile type is not set, it means there was an error with a source profile
// We exclude it from the profile list so it cannot be assumed
if profile.ProfileType != "" {
initialisedProfiles[k] = profile.CFSharedConfig
} else {
debug.Fprintf(debug.VerbosityDebug, color.Error, "failed to identify profile type for profile: %s", k)
}
}
return initialisedProfiles, nil
}
Expand Down

0 comments on commit 586c20a

Please sign in to comment.