Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

granted sso populate create ~/.aws if it does not exist #714

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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{
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
Loading