Skip to content

Commit

Permalink
Catch aws-okta related errors and bubble up user (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianho committed Jun 7, 2019
1 parent afd70f6 commit 577b9f8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func processRegion(ctx context.Context, conf *config.Config, sess *session.Sessi
defer span.End()
span.AddAttributes(trace.StringAttribute(telemetry.FieldRegion, region.AWSRegion))

awsClient := getAWSClient(ctx, conf, sess, region)
awsClient, err := getAWSClient(ctx, conf, sess, region)
if err != nil {
span.AddAttributes(trace.StringAttribute(telemetry.FieldError, err.Error()))
return err
}
username, err := conf.GetAWSUsername(ctx, awsClient)
if err != nil {
span.AddAttributes(trace.StringAttribute(telemetry.FieldError, err.Error()))
Expand All @@ -138,7 +142,7 @@ func processRegion(ctx context.Context, conf *config.Config, sess *session.Sessi
}

// getAWSClient configures an aws client
func getAWSClient(ctx context.Context, conf *config.Config, sess *session.Session, region config.Region) *cziAWS.Client {
func getAWSClient(ctx context.Context, conf *config.Config, sess *session.Session, region config.Region) (*cziAWS.Client, error) {
_, span := trace.StartSpan(ctx, "get_aws_client")
defer span.End()
// for things meant to be run as a user
Expand All @@ -151,7 +155,7 @@ func getAWSClient(ctx context.Context, conf *config.Config, sess *session.Sessio
creds, err := getAWSOktaCredentials(conf)
if err != nil {
log.Errorf("Error in retrieving AWS Okta session credentials: %s.", err.Error())
return nil
return nil, err
}

userConf = &aws.Config{
Expand Down Expand Up @@ -182,7 +186,7 @@ func getAWSClient(ctx context.Context, conf *config.Config, sess *session.Sessio
WithKMS(userConf).
WithSTS(userConf).
WithLambda(lambdaConf)
return awsClient
return awsClient, nil
}

func getAWSOktaCredentials(conf *config.Config) (*credentials.Value, error) {
Expand Down

0 comments on commit 577b9f8

Please sign in to comment.