Skip to content

Commit

Permalink
console command now honors non-Default AWS SSO instances
Browse files Browse the repository at this point in the history
Users using `--sso` with `eval` or `exec` and then running
`console` would find the latter command would fail because
it did not know which AWS SSO instance was used with the
previous command.

We now set AWS_SSO environment variable so this value is
automatically tracked with `console`, `list`, etc.

Fixes: #208
  • Loading branch information
synfinatic committed Dec 31, 2021
1 parent c4b2ea8 commit 94cca4d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* AccountAlias/AccountName tags are inconsistenly applied/missing #201
* Honor config.yaml `DefaultSSO` #209
* Setup now defaults to `warn` log level instead of `info` #214
* `console` command did not know when you are using a non-Default SSO instance #208

## [1.6.0] - 2021-12-24

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ The following environment variables are specific to `aws-sso`:
* `AWS_SSO_SESSION_EXPIRATION` -- The date and time when the IAM role credentials will expire
* `AWS_SSO_DEFAULT_REGION` -- Tracking variable for `AWS_DEFAULT_REGION`
* `AWS_SSO_PROFILE` -- User customizable varible using the [ProfileFormat](#profileformat) template
* `AWS_SSO` -- AWS SSO instance name

## Release History

Expand Down
1 change: 1 addition & 0 deletions cmd/eval_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func unsetEnvVars(ctx *RunContext) error {
"AWS_SSO_ROLE_ARN",
"AWS_SSO_SESSION_EXPIRATION",
"AWS_SSO_PROFILE",
"AWS_SSO",
}

// clear the region if
Expand Down
3 changes: 2 additions & 1 deletion cmd/exec_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (cc *ExecCmd) Run(ctx *RunContext) error {
return err
}
if err = ctx.Settings.Cache.Expired(sso); err != nil {
log.Warnf(err.Error())
log.Infof(err.Error())
c := &CacheCmd{}
if err = c.Run(ctx); err != nil {
return err
Expand Down Expand Up @@ -165,6 +165,7 @@ func execShellEnvs(ctx *RunContext, awssso *sso.AWSSSO, accountid int64, role, r
"AWS_SSO_ROLE_NAME": creds.RoleName,
"AWS_SSO_SESSION_EXPIRATION": creds.ExpireString(),
"AWS_SSO_ROLE_ARN": utils.MakeRoleARN(creds.AccountId, creds.RoleName),
"AWS_SSO": ctx.Cli.SSO,
}

if len(region) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type CLI struct {
Lines bool `kong:"help='Print line number in logs'"`
LogLevel string `kong:"short='L',name='level',help='Logging level [error|warn|info|debug|trace] (default: info)'"`
UrlAction string `kong:"short='u',help='How to handle URLs [open|print|clip] (default: open)'"`
SSO string `kong:"short='S',help='AWS SSO Instance',env='AWS_SSO',predictor='sso'"`
SSO string `kong:"short='S',help='Override default AWS SSO Instance',env='AWS_SSO',predictor='sso'"`
STSRefresh bool `kong:"help='Force refresh of STS Token Credentials'"`

// Commands
Expand Down
2 changes: 1 addition & 1 deletion sso/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func LoadSettings(configFile, cacheFile string, defaults map[string]interface{},
// load the cache
var err error
if s.Cache, err = OpenCache(s.cacheFile, s); err != nil {
log.Warnf("%s", err.Error())
log.Infof("%s", err.Error())
}

return s, nil
Expand Down

0 comments on commit 94cca4d

Please sign in to comment.