From d555205b0ee87e18776915dfbed264be012de4e1 Mon Sep 17 00:00:00 2001 From: Shwetha Umashanker <32020525+shwethaumashanker@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:13:51 -0400 Subject: [PATCH] granted sso populate create ./aws if it does not exist --- pkg/granted/sso.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/granted/sso.go b/pkg/granted/sso.go index 1c27eec5..f974f9b1 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/execute. + USER_READ_WRITE_PERM = 0700 +) + // 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,