Skip to content

Commit

Permalink
Merge pull request #97 from hashicorp/always-log
Browse files Browse the repository at this point in the history
Remove `DebugLogging` parameter from `awsbase.Config` and always enable logging
  • Loading branch information
gdavison authored Feb 2, 2022
2 parents 758d3bd + 4bc4b8a commit 39f6626
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
9 changes: 2 additions & 7 deletions aws_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func commonLoadOptions(c *Config) ([]func(*config.LoadOptions) error, error) {
config.WithRegion(c.Region),
config.WithHTTPClient(httpClient),
config.WithAPIOptions(apiOptions),
config.WithClientLogMode(aws.LogRequestWithBody | aws.LogResponseWithBody | aws.LogRetries),
config.WithLogger(debugLogger{}),
}

if len(c.SharedConfigFiles) > 0 {
Expand All @@ -168,13 +170,6 @@ func commonLoadOptions(c *Config) ([]func(*config.LoadOptions) error, error) {
)
}

if c.DebugLogging {
loadOptions = append(loadOptions,
config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponseWithBody|aws.LogRetries),
config.WithLogger(debugLogger{}),
)
}

if c.EC2MetadataServiceEndpoint != "" {
loadOptions = append(loadOptions,
config.WithEC2IMDSEndpoint(c.EC2MetadataServiceEndpoint),
Expand Down
6 changes: 2 additions & 4 deletions aws_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,8 @@ region = us-east-1
RoleARN: servicemocks.MockStsAssumeRoleArn,
SessionName: servicemocks.MockStsAssumeRoleSessionName,
},
DebugLogging: true,
Region: "us-east-1",
SecretKey: servicemocks.MockStaticSecretKey,
Region: "us-east-1",
SecretKey: servicemocks.MockStaticSecretKey,
},
Description: "assume role error",
ExpectedError: func(err error) bool {
Expand Down Expand Up @@ -2004,7 +2003,6 @@ func TestRetryHandlers(t *testing.T) {
MaxRetries: maxRetries,
SecretKey: servicemocks.MockStaticSecretKey,
SkipCredsValidation: true,
DebugLogging: true,
}
awsConfig, err := GetAwsConfig(context.Background(), config)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type Config struct {
AssumeRole *AssumeRole
CallerDocumentationURL string
CallerName string
DebugLogging bool
EC2MetadataServiceEndpoint string
EC2MetadataServiceEndpointMode string
HTTPProxy string
Expand Down
8 changes: 2 additions & 6 deletions v2/awsv1shim/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,15 @@ func getSessionOptions(awsC *awsv2.Config, c *awsbase.Config) (*session.Options,
creds.SessionToken,
),
HTTPClient: httpClient,
LogLevel: aws.LogLevel(aws.LogDebugWithHTTPBody | aws.LogDebugWithRequestRetries | aws.LogDebugWithRequestErrors),
Logger: debugLogger{},
MaxRetries: aws.Int(0),
Region: aws.String(awsC.Region),
UseFIPSEndpoint: convertFIPSEndpointState(useFIPSEndpoint),
UseDualStackEndpoint: convertDualStackEndpointState(useDualStackEndpoint),
},
}

// This needs its own debug logger. Don't reuse or wrap the AWS SDK for Go v2 logger, since it hardcodes the string "aws-sdk-go-v2"
if c.DebugLogging {
options.Config.LogLevel = aws.LogLevel(aws.LogDebugWithHTTPBody | aws.LogDebugWithRequestRetries | aws.LogDebugWithRequestErrors)
options.Config.Logger = debugLogger{}
}

return options, nil
}

Expand Down
7 changes: 3 additions & 4 deletions v2/awsv1shim/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestGetSessionOptions(t *testing.T) {
false,
},
{"ConfigWithCredsAndOptions",
&awsbase.Config{AccessKey: "MockAccessKey", SecretKey: "MockSecretKey", Insecure: true, DebugLogging: true},
&awsbase.Config{AccessKey: "MockAccessKey", SecretKey: "MockSecretKey", Insecure: true},
false,
},
}
Expand Down Expand Up @@ -799,9 +799,8 @@ region = us-east-1
RoleARN: servicemocks.MockStsAssumeRoleArn,
SessionName: servicemocks.MockStsAssumeRoleSessionName,
},
DebugLogging: true,
Region: "us-east-1",
SecretKey: servicemocks.MockStaticSecretKey,
Region: "us-east-1",
SecretKey: servicemocks.MockStaticSecretKey,
},
Description: "assume role error",
ExpectedError: func(err error) bool {
Expand Down

0 comments on commit 39f6626

Please sign in to comment.