Skip to content

Commit

Permalink
fix crash when aws region is not specified in config
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreZiviani committed Jul 5, 2022
1 parent f128b6e commit 2ae9dd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/sso/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/AndreZiviani/aws-fuzzy/internal/tracing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/common-fate/granted/pkg/browsers"
"github.com/common-fate/granted/pkg/cfaws"
"github.com/common-fate/granted/pkg/config"
"github.com/common-fate/granted/pkg/debug"
opentracing "github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -46,12 +45,20 @@ func (p *Console) OpenBrowser(ctx context.Context, credentials *aws.Credentials)
span, ctx := opentracing.StartSpanFromContext(ctx, "ssorolecreds")
defer span.Finish()

awsProfiles, _ := cfaws.GetProfilesFromDefaultSharedConfig(ctx)
login := Login{}
login.LoadProfiles()
profile, err := login.GetProfile(p.Profile)
if err != nil {
return err
}

profile := awsProfiles[p.Profile]
region := p.Region
if len(profile.AWSConfig.Region) > 0 {
region = profile.AWSConfig.Region
}

browserOpts := browsers.BrowserOpts{Profile: profile.Name}
url, err := browsers.MakeUrl(browsers.SessionFromCredentials(*credentials), browserOpts, "", profile.AWSConfig.Region)
url, err := browsers.MakeUrl(browsers.SessionFromCredentials(*credentials), browserOpts, "", region)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions internal/sso/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Login struct {

type Console struct {
Profile string `short:"p" long:"profile" env:"AWS_PROFILE" default:"default" description:"What profile to use"`
Region string `short:"r" long:"region" env:"AWS_REGION" default:"us-east-1" description:"What region to use"`
Url bool `short:"u" long:"url" description:"Only print login url"`
Verbose bool `short:"v" long:"verbose" description:"Enable verbose messages"`
}
Expand Down

0 comments on commit 2ae9dd9

Please sign in to comment.