From 9f8c2ecbd248e29622964affebe907fac8c3761d Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Fri, 13 Nov 2020 14:08:48 -0800 Subject: [PATCH] config: Add a WithRetryer provider helper to the config loader (#897) Adds a WithRetryer configuration provider to the config loader as a convenience helper to set the Retryer on the Config when its being loaded. --- .../config-feature-1605221765957672000.json | 9 +++++ config/codegen/main.go | 1 + config/config.go | 1 + config/provider.go | 33 +++++++++++++++++++ config/provider_assert_test.go | 5 +++ config/resolve.go | 14 ++++++++ 6 files changed, 63 insertions(+) create mode 100644 .changes/next-release/config-feature-1605221765957672000.json diff --git a/.changes/next-release/config-feature-1605221765957672000.json b/.changes/next-release/config-feature-1605221765957672000.json new file mode 100644 index 00000000000..2c5b31b049a --- /dev/null +++ b/.changes/next-release/config-feature-1605221765957672000.json @@ -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 +} \ No newline at end of file diff --git a/config/codegen/main.go b/config/codegen/main.go index 8c46ec62b9a..d1fd1931391 100644 --- a/config/codegen/main.go +++ b/config/codegen/main.go @@ -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{}{ diff --git a/config/config.go b/config/config.go index 7fb51b54c3d..62917156cee 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,7 @@ var defaultAWSConfigResolvers = []awsConfigResolver{ resolveHTTPClient, resolveEndpointResolver, resolveAPIOptions, + resolveRetryer, resolveRegion, // TODO: Add back EC2 Region Resolver Support diff --git a/config/provider.go b/config/provider.go index a316c60bb9d..c9602f9d9bf 100644 --- a/config/provider.go +++ b/config/provider.go @@ -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 +} diff --git a/config/provider_assert_test.go b/config/provider_assert_test.go index f32f0ebae20..ec35b7aa77c 100644 --- a/config/provider_assert_test.go +++ b/config/provider_assert_test.go @@ -56,6 +56,11 @@ var ( _ RegionProvider = WithEC2IMDSRegion{} ) +// RetryProvider implementor assertions +var ( + _ RetryProvider = WithRetryer(nil) +) + // SharedConfigFilesProvider implementor assertions var ( _ SharedConfigFilesProvider = &EnvConfig{} diff --git a/config/resolve.go b/config/resolve.go index db287c6669a..0135c680c91 100644 --- a/config/resolve.go +++ b/config/resolve.go @@ -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 +}