Skip to content

Commit

Permalink
Merge pull request #386 from coveooss/fix/DT-5209-infinite-loop-sessi…
Browse files Browse the repository at this point in the history
…on-duration

Fix infinite loop when extending role session duration
  • Loading branch information
dblanchette authored Oct 20, 2022
2 parents 6a5aa3d + 64f8fe0 commit c93cfda
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,13 @@ func (config TGFConfig) String() string {

var cachedAwsConfig *aws.Config

func (tgfConfig *TGFConfig) getAwsConfig(assumeRoleDuration time.Duration) (aws.Config, error) {
if cachedAwsConfig != nil {
log.Debug("Using cached AWS config")
return *cachedAwsConfig, nil
}

func (tgfConfig *TGFConfig) loadDefaultConfig(assumeRoleDuration time.Duration) (aws.Config, error) {
log.Debugf("Creating new AWS config (assumeRoleDuration=%s)", assumeRoleDuration)
config, err := awsConfig.LoadDefaultConfig(
return awsConfig.LoadDefaultConfig(
context.TODO(),
awsConfig.WithSharedConfigProfile(tgfConfig.tgf.AwsProfile),
awsConfig.WithLogger(awsLogger),
// The logger level controlled by the --aws-debug flag controls whether or not the logs are shown.
// The logger level controlled by the --aws-debug flag controls whether the logs are shown.
// With that in mind, we just let the AWS SDK blindly log and rely on the logger to decide if it should print or not.
awsConfig.WithClientLogMode(
aws.LogRetries|
Expand All @@ -189,7 +184,15 @@ func (tgfConfig *TGFConfig) getAwsConfig(assumeRoleDuration time.Duration) (aws.
}
}),
)
}

func (tgfConfig *TGFConfig) getAwsConfig(assumeRoleDuration time.Duration) (aws.Config, error) {
if cachedAwsConfig != nil {
log.Debug("Using cached AWS config")
return *cachedAwsConfig, nil
}

config, err := tgfConfig.loadDefaultConfig(assumeRoleDuration)
if err != nil {
return config, err
}
Expand Down Expand Up @@ -217,7 +220,7 @@ func (tgfConfig *TGFConfig) getAwsConfig(assumeRoleDuration time.Duration) (aws.
)

shortConfig := config
config, err = tgfConfig.getAwsConfig(newDuration)
config, err = tgfConfig.loadDefaultConfig(assumeRoleDuration)
if err != nil {
log.Warning("Failed to extend current AWS session, will use the current short duration.", err)
config = shortConfig
Expand Down

0 comments on commit c93cfda

Please sign in to comment.