Skip to content

Commit

Permalink
granted sso populate create ./aws if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
shwethaumashanker committed Jul 25, 2024
1 parent be4bb77 commit d555205
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/granted/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"sync"

"net/http"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d555205

Please sign in to comment.