diff --git a/pkg/granted/sso.go b/pkg/granted/sso.go index 1c27eec5..e4add96e 100644 --- a/pkg/granted/sso.go +++ b/pkg/granted/sso.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "path/filepath" "sync" "net/http" @@ -41,6 +42,11 @@ var SSOCommand = cli.Command{ Subcommands: []*cli.Command{&GenerateCommand, &PopulateCommand, &LoginCommand}, } +const ( + // permission for user to read/write. + USER_READ_WRITE_PERM = 0644 +) + // in dev: // go run ./cmd/granted/main.go sso generate --sso-region ap-southeast-2 [url] var GenerateCommand = cli.Command{ @@ -180,6 +186,16 @@ var PopulateCommand = cli.Command{ configFilename := cfaws.GetAWSConfigPath() + // Create ~/.aws if it does not exists + dir := filepath.Dir(configFilename) + if _, err := os.Stat(dir); os.IsNotExist(err) { + clio.Infof("created AWS config file: %s", dir) + err = os.MkdirAll(dir, USER_READ_WRITE_PERM) + if err != nil { + return err + } + } + config, err := ini.LoadSources(ini.LoadOptions{ AllowNonUniqueSections: false, SkipUnrecognizableLines: false,