Skip to content

Commit

Permalink
config: Add a WithRetryer provider helper to the config loader (#897)
Browse files Browse the repository at this point in the history
Adds a WithRetryer configuration provider to the config loader as a convenience helper to set the Retryer on the Config when its being loaded.
  • Loading branch information
jasdel authored Nov 13, 2020
1 parent 5b010cb commit 9f8c2ec
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .changes/next-release/config-feature-1605221765957672000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "config-feature-1605221765957672000",
"SchemaVersion": 1,
"Module": "config",
"Type": "feature",
"Description": "Add a WithRetryer provider helper to the config loader",
"MinVersion": "",
"AffectedModules": null
}
1 change: 1 addition & 0 deletions config/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var implAsserts = map[string][]string{
"HTTPClientProvider": {`WithHTTPClient(nil)`},
"AssumeRoleCredentialOptionsProvider": {`WithAssumeRoleCredentialOptions(nil)`},
"WebIdentityRoleCredentialOptionsProvider": {`WithWebIdentityRoleCredentialOptions(nil)`},
"RetryProvider": {`WithRetryer(nil)`},
}

var tplProviderTests = template.Must(template.New("tplProviderTests").Funcs(map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var defaultAWSConfigResolvers = []awsConfigResolver{
resolveHTTPClient,
resolveEndpointResolver,
resolveAPIOptions,
resolveRetryer,

resolveRegion,
// TODO: Add back EC2 Region Resolver Support
Expand Down
33 changes: 33 additions & 0 deletions config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,36 @@ func getLogConfigurationWarnings(configs configs) (v bool, found bool, err error
}
return v, found, err
}

// RetryProvider is an configuration provider for custom Retryer.
type RetryProvider interface {
GetRetryer() (aws.Retryer, bool, error)
}

// WithRetryer returns a RetryProvider for the SDK retryer provided.
func WithRetryer(retryer aws.Retryer) RetryProvider {
return retryProvider{retryer: retryer}
}

type retryProvider struct {
retryer aws.Retryer
}

func (p retryProvider) GetRetryer() (aws.Retryer, bool, error) {
return p.retryer, true, nil
}

func getRetryer(configs configs) (v aws.Retryer, found bool, err error) {
for _, c := range configs {
if p, ok := c.(RetryProvider); ok {
v, found, err = p.GetRetryer()
if err != nil {
return nil, false, err
}
if found {
break
}
}
}
return v, found, err
}
5 changes: 5 additions & 0 deletions config/provider_assert_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions config/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,17 @@ func resolveClientLogMode(cfg *aws.Config, configs configs) error {

return nil
}

func resolveRetryer(cfg *aws.Config, configs configs) error {
retryer, found, err := getRetryer(configs)
if err != nil {
return err
}
if !found {
return nil
}

cfg.Retryer = retryer

return nil
}

0 comments on commit 9f8c2ec

Please sign in to comment.