diff --git a/internal/protocoltest/awsrestjson/api_client.go b/internal/protocoltest/awsrestjson/api_client.go index 9c9d18af79b..d80d7568eb4 100644 --- a/internal/protocoltest/awsrestjson/api_client.go +++ b/internal/protocoltest/awsrestjson/api_client.go @@ -5,7 +5,9 @@ package awsrestjson import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -39,6 +42,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -63,6 +68,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -83,9 +92,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -113,6 +135,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -165,11 +193,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -179,10 +209,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -210,6 +274,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "restjsonprotocol", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/internal/protocoltest/ec2query/api_client.go b/internal/protocoltest/ec2query/api_client.go index d844b5d9eb6..e237016c5ed 100644 --- a/internal/protocoltest/ec2query/api_client.go +++ b/internal/protocoltest/ec2query/api_client.go @@ -5,7 +5,9 @@ package ec2query import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -39,6 +42,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -63,6 +68,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -83,9 +92,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -113,6 +135,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -165,11 +193,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -179,10 +209,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -210,6 +274,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "ec2protocol", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/internal/protocoltest/jsonrpc/api_client.go b/internal/protocoltest/jsonrpc/api_client.go index 106fb0677b1..04223ab212f 100644 --- a/internal/protocoltest/jsonrpc/api_client.go +++ b/internal/protocoltest/jsonrpc/api_client.go @@ -4,7 +4,9 @@ package jsonrpc import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/internal/protocoltest/jsonrpc10/api_client.go b/internal/protocoltest/jsonrpc10/api_client.go index 5179f18aa1c..286d3049d8c 100644 --- a/internal/protocoltest/jsonrpc10/api_client.go +++ b/internal/protocoltest/jsonrpc10/api_client.go @@ -4,7 +4,9 @@ package jsonrpc10 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -14,6 +16,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -37,6 +40,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -59,6 +64,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -75,9 +84,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -105,6 +127,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -157,11 +185,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -171,10 +201,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -202,6 +266,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "jsonrpc10", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/internal/protocoltest/query/api_client.go b/internal/protocoltest/query/api_client.go index c31a406a709..2bcf4193b8a 100644 --- a/internal/protocoltest/query/api_client.go +++ b/internal/protocoltest/query/api_client.go @@ -5,7 +5,9 @@ package query import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -39,6 +42,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -63,6 +68,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -83,9 +92,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -113,6 +135,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -165,11 +193,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -179,10 +209,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -210,6 +274,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "queryprotocol", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/internal/protocoltest/restxml/api_client.go b/internal/protocoltest/restxml/api_client.go index f302d53aa9a..c91bab45aa6 100644 --- a/internal/protocoltest/restxml/api_client.go +++ b/internal/protocoltest/restxml/api_client.go @@ -5,7 +5,9 @@ package restxml import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -39,6 +42,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -63,6 +68,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -83,9 +92,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -113,6 +135,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -165,11 +193,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -179,10 +209,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -210,6 +274,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "restxmlprotocol", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/internal/protocoltest/restxmlwithnamespace/api_client.go b/internal/protocoltest/restxmlwithnamespace/api_client.go index 2e90b4d5219..310e8190643 100644 --- a/internal/protocoltest/restxmlwithnamespace/api_client.go +++ b/internal/protocoltest/restxmlwithnamespace/api_client.go @@ -4,7 +4,9 @@ package restxmlwithnamespace import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -14,6 +16,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" ) @@ -37,6 +40,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPClient(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -59,6 +64,10 @@ type Options struct { // Configures the events that will be sent to the configured logger. ClientLogMode aws.ClientLogMode + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -75,9 +84,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -105,6 +127,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -157,11 +185,13 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -171,10 +201,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -202,6 +266,21 @@ func addClientUserAgent(stack *middleware.Stack) error { return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "restxmlprotocolnamespace", goModuleVersion)(stack) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/accessanalyzer/api_client.go b/service/accessanalyzer/api_client.go index 44a3ab0c94d..65aeb02d209 100644 --- a/service/accessanalyzer/api_client.go +++ b/service/accessanalyzer/api_client.go @@ -5,7 +5,9 @@ package accessanalyzer import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/account/api_client.go b/service/account/api_client.go index a0897068f39..b81392f4a31 100644 --- a/service/account/api_client.go +++ b/service/account/api_client.go @@ -4,7 +4,9 @@ package account import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/acm/api_client.go b/service/acm/api_client.go index c0a80409b38..d322b733399 100644 --- a/service/acm/api_client.go +++ b/service/acm/api_client.go @@ -4,7 +4,9 @@ package acm import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/acmpca/api_client.go b/service/acmpca/api_client.go index c913621ef75..d652f259ada 100644 --- a/service/acmpca/api_client.go +++ b/service/acmpca/api_client.go @@ -4,7 +4,9 @@ package acmpca import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/alexaforbusiness/api_client.go b/service/alexaforbusiness/api_client.go index cb345b016b9..7d7edcaff4c 100644 --- a/service/alexaforbusiness/api_client.go +++ b/service/alexaforbusiness/api_client.go @@ -5,7 +5,9 @@ package alexaforbusiness import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/amp/api_client.go b/service/amp/api_client.go index 570186959c0..26d464ebabf 100644 --- a/service/amp/api_client.go +++ b/service/amp/api_client.go @@ -5,7 +5,9 @@ package amp import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/amplify/api_client.go b/service/amplify/api_client.go index b3b7820d6d0..8e98659b724 100644 --- a/service/amplify/api_client.go +++ b/service/amplify/api_client.go @@ -4,7 +4,9 @@ package amplify import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/amplifybackend/api_client.go b/service/amplifybackend/api_client.go index 7f4e7c0d945..062206a14e2 100644 --- a/service/amplifybackend/api_client.go +++ b/service/amplifybackend/api_client.go @@ -4,7 +4,9 @@ package amplifybackend import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/amplifyuibuilder/api_client.go b/service/amplifyuibuilder/api_client.go index 9d09abc3ddf..5ac28747e0e 100644 --- a/service/amplifyuibuilder/api_client.go +++ b/service/amplifyuibuilder/api_client.go @@ -5,7 +5,9 @@ package amplifyuibuilder import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/apigateway/api_client.go b/service/apigateway/api_client.go index ac94db1a410..a475ed1ebb4 100644 --- a/service/apigateway/api_client.go +++ b/service/apigateway/api_client.go @@ -4,7 +4,9 @@ package apigateway import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/apigatewaymanagementapi/api_client.go b/service/apigatewaymanagementapi/api_client.go index 1ef14f6451f..e823d39bccc 100644 --- a/service/apigatewaymanagementapi/api_client.go +++ b/service/apigatewaymanagementapi/api_client.go @@ -4,7 +4,9 @@ package apigatewaymanagementapi import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/apigatewayv2/api_client.go b/service/apigatewayv2/api_client.go index 9256661e8e2..b4372ed99ff 100644 --- a/service/apigatewayv2/api_client.go +++ b/service/apigatewayv2/api_client.go @@ -4,7 +4,9 @@ package apigatewayv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appconfig/api_client.go b/service/appconfig/api_client.go index c4c2283e37a..eb5e5d50798 100644 --- a/service/appconfig/api_client.go +++ b/service/appconfig/api_client.go @@ -4,7 +4,9 @@ package appconfig import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appconfigdata/api_client.go b/service/appconfigdata/api_client.go index 9d913425dc6..753f3f7950a 100644 --- a/service/appconfigdata/api_client.go +++ b/service/appconfigdata/api_client.go @@ -4,7 +4,9 @@ package appconfigdata import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appflow/api_client.go b/service/appflow/api_client.go index 0ec64afa024..44df58906cb 100644 --- a/service/appflow/api_client.go +++ b/service/appflow/api_client.go @@ -4,7 +4,9 @@ package appflow import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appintegrations/api_client.go b/service/appintegrations/api_client.go index f4ae9bb710d..86b9fe2f32f 100644 --- a/service/appintegrations/api_client.go +++ b/service/appintegrations/api_client.go @@ -5,7 +5,9 @@ package appintegrations import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/applicationautoscaling/api_client.go b/service/applicationautoscaling/api_client.go index e87573caadc..f41f82aa849 100644 --- a/service/applicationautoscaling/api_client.go +++ b/service/applicationautoscaling/api_client.go @@ -4,7 +4,9 @@ package applicationautoscaling import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/applicationcostprofiler/api_client.go b/service/applicationcostprofiler/api_client.go index 5a5297b960b..d80f7b1025e 100644 --- a/service/applicationcostprofiler/api_client.go +++ b/service/applicationcostprofiler/api_client.go @@ -4,7 +4,9 @@ package applicationcostprofiler import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/applicationdiscoveryservice/api_client.go b/service/applicationdiscoveryservice/api_client.go index 0a8000caf0e..fc46b9b6391 100644 --- a/service/applicationdiscoveryservice/api_client.go +++ b/service/applicationdiscoveryservice/api_client.go @@ -5,7 +5,9 @@ package applicationdiscoveryservice import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/applicationinsights/api_client.go b/service/applicationinsights/api_client.go index 821f8d47227..28feff58dc3 100644 --- a/service/applicationinsights/api_client.go +++ b/service/applicationinsights/api_client.go @@ -4,7 +4,9 @@ package applicationinsights import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appmesh/api_client.go b/service/appmesh/api_client.go index 0a27789e847..a1f08158c84 100644 --- a/service/appmesh/api_client.go +++ b/service/appmesh/api_client.go @@ -5,7 +5,9 @@ package appmesh import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/apprunner/api_client.go b/service/apprunner/api_client.go index aa9ede04fc8..6c2704ac3da 100644 --- a/service/apprunner/api_client.go +++ b/service/apprunner/api_client.go @@ -4,7 +4,9 @@ package apprunner import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appstream/api_client.go b/service/appstream/api_client.go index 5e7d2d8dcde..f5d64e2e7c2 100644 --- a/service/appstream/api_client.go +++ b/service/appstream/api_client.go @@ -4,7 +4,9 @@ package appstream import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/appsync/api_client.go b/service/appsync/api_client.go index e176d389875..3cb9eb5a2d6 100644 --- a/service/appsync/api_client.go +++ b/service/appsync/api_client.go @@ -4,7 +4,9 @@ package appsync import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/athena/api_client.go b/service/athena/api_client.go index 91212217814..6807056f94e 100644 --- a/service/athena/api_client.go +++ b/service/athena/api_client.go @@ -5,7 +5,9 @@ package athena import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/auditmanager/api_client.go b/service/auditmanager/api_client.go index 29fcebe863a..9d449b2f34a 100644 --- a/service/auditmanager/api_client.go +++ b/service/auditmanager/api_client.go @@ -4,7 +4,9 @@ package auditmanager import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/autoscaling/api_client.go b/service/autoscaling/api_client.go index dcff6e8b9ec..3e55fbe5dd4 100644 --- a/service/autoscaling/api_client.go +++ b/service/autoscaling/api_client.go @@ -4,7 +4,9 @@ package autoscaling import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/autoscalingplans/api_client.go b/service/autoscalingplans/api_client.go index eb7748a7370..98c7e4c1fa6 100644 --- a/service/autoscalingplans/api_client.go +++ b/service/autoscalingplans/api_client.go @@ -4,7 +4,9 @@ package autoscalingplans import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/backup/api_client.go b/service/backup/api_client.go index e612eceabf7..de5735cd31e 100644 --- a/service/backup/api_client.go +++ b/service/backup/api_client.go @@ -5,7 +5,9 @@ package backup import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/backupgateway/api_client.go b/service/backupgateway/api_client.go index 57e3484333e..44c77bc040a 100644 --- a/service/backupgateway/api_client.go +++ b/service/backupgateway/api_client.go @@ -4,7 +4,9 @@ package backupgateway import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/batch/api_client.go b/service/batch/api_client.go index a72364711b4..72d0e60e680 100644 --- a/service/batch/api_client.go +++ b/service/batch/api_client.go @@ -4,7 +4,9 @@ package batch import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/braket/api_client.go b/service/braket/api_client.go index 8015f508356..9d547dcba72 100644 --- a/service/braket/api_client.go +++ b/service/braket/api_client.go @@ -5,7 +5,9 @@ package braket import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/budgets/api_client.go b/service/budgets/api_client.go index 61d8114f547..1dfa5aad153 100644 --- a/service/budgets/api_client.go +++ b/service/budgets/api_client.go @@ -4,7 +4,9 @@ package budgets import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/chime/api_client.go b/service/chime/api_client.go index 3c557703877..25e94342728 100644 --- a/service/chime/api_client.go +++ b/service/chime/api_client.go @@ -5,7 +5,9 @@ package chime import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/chimesdkidentity/api_client.go b/service/chimesdkidentity/api_client.go index 311800a5333..242f64c84bb 100644 --- a/service/chimesdkidentity/api_client.go +++ b/service/chimesdkidentity/api_client.go @@ -5,7 +5,9 @@ package chimesdkidentity import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/chimesdkmeetings/api_client.go b/service/chimesdkmeetings/api_client.go index a389ca3de85..f4984e0ce35 100644 --- a/service/chimesdkmeetings/api_client.go +++ b/service/chimesdkmeetings/api_client.go @@ -5,7 +5,9 @@ package chimesdkmeetings import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/chimesdkmessaging/api_client.go b/service/chimesdkmessaging/api_client.go index 076ee61fdcc..c7a1f0af06b 100644 --- a/service/chimesdkmessaging/api_client.go +++ b/service/chimesdkmessaging/api_client.go @@ -5,7 +5,9 @@ package chimesdkmessaging import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/cloud9/api_client.go b/service/cloud9/api_client.go index d7d60ea97a6..50f7aaeb44e 100644 --- a/service/cloud9/api_client.go +++ b/service/cloud9/api_client.go @@ -4,7 +4,9 @@ package cloud9 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudcontrol/api_client.go b/service/cloudcontrol/api_client.go index f8c3012adbd..faa3f5dc44b 100644 --- a/service/cloudcontrol/api_client.go +++ b/service/cloudcontrol/api_client.go @@ -5,7 +5,9 @@ package cloudcontrol import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/clouddirectory/api_client.go b/service/clouddirectory/api_client.go index 7817f013f4c..02476c1d5da 100644 --- a/service/clouddirectory/api_client.go +++ b/service/clouddirectory/api_client.go @@ -4,7 +4,9 @@ package clouddirectory import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudformation/api_client.go b/service/cloudformation/api_client.go index ff3df5de72c..fe7244d95a2 100644 --- a/service/cloudformation/api_client.go +++ b/service/cloudformation/api_client.go @@ -5,7 +5,9 @@ package cloudformation import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/cloudfront/api_client.go b/service/cloudfront/api_client.go index bdabcd0a6fc..dc408730adc 100644 --- a/service/cloudfront/api_client.go +++ b/service/cloudfront/api_client.go @@ -4,7 +4,9 @@ package cloudfront import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudhsm/api_client.go b/service/cloudhsm/api_client.go index ae1ade94c7f..e244340b97d 100644 --- a/service/cloudhsm/api_client.go +++ b/service/cloudhsm/api_client.go @@ -4,7 +4,9 @@ package cloudhsm import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudhsmv2/api_client.go b/service/cloudhsmv2/api_client.go index 1b540d7e85e..af2f487fe10 100644 --- a/service/cloudhsmv2/api_client.go +++ b/service/cloudhsmv2/api_client.go @@ -4,7 +4,9 @@ package cloudhsmv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudsearch/api_client.go b/service/cloudsearch/api_client.go index 9138e32da6a..91a3c03abae 100644 --- a/service/cloudsearch/api_client.go +++ b/service/cloudsearch/api_client.go @@ -4,7 +4,9 @@ package cloudsearch import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudsearchdomain/api_client.go b/service/cloudsearchdomain/api_client.go index fe20221e480..86f82aa1338 100644 --- a/service/cloudsearchdomain/api_client.go +++ b/service/cloudsearchdomain/api_client.go @@ -4,7 +4,9 @@ package cloudsearchdomain import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudtrail/api_client.go b/service/cloudtrail/api_client.go index 22dcd7fc398..95549ea6ba9 100644 --- a/service/cloudtrail/api_client.go +++ b/service/cloudtrail/api_client.go @@ -4,7 +4,9 @@ package cloudtrail import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudwatch/api_client.go b/service/cloudwatch/api_client.go index 8e66303ae92..2b1ef2b7c72 100644 --- a/service/cloudwatch/api_client.go +++ b/service/cloudwatch/api_client.go @@ -4,7 +4,9 @@ package cloudwatch import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudwatchevents/api_client.go b/service/cloudwatchevents/api_client.go index be1d80022f4..f9644c77b0a 100644 --- a/service/cloudwatchevents/api_client.go +++ b/service/cloudwatchevents/api_client.go @@ -4,7 +4,9 @@ package cloudwatchevents import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cloudwatchlogs/api_client.go b/service/cloudwatchlogs/api_client.go index 768ac315da9..25909a8a201 100644 --- a/service/cloudwatchlogs/api_client.go +++ b/service/cloudwatchlogs/api_client.go @@ -4,7 +4,9 @@ package cloudwatchlogs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codeartifact/api_client.go b/service/codeartifact/api_client.go index fe21458ee14..1108f2d4e52 100644 --- a/service/codeartifact/api_client.go +++ b/service/codeartifact/api_client.go @@ -4,7 +4,9 @@ package codeartifact import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codebuild/api_client.go b/service/codebuild/api_client.go index 9b7e7072ccc..91622db1d12 100644 --- a/service/codebuild/api_client.go +++ b/service/codebuild/api_client.go @@ -4,7 +4,9 @@ package codebuild import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codecommit/api_client.go b/service/codecommit/api_client.go index 05b94644813..8000aa02ba3 100644 --- a/service/codecommit/api_client.go +++ b/service/codecommit/api_client.go @@ -5,7 +5,9 @@ package codecommit import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/codedeploy/api_client.go b/service/codedeploy/api_client.go index e06eb13a948..3f74b96fb19 100644 --- a/service/codedeploy/api_client.go +++ b/service/codedeploy/api_client.go @@ -4,7 +4,9 @@ package codedeploy import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codeguruprofiler/api_client.go b/service/codeguruprofiler/api_client.go index da9b44f7d87..385068f073a 100644 --- a/service/codeguruprofiler/api_client.go +++ b/service/codeguruprofiler/api_client.go @@ -5,7 +5,9 @@ package codeguruprofiler import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/codegurureviewer/api_client.go b/service/codegurureviewer/api_client.go index b54d180ad4c..330acca3889 100644 --- a/service/codegurureviewer/api_client.go +++ b/service/codegurureviewer/api_client.go @@ -5,7 +5,9 @@ package codegurureviewer import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/codepipeline/api_client.go b/service/codepipeline/api_client.go index b8441bf4c95..41f20f4ca1c 100644 --- a/service/codepipeline/api_client.go +++ b/service/codepipeline/api_client.go @@ -5,7 +5,9 @@ package codepipeline import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/codestar/api_client.go b/service/codestar/api_client.go index 50fb4294397..a5207319f6b 100644 --- a/service/codestar/api_client.go +++ b/service/codestar/api_client.go @@ -4,7 +4,9 @@ package codestar import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codestarconnections/api_client.go b/service/codestarconnections/api_client.go index 491bfb02d25..ee1c888683a 100644 --- a/service/codestarconnections/api_client.go +++ b/service/codestarconnections/api_client.go @@ -4,7 +4,9 @@ package codestarconnections import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/codestarnotifications/api_client.go b/service/codestarnotifications/api_client.go index 9dec52c518a..0c436834785 100644 --- a/service/codestarnotifications/api_client.go +++ b/service/codestarnotifications/api_client.go @@ -5,7 +5,9 @@ package codestarnotifications import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/cognitoidentity/api_client.go b/service/cognitoidentity/api_client.go index e6bda298e87..3ffbd9eeb75 100644 --- a/service/cognitoidentity/api_client.go +++ b/service/cognitoidentity/api_client.go @@ -4,7 +4,9 @@ package cognitoidentity import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cognitoidentityprovider/api_client.go b/service/cognitoidentityprovider/api_client.go index a45093bd0f3..3996f8c4f21 100644 --- a/service/cognitoidentityprovider/api_client.go +++ b/service/cognitoidentityprovider/api_client.go @@ -4,7 +4,9 @@ package cognitoidentityprovider import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/cognitosync/api_client.go b/service/cognitosync/api_client.go index aff1c509165..716a1659d08 100644 --- a/service/cognitosync/api_client.go +++ b/service/cognitosync/api_client.go @@ -4,7 +4,9 @@ package cognitosync import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/comprehend/api_client.go b/service/comprehend/api_client.go index 449059f04ae..40a03596b26 100644 --- a/service/comprehend/api_client.go +++ b/service/comprehend/api_client.go @@ -5,7 +5,9 @@ package comprehend import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/comprehendmedical/api_client.go b/service/comprehendmedical/api_client.go index b69493fa786..67b7c56a160 100644 --- a/service/comprehendmedical/api_client.go +++ b/service/comprehendmedical/api_client.go @@ -5,7 +5,9 @@ package comprehendmedical import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/computeoptimizer/api_client.go b/service/computeoptimizer/api_client.go index b2400605665..bbb020610c0 100644 --- a/service/computeoptimizer/api_client.go +++ b/service/computeoptimizer/api_client.go @@ -4,7 +4,9 @@ package computeoptimizer import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/configservice/api_client.go b/service/configservice/api_client.go index 9a53484e8d7..a38dd9b9934 100644 --- a/service/configservice/api_client.go +++ b/service/configservice/api_client.go @@ -4,7 +4,9 @@ package configservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/connect/api_client.go b/service/connect/api_client.go index 9ae527750cf..02f80c10cf9 100644 --- a/service/connect/api_client.go +++ b/service/connect/api_client.go @@ -5,7 +5,9 @@ package connect import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/connectcontactlens/api_client.go b/service/connectcontactlens/api_client.go index dc36e52bd3e..d33a92059f4 100644 --- a/service/connectcontactlens/api_client.go +++ b/service/connectcontactlens/api_client.go @@ -4,7 +4,9 @@ package connectcontactlens import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/connectparticipant/api_client.go b/service/connectparticipant/api_client.go index 26382553f90..7e329add5c8 100644 --- a/service/connectparticipant/api_client.go +++ b/service/connectparticipant/api_client.go @@ -5,7 +5,9 @@ package connectparticipant import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/costandusagereportservice/api_client.go b/service/costandusagereportservice/api_client.go index 6b6121a19cd..9fc77636269 100644 --- a/service/costandusagereportservice/api_client.go +++ b/service/costandusagereportservice/api_client.go @@ -4,7 +4,9 @@ package costandusagereportservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/costexplorer/api_client.go b/service/costexplorer/api_client.go index aa1a0366030..3970de08c96 100644 --- a/service/costexplorer/api_client.go +++ b/service/costexplorer/api_client.go @@ -4,7 +4,9 @@ package costexplorer import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/customerprofiles/api_client.go b/service/customerprofiles/api_client.go index 755e045bf17..3ecb68e193f 100644 --- a/service/customerprofiles/api_client.go +++ b/service/customerprofiles/api_client.go @@ -4,7 +4,9 @@ package customerprofiles import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/databasemigrationservice/api_client.go b/service/databasemigrationservice/api_client.go index 26c6a076844..39f5718b1ef 100644 --- a/service/databasemigrationservice/api_client.go +++ b/service/databasemigrationservice/api_client.go @@ -4,7 +4,9 @@ package databasemigrationservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/databrew/api_client.go b/service/databrew/api_client.go index b44a2bacd65..984e18b90b6 100644 --- a/service/databrew/api_client.go +++ b/service/databrew/api_client.go @@ -4,7 +4,9 @@ package databrew import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/dataexchange/api_client.go b/service/dataexchange/api_client.go index 97e3612eb05..d0701715b5b 100644 --- a/service/dataexchange/api_client.go +++ b/service/dataexchange/api_client.go @@ -4,7 +4,9 @@ package dataexchange import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/datapipeline/api_client.go b/service/datapipeline/api_client.go index a8af747d866..4dd58c5329f 100644 --- a/service/datapipeline/api_client.go +++ b/service/datapipeline/api_client.go @@ -4,7 +4,9 @@ package datapipeline import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/datasync/api_client.go b/service/datasync/api_client.go index 303e6293e6f..77210ef534d 100644 --- a/service/datasync/api_client.go +++ b/service/datasync/api_client.go @@ -4,7 +4,9 @@ package datasync import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/dax/api_client.go b/service/dax/api_client.go index 815a27f49ed..61971ad73ed 100644 --- a/service/dax/api_client.go +++ b/service/dax/api_client.go @@ -4,7 +4,9 @@ package dax import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/detective/api_client.go b/service/detective/api_client.go index c64a2eea679..e7915d4ef08 100644 --- a/service/detective/api_client.go +++ b/service/detective/api_client.go @@ -4,7 +4,9 @@ package detective import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/devicefarm/api_client.go b/service/devicefarm/api_client.go index c80899620fe..6f277d2ad37 100644 --- a/service/devicefarm/api_client.go +++ b/service/devicefarm/api_client.go @@ -4,7 +4,9 @@ package devicefarm import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/devopsguru/api_client.go b/service/devopsguru/api_client.go index b33944376ae..e2071356c5c 100644 --- a/service/devopsguru/api_client.go +++ b/service/devopsguru/api_client.go @@ -5,7 +5,9 @@ package devopsguru import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/directconnect/api_client.go b/service/directconnect/api_client.go index 941ecf1afa3..06cfdcd745c 100644 --- a/service/directconnect/api_client.go +++ b/service/directconnect/api_client.go @@ -4,7 +4,9 @@ package directconnect import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/directoryservice/api_client.go b/service/directoryservice/api_client.go index 3e384865aff..fb9cb17c73f 100644 --- a/service/directoryservice/api_client.go +++ b/service/directoryservice/api_client.go @@ -4,7 +4,9 @@ package directoryservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/dlm/api_client.go b/service/dlm/api_client.go index be8d8de18c7..b4593b1164a 100644 --- a/service/dlm/api_client.go +++ b/service/dlm/api_client.go @@ -4,7 +4,9 @@ package dlm import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/docdb/api_client.go b/service/docdb/api_client.go index edd3a633c77..977403391b8 100644 --- a/service/docdb/api_client.go +++ b/service/docdb/api_client.go @@ -4,7 +4,9 @@ package docdb import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/protocol/query" "github.com/aws/aws-sdk-go-v2/aws/retry" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -69,6 +74,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -88,9 +97,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -118,6 +140,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +198,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +215,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +307,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/drs/api_client.go b/service/drs/api_client.go index 6cec3dc8ee8..27fd7615527 100644 --- a/service/drs/api_client.go +++ b/service/drs/api_client.go @@ -4,7 +4,9 @@ package drs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/dynamodb/api_client.go b/service/dynamodb/api_client.go index 94bce94fa51..bb6b0167b73 100644 --- a/service/dynamodb/api_client.go +++ b/service/dynamodb/api_client.go @@ -7,6 +7,7 @@ import ( cryptorand "crypto/rand" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -21,6 +22,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "net/url" "strings" @@ -52,6 +54,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -83,6 +87,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // Allows you to disable the client's validation of response integrity using CRC32 // checksum. Enabled by default. DisableValidateResponseChecksum bool @@ -117,9 +125,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -147,6 +168,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -199,12 +226,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -215,10 +244,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -273,6 +336,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/dynamodbstreams/api_client.go b/service/dynamodbstreams/api_client.go index 40c54cf8298..46defa4a314 100644 --- a/service/dynamodbstreams/api_client.go +++ b/service/dynamodbstreams/api_client.go @@ -4,7 +4,9 @@ package dynamodbstreams import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ebs/api_client.go b/service/ebs/api_client.go index 180d11903bd..05d236fc1af 100644 --- a/service/ebs/api_client.go +++ b/service/ebs/api_client.go @@ -5,7 +5,9 @@ package ebs import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/ec2/api_client.go b/service/ec2/api_client.go index 2c87c12b43a..80a488e923b 100644 --- a/service/ec2/api_client.go +++ b/service/ec2/api_client.go @@ -5,7 +5,9 @@ package ec2 import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/protocol/query" "github.com/aws/aws-sdk-go-v2/aws/retry" @@ -19,6 +21,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -46,6 +49,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -73,6 +78,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -96,9 +105,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -126,6 +148,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -178,12 +206,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -193,10 +223,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -251,6 +315,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/ec2instanceconnect/api_client.go b/service/ec2instanceconnect/api_client.go index 0126d4d8031..907827f5639 100644 --- a/service/ec2instanceconnect/api_client.go +++ b/service/ec2instanceconnect/api_client.go @@ -4,7 +4,9 @@ package ec2instanceconnect import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ecr/api_client.go b/service/ecr/api_client.go index 4e274f2714c..92d8d951b82 100644 --- a/service/ecr/api_client.go +++ b/service/ecr/api_client.go @@ -4,7 +4,9 @@ package ecr import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ecrpublic/api_client.go b/service/ecrpublic/api_client.go index d8e2f569ba5..8dd3ffb77ab 100644 --- a/service/ecrpublic/api_client.go +++ b/service/ecrpublic/api_client.go @@ -4,7 +4,9 @@ package ecrpublic import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ecs/api_client.go b/service/ecs/api_client.go index 55ae6a0c909..1207ac34b5a 100644 --- a/service/ecs/api_client.go +++ b/service/ecs/api_client.go @@ -4,7 +4,9 @@ package ecs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/efs/api_client.go b/service/efs/api_client.go index c7660c5a7dc..a7b17c9ea4c 100644 --- a/service/efs/api_client.go +++ b/service/efs/api_client.go @@ -5,7 +5,9 @@ package efs import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/eks/api_client.go b/service/eks/api_client.go index 63f36e5f571..0f10ed89529 100644 --- a/service/eks/api_client.go +++ b/service/eks/api_client.go @@ -5,7 +5,9 @@ package eks import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/elasticache/api_client.go b/service/elasticache/api_client.go index 3b5a3121327..812fe3e0c1a 100644 --- a/service/elasticache/api_client.go +++ b/service/elasticache/api_client.go @@ -4,7 +4,9 @@ package elasticache import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elasticbeanstalk/api_client.go b/service/elasticbeanstalk/api_client.go index dd62e68f9c6..0191039cd56 100644 --- a/service/elasticbeanstalk/api_client.go +++ b/service/elasticbeanstalk/api_client.go @@ -4,7 +4,9 @@ package elasticbeanstalk import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elasticinference/api_client.go b/service/elasticinference/api_client.go index ed1322fc8cc..0df707455a6 100644 --- a/service/elasticinference/api_client.go +++ b/service/elasticinference/api_client.go @@ -4,7 +4,9 @@ package elasticinference import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elasticloadbalancing/api_client.go b/service/elasticloadbalancing/api_client.go index 5f6a55a5767..30cb56f1021 100644 --- a/service/elasticloadbalancing/api_client.go +++ b/service/elasticloadbalancing/api_client.go @@ -4,7 +4,9 @@ package elasticloadbalancing import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elasticloadbalancingv2/api_client.go b/service/elasticloadbalancingv2/api_client.go index e5691ba35bc..5a8dffb86d7 100644 --- a/service/elasticloadbalancingv2/api_client.go +++ b/service/elasticloadbalancingv2/api_client.go @@ -4,7 +4,9 @@ package elasticloadbalancingv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elasticsearchservice/api_client.go b/service/elasticsearchservice/api_client.go index eb281eb41ca..463bff401c0 100644 --- a/service/elasticsearchservice/api_client.go +++ b/service/elasticsearchservice/api_client.go @@ -4,7 +4,9 @@ package elasticsearchservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/elastictranscoder/api_client.go b/service/elastictranscoder/api_client.go index 7eefaef0c5a..04e94433210 100644 --- a/service/elastictranscoder/api_client.go +++ b/service/elastictranscoder/api_client.go @@ -4,7 +4,9 @@ package elastictranscoder import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/emr/api_client.go b/service/emr/api_client.go index 32d7d776571..c47ba4ee21a 100644 --- a/service/emr/api_client.go +++ b/service/emr/api_client.go @@ -4,7 +4,9 @@ package emr import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/emrcontainers/api_client.go b/service/emrcontainers/api_client.go index 14599345160..7ccf5849cb6 100644 --- a/service/emrcontainers/api_client.go +++ b/service/emrcontainers/api_client.go @@ -5,7 +5,9 @@ package emrcontainers import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/eventbridge/api_client.go b/service/eventbridge/api_client.go index 8819268177c..991c6959604 100644 --- a/service/eventbridge/api_client.go +++ b/service/eventbridge/api_client.go @@ -4,7 +4,9 @@ package eventbridge import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/evidently/api_client.go b/service/evidently/api_client.go index b184f799906..b05680e6e76 100644 --- a/service/evidently/api_client.go +++ b/service/evidently/api_client.go @@ -4,7 +4,9 @@ package evidently import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/finspace/api_client.go b/service/finspace/api_client.go index 8feed162ee5..9fe699f9fe2 100644 --- a/service/finspace/api_client.go +++ b/service/finspace/api_client.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -16,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "strings" "time" @@ -44,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -69,6 +73,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -88,9 +96,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -118,6 +139,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +197,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +214,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +306,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/finspacedata/api_client.go b/service/finspacedata/api_client.go index 46d9d6d6b22..905ee8c548a 100644 --- a/service/finspacedata/api_client.go +++ b/service/finspacedata/api_client.go @@ -7,6 +7,7 @@ import ( cryptorand "crypto/rand" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -18,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "strings" "time" @@ -45,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -72,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -95,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -125,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -177,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -192,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -250,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/firehose/api_client.go b/service/firehose/api_client.go index 55995909886..649ee17662a 100644 --- a/service/firehose/api_client.go +++ b/service/firehose/api_client.go @@ -4,7 +4,9 @@ package firehose import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/fis/api_client.go b/service/fis/api_client.go index 0d798f8bc2a..bf9d904fd83 100644 --- a/service/fis/api_client.go +++ b/service/fis/api_client.go @@ -5,7 +5,9 @@ package fis import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/fms/api_client.go b/service/fms/api_client.go index 5804b3b2373..7ececf9b547 100644 --- a/service/fms/api_client.go +++ b/service/fms/api_client.go @@ -4,7 +4,9 @@ package fms import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/forecast/api_client.go b/service/forecast/api_client.go index 665041b1d47..7a3cf345c81 100644 --- a/service/forecast/api_client.go +++ b/service/forecast/api_client.go @@ -4,7 +4,9 @@ package forecast import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/forecastquery/api_client.go b/service/forecastquery/api_client.go index 09c37a9df5c..fb693ac43ce 100644 --- a/service/forecastquery/api_client.go +++ b/service/forecastquery/api_client.go @@ -4,7 +4,9 @@ package forecastquery import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/frauddetector/api_client.go b/service/frauddetector/api_client.go index e46e520636c..d5508bc8786 100644 --- a/service/frauddetector/api_client.go +++ b/service/frauddetector/api_client.go @@ -4,7 +4,9 @@ package frauddetector import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/fsx/api_client.go b/service/fsx/api_client.go index dddff0f42a1..387d5095b0f 100644 --- a/service/fsx/api_client.go +++ b/service/fsx/api_client.go @@ -5,7 +5,9 @@ package fsx import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/gamelift/api_client.go b/service/gamelift/api_client.go index f6f1fceaad1..d3fc47ae73f 100644 --- a/service/gamelift/api_client.go +++ b/service/gamelift/api_client.go @@ -4,7 +4,9 @@ package gamelift import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/glacier/api_client.go b/service/glacier/api_client.go index e607783e076..73932894c75 100644 --- a/service/glacier/api_client.go +++ b/service/glacier/api_client.go @@ -4,7 +4,9 @@ package glacier import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/globalaccelerator/api_client.go b/service/globalaccelerator/api_client.go index 79196de6319..d17f1503693 100644 --- a/service/globalaccelerator/api_client.go +++ b/service/globalaccelerator/api_client.go @@ -5,7 +5,9 @@ package globalaccelerator import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/glue/api_client.go b/service/glue/api_client.go index 075243e9d0f..e39ba22b5b8 100644 --- a/service/glue/api_client.go +++ b/service/glue/api_client.go @@ -4,7 +4,9 @@ package glue import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/grafana/api_client.go b/service/grafana/api_client.go index 3605d847d07..eb1d868af6e 100644 --- a/service/grafana/api_client.go +++ b/service/grafana/api_client.go @@ -5,7 +5,9 @@ package grafana import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/greengrass/api_client.go b/service/greengrass/api_client.go index 75a434b6280..577463342ac 100644 --- a/service/greengrass/api_client.go +++ b/service/greengrass/api_client.go @@ -4,7 +4,9 @@ package greengrass import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/greengrassv2/api_client.go b/service/greengrassv2/api_client.go index dc8d6ca6e90..2054622625c 100644 --- a/service/greengrassv2/api_client.go +++ b/service/greengrassv2/api_client.go @@ -5,7 +5,9 @@ package greengrassv2 import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/groundstation/api_client.go b/service/groundstation/api_client.go index 86da4af5a49..4707a616b57 100644 --- a/service/groundstation/api_client.go +++ b/service/groundstation/api_client.go @@ -4,7 +4,9 @@ package groundstation import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/guardduty/api_client.go b/service/guardduty/api_client.go index 584769b9909..6638710a637 100644 --- a/service/guardduty/api_client.go +++ b/service/guardduty/api_client.go @@ -5,7 +5,9 @@ package guardduty import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/health/api_client.go b/service/health/api_client.go index 0575dbff056..bdc8f95f618 100644 --- a/service/health/api_client.go +++ b/service/health/api_client.go @@ -4,7 +4,9 @@ package health import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/healthlake/api_client.go b/service/healthlake/api_client.go index b30be495d41..e0f6bd1793e 100644 --- a/service/healthlake/api_client.go +++ b/service/healthlake/api_client.go @@ -5,7 +5,9 @@ package healthlake import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/honeycode/api_client.go b/service/honeycode/api_client.go index 6cc40d95a91..f2f4720a684 100644 --- a/service/honeycode/api_client.go +++ b/service/honeycode/api_client.go @@ -4,7 +4,9 @@ package honeycode import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iam/api_client.go b/service/iam/api_client.go index 40826b4a0e6..f482c3a1614 100644 --- a/service/iam/api_client.go +++ b/service/iam/api_client.go @@ -4,7 +4,9 @@ package iam import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/identitystore/api_client.go b/service/identitystore/api_client.go index 40b3a3b9eff..a4848a4c041 100644 --- a/service/identitystore/api_client.go +++ b/service/identitystore/api_client.go @@ -4,7 +4,9 @@ package identitystore import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/imagebuilder/api_client.go b/service/imagebuilder/api_client.go index 18198401ee1..da9c5c45335 100644 --- a/service/imagebuilder/api_client.go +++ b/service/imagebuilder/api_client.go @@ -5,7 +5,9 @@ package imagebuilder import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/inspector/api_client.go b/service/inspector/api_client.go index 1d47d8c1132..735635de7c5 100644 --- a/service/inspector/api_client.go +++ b/service/inspector/api_client.go @@ -4,7 +4,9 @@ package inspector import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/inspector2/api_client.go b/service/inspector2/api_client.go index a2f0277ed14..b9ac6571271 100644 --- a/service/inspector2/api_client.go +++ b/service/inspector2/api_client.go @@ -5,7 +5,9 @@ package inspector2 import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/iot/api_client.go b/service/iot/api_client.go index 16b66e6751b..495cdea3b05 100644 --- a/service/iot/api_client.go +++ b/service/iot/api_client.go @@ -5,7 +5,9 @@ package iot import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/iot1clickdevicesservice/api_client.go b/service/iot1clickdevicesservice/api_client.go index 316f7739850..6bf632e542d 100644 --- a/service/iot1clickdevicesservice/api_client.go +++ b/service/iot1clickdevicesservice/api_client.go @@ -4,7 +4,9 @@ package iot1clickdevicesservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iot1clickprojects/api_client.go b/service/iot1clickprojects/api_client.go index 032ca767368..2a1fc4baf06 100644 --- a/service/iot1clickprojects/api_client.go +++ b/service/iot1clickprojects/api_client.go @@ -4,7 +4,9 @@ package iot1clickprojects import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotanalytics/api_client.go b/service/iotanalytics/api_client.go index dd2ec058633..c58b00423cc 100644 --- a/service/iotanalytics/api_client.go +++ b/service/iotanalytics/api_client.go @@ -4,7 +4,9 @@ package iotanalytics import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotdataplane/api_client.go b/service/iotdataplane/api_client.go index 76ab9d9603c..2f602e110de 100644 --- a/service/iotdataplane/api_client.go +++ b/service/iotdataplane/api_client.go @@ -4,7 +4,9 @@ package iotdataplane import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotdeviceadvisor/api_client.go b/service/iotdeviceadvisor/api_client.go index ec33531accf..c8f50d3cd6a 100644 --- a/service/iotdeviceadvisor/api_client.go +++ b/service/iotdeviceadvisor/api_client.go @@ -4,7 +4,9 @@ package iotdeviceadvisor import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotevents/api_client.go b/service/iotevents/api_client.go index d9f5d002cfa..170e3b10c6e 100644 --- a/service/iotevents/api_client.go +++ b/service/iotevents/api_client.go @@ -4,7 +4,9 @@ package iotevents import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ioteventsdata/api_client.go b/service/ioteventsdata/api_client.go index a421741634a..8d60b663cd1 100644 --- a/service/ioteventsdata/api_client.go +++ b/service/ioteventsdata/api_client.go @@ -4,7 +4,9 @@ package ioteventsdata import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotfleethub/api_client.go b/service/iotfleethub/api_client.go index b05ecfffdef..c9c1cad5355 100644 --- a/service/iotfleethub/api_client.go +++ b/service/iotfleethub/api_client.go @@ -5,7 +5,9 @@ package iotfleethub import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/iotjobsdataplane/api_client.go b/service/iotjobsdataplane/api_client.go index b22f0f93f2c..46e09fac440 100644 --- a/service/iotjobsdataplane/api_client.go +++ b/service/iotjobsdataplane/api_client.go @@ -4,7 +4,9 @@ package iotjobsdataplane import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotsecuretunneling/api_client.go b/service/iotsecuretunneling/api_client.go index ef65b0d7980..f86a32ba16f 100644 --- a/service/iotsecuretunneling/api_client.go +++ b/service/iotsecuretunneling/api_client.go @@ -4,7 +4,9 @@ package iotsecuretunneling import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotsitewise/api_client.go b/service/iotsitewise/api_client.go index 885686bf9b0..63e05625237 100644 --- a/service/iotsitewise/api_client.go +++ b/service/iotsitewise/api_client.go @@ -5,7 +5,9 @@ package iotsitewise import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/iotthingsgraph/api_client.go b/service/iotthingsgraph/api_client.go index 701115c2c04..5d5f6d9e393 100644 --- a/service/iotthingsgraph/api_client.go +++ b/service/iotthingsgraph/api_client.go @@ -4,7 +4,9 @@ package iotthingsgraph import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iottwinmaker/api_client.go b/service/iottwinmaker/api_client.go index d15490143c2..9980a397da6 100644 --- a/service/iottwinmaker/api_client.go +++ b/service/iottwinmaker/api_client.go @@ -4,7 +4,9 @@ package iottwinmaker import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/iotwireless/api_client.go b/service/iotwireless/api_client.go index a2c11473dd1..74ccc1509fd 100644 --- a/service/iotwireless/api_client.go +++ b/service/iotwireless/api_client.go @@ -5,7 +5,9 @@ package iotwireless import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/ivs/api_client.go b/service/ivs/api_client.go index 598db3f0f63..3a7985eb327 100644 --- a/service/ivs/api_client.go +++ b/service/ivs/api_client.go @@ -4,7 +4,9 @@ package ivs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kafka/api_client.go b/service/kafka/api_client.go index 7bf5ee3d396..a699217893d 100644 --- a/service/kafka/api_client.go +++ b/service/kafka/api_client.go @@ -4,7 +4,9 @@ package kafka import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kafkaconnect/api_client.go b/service/kafkaconnect/api_client.go index bfb279bc8b3..fc6356d2dda 100644 --- a/service/kafkaconnect/api_client.go +++ b/service/kafkaconnect/api_client.go @@ -4,7 +4,9 @@ package kafkaconnect import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kendra/api_client.go b/service/kendra/api_client.go index f499c9bd47c..407d85fd3dd 100644 --- a/service/kendra/api_client.go +++ b/service/kendra/api_client.go @@ -5,7 +5,9 @@ package kendra import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/kinesis/api_client.go b/service/kinesis/api_client.go index 9cc1ecf2079..e4659771ccd 100644 --- a/service/kinesis/api_client.go +++ b/service/kinesis/api_client.go @@ -4,7 +4,9 @@ package kinesis import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -169,12 +197,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -184,10 +214,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -242,6 +306,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisanalytics/api_client.go b/service/kinesisanalytics/api_client.go index 249edcd801e..72a57baf710 100644 --- a/service/kinesisanalytics/api_client.go +++ b/service/kinesisanalytics/api_client.go @@ -4,7 +4,9 @@ package kinesisanalytics import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisanalyticsv2/api_client.go b/service/kinesisanalyticsv2/api_client.go index 4086730c560..f073e812c09 100644 --- a/service/kinesisanalyticsv2/api_client.go +++ b/service/kinesisanalyticsv2/api_client.go @@ -4,7 +4,9 @@ package kinesisanalyticsv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisvideo/api_client.go b/service/kinesisvideo/api_client.go index 3d1f087624f..b86217d4795 100644 --- a/service/kinesisvideo/api_client.go +++ b/service/kinesisvideo/api_client.go @@ -4,7 +4,9 @@ package kinesisvideo import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisvideoarchivedmedia/api_client.go b/service/kinesisvideoarchivedmedia/api_client.go index cf8e31b798e..7f18cb5355c 100644 --- a/service/kinesisvideoarchivedmedia/api_client.go +++ b/service/kinesisvideoarchivedmedia/api_client.go @@ -4,7 +4,9 @@ package kinesisvideoarchivedmedia import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisvideomedia/api_client.go b/service/kinesisvideomedia/api_client.go index 3edaa11f41d..8d59734d633 100644 --- a/service/kinesisvideomedia/api_client.go +++ b/service/kinesisvideomedia/api_client.go @@ -4,7 +4,9 @@ package kinesisvideomedia import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kinesisvideosignaling/api_client.go b/service/kinesisvideosignaling/api_client.go index 21e0e36482c..25937232dea 100644 --- a/service/kinesisvideosignaling/api_client.go +++ b/service/kinesisvideosignaling/api_client.go @@ -4,7 +4,9 @@ package kinesisvideosignaling import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/kms/api_client.go b/service/kms/api_client.go index 0bc829e22b9..776862dfc5e 100644 --- a/service/kms/api_client.go +++ b/service/kms/api_client.go @@ -4,7 +4,9 @@ package kms import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lakeformation/api_client.go b/service/lakeformation/api_client.go index c0d63664a88..b196088a639 100644 --- a/service/lakeformation/api_client.go +++ b/service/lakeformation/api_client.go @@ -4,7 +4,9 @@ package lakeformation import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lambda/api_client.go b/service/lambda/api_client.go index 770dd4ca943..f074f4fb785 100644 --- a/service/lambda/api_client.go +++ b/service/lambda/api_client.go @@ -4,7 +4,9 @@ package lambda import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lexmodelbuildingservice/api_client.go b/service/lexmodelbuildingservice/api_client.go index 3aed57b2ec5..18f68c74f46 100644 --- a/service/lexmodelbuildingservice/api_client.go +++ b/service/lexmodelbuildingservice/api_client.go @@ -4,7 +4,9 @@ package lexmodelbuildingservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lexmodelsv2/api_client.go b/service/lexmodelsv2/api_client.go index 1fa3b77b462..8bef83f0e06 100644 --- a/service/lexmodelsv2/api_client.go +++ b/service/lexmodelsv2/api_client.go @@ -4,7 +4,9 @@ package lexmodelsv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lexruntimeservice/api_client.go b/service/lexruntimeservice/api_client.go index 7085144c4d0..1d54ebfdfb4 100644 --- a/service/lexruntimeservice/api_client.go +++ b/service/lexruntimeservice/api_client.go @@ -4,7 +4,9 @@ package lexruntimeservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lexruntimev2/api_client.go b/service/lexruntimev2/api_client.go index 7151f4c188b..74aa0d89128 100644 --- a/service/lexruntimev2/api_client.go +++ b/service/lexruntimev2/api_client.go @@ -4,7 +4,9 @@ package lexruntimev2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +198,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +215,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +307,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/licensemanager/api_client.go b/service/licensemanager/api_client.go index a09b8714518..ad5368edb39 100644 --- a/service/licensemanager/api_client.go +++ b/service/licensemanager/api_client.go @@ -4,7 +4,9 @@ package licensemanager import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lightsail/api_client.go b/service/lightsail/api_client.go index 60a6d9401bb..1664f871bf2 100644 --- a/service/lightsail/api_client.go +++ b/service/lightsail/api_client.go @@ -4,7 +4,9 @@ package lightsail import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/location/api_client.go b/service/location/api_client.go index 12f9b642559..a8f3b0f62fe 100644 --- a/service/location/api_client.go +++ b/service/location/api_client.go @@ -4,7 +4,9 @@ package location import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lookoutequipment/api_client.go b/service/lookoutequipment/api_client.go index 9ccc3594582..2db5ca65cee 100644 --- a/service/lookoutequipment/api_client.go +++ b/service/lookoutequipment/api_client.go @@ -5,7 +5,9 @@ package lookoutequipment import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/lookoutmetrics/api_client.go b/service/lookoutmetrics/api_client.go index efd21ee6616..e24a3a8a683 100644 --- a/service/lookoutmetrics/api_client.go +++ b/service/lookoutmetrics/api_client.go @@ -4,7 +4,9 @@ package lookoutmetrics import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/lookoutvision/api_client.go b/service/lookoutvision/api_client.go index 293b8d102b1..994d8c81c75 100644 --- a/service/lookoutvision/api_client.go +++ b/service/lookoutvision/api_client.go @@ -5,7 +5,9 @@ package lookoutvision import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/machinelearning/api_client.go b/service/machinelearning/api_client.go index ac2042157ee..c51422fede7 100644 --- a/service/machinelearning/api_client.go +++ b/service/machinelearning/api_client.go @@ -4,7 +4,9 @@ package machinelearning import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/macie/api_client.go b/service/macie/api_client.go index 392ba5756d3..5db99984aa6 100644 --- a/service/macie/api_client.go +++ b/service/macie/api_client.go @@ -4,7 +4,9 @@ package macie import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/macie2/api_client.go b/service/macie2/api_client.go index 4ca29964d2b..9ee739b08e3 100644 --- a/service/macie2/api_client.go +++ b/service/macie2/api_client.go @@ -5,7 +5,9 @@ package macie2 import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/managedblockchain/api_client.go b/service/managedblockchain/api_client.go index 07005e54c5e..73be8962c70 100644 --- a/service/managedblockchain/api_client.go +++ b/service/managedblockchain/api_client.go @@ -5,7 +5,9 @@ package managedblockchain import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/marketplacecatalog/api_client.go b/service/marketplacecatalog/api_client.go index a8118344300..041b5b60fb2 100644 --- a/service/marketplacecatalog/api_client.go +++ b/service/marketplacecatalog/api_client.go @@ -4,7 +4,9 @@ package marketplacecatalog import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/marketplacecommerceanalytics/api_client.go b/service/marketplacecommerceanalytics/api_client.go index 1b91404b043..a4906f85b32 100644 --- a/service/marketplacecommerceanalytics/api_client.go +++ b/service/marketplacecommerceanalytics/api_client.go @@ -4,7 +4,9 @@ package marketplacecommerceanalytics import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/marketplaceentitlementservice/api_client.go b/service/marketplaceentitlementservice/api_client.go index 9d15c76de37..c66a8ed0598 100644 --- a/service/marketplaceentitlementservice/api_client.go +++ b/service/marketplaceentitlementservice/api_client.go @@ -4,7 +4,9 @@ package marketplaceentitlementservice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/marketplacemetering/api_client.go b/service/marketplacemetering/api_client.go index a2fb2d1dfa1..e688a8e3157 100644 --- a/service/marketplacemetering/api_client.go +++ b/service/marketplacemetering/api_client.go @@ -4,7 +4,9 @@ package marketplacemetering import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediaconnect/api_client.go b/service/mediaconnect/api_client.go index be4d152e32d..77bea9ae2a3 100644 --- a/service/mediaconnect/api_client.go +++ b/service/mediaconnect/api_client.go @@ -4,7 +4,9 @@ package mediaconnect import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediaconvert/api_client.go b/service/mediaconvert/api_client.go index 4c1bdd05a7b..f6aa62bc217 100644 --- a/service/mediaconvert/api_client.go +++ b/service/mediaconvert/api_client.go @@ -5,7 +5,9 @@ package mediaconvert import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/medialive/api_client.go b/service/medialive/api_client.go index d86010cdfb2..287b4a82b6d 100644 --- a/service/medialive/api_client.go +++ b/service/medialive/api_client.go @@ -5,7 +5,9 @@ package medialive import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/mediapackage/api_client.go b/service/mediapackage/api_client.go index db77449cfbf..eae2bfe3c07 100644 --- a/service/mediapackage/api_client.go +++ b/service/mediapackage/api_client.go @@ -4,7 +4,9 @@ package mediapackage import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediapackagevod/api_client.go b/service/mediapackagevod/api_client.go index 4d602749411..c1346f26fe7 100644 --- a/service/mediapackagevod/api_client.go +++ b/service/mediapackagevod/api_client.go @@ -4,7 +4,9 @@ package mediapackagevod import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediastore/api_client.go b/service/mediastore/api_client.go index fba84f951d3..5d89e82ae6b 100644 --- a/service/mediastore/api_client.go +++ b/service/mediastore/api_client.go @@ -4,7 +4,9 @@ package mediastore import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediastoredata/api_client.go b/service/mediastoredata/api_client.go index bf3e5a5a087..8a3f32392b8 100644 --- a/service/mediastoredata/api_client.go +++ b/service/mediastoredata/api_client.go @@ -4,7 +4,9 @@ package mediastoredata import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mediatailor/api_client.go b/service/mediatailor/api_client.go index 1c0f354cb20..0ae04a439cb 100644 --- a/service/mediatailor/api_client.go +++ b/service/mediatailor/api_client.go @@ -4,7 +4,9 @@ package mediatailor import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/memorydb/api_client.go b/service/memorydb/api_client.go index 74adb00bf3d..fbf538e2272 100644 --- a/service/memorydb/api_client.go +++ b/service/memorydb/api_client.go @@ -4,7 +4,9 @@ package memorydb import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mgn/api_client.go b/service/mgn/api_client.go index 305aa603cde..59f66c4668a 100644 --- a/service/mgn/api_client.go +++ b/service/mgn/api_client.go @@ -4,7 +4,9 @@ package mgn import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/migrationhub/api_client.go b/service/migrationhub/api_client.go index 9f94687cc86..20a95320880 100644 --- a/service/migrationhub/api_client.go +++ b/service/migrationhub/api_client.go @@ -4,7 +4,9 @@ package migrationhub import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/migrationhubconfig/api_client.go b/service/migrationhubconfig/api_client.go index f2015d54ab1..3280fcbb00a 100644 --- a/service/migrationhubconfig/api_client.go +++ b/service/migrationhubconfig/api_client.go @@ -4,7 +4,9 @@ package migrationhubconfig import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/migrationhubrefactorspaces/api_client.go b/service/migrationhubrefactorspaces/api_client.go index 0ab54d9a6c0..759a8c872c0 100644 --- a/service/migrationhubrefactorspaces/api_client.go +++ b/service/migrationhubrefactorspaces/api_client.go @@ -5,7 +5,9 @@ package migrationhubrefactorspaces import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/migrationhubstrategy/api_client.go b/service/migrationhubstrategy/api_client.go index ec6fa0d3025..c2ea80d0755 100644 --- a/service/migrationhubstrategy/api_client.go +++ b/service/migrationhubstrategy/api_client.go @@ -4,7 +4,9 @@ package migrationhubstrategy import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mobile/api_client.go b/service/mobile/api_client.go index 9a31eeca0c9..beeda0ebabb 100644 --- a/service/mobile/api_client.go +++ b/service/mobile/api_client.go @@ -4,7 +4,9 @@ package mobile import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mq/api_client.go b/service/mq/api_client.go index 840d085a24c..7f88b783a73 100644 --- a/service/mq/api_client.go +++ b/service/mq/api_client.go @@ -5,7 +5,9 @@ package mq import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/mturk/api_client.go b/service/mturk/api_client.go index 073b943f166..b97c5a71241 100644 --- a/service/mturk/api_client.go +++ b/service/mturk/api_client.go @@ -4,7 +4,9 @@ package mturk import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/mwaa/api_client.go b/service/mwaa/api_client.go index 3d3dc4c5911..14e655a3323 100644 --- a/service/mwaa/api_client.go +++ b/service/mwaa/api_client.go @@ -4,7 +4,9 @@ package mwaa import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/neptune/api_client.go b/service/neptune/api_client.go index 3ec95e82120..111606e373e 100644 --- a/service/neptune/api_client.go +++ b/service/neptune/api_client.go @@ -4,7 +4,9 @@ package neptune import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/protocol/query" "github.com/aws/aws-sdk-go-v2/aws/retry" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -68,6 +73,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -87,9 +96,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -117,6 +139,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -169,12 +197,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -184,10 +214,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -242,6 +306,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/networkfirewall/api_client.go b/service/networkfirewall/api_client.go index 4cfa78ee1a5..92bed6a06d5 100644 --- a/service/networkfirewall/api_client.go +++ b/service/networkfirewall/api_client.go @@ -4,7 +4,9 @@ package networkfirewall import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/networkmanager/api_client.go b/service/networkmanager/api_client.go index cc3409e23da..4a2d21516d5 100644 --- a/service/networkmanager/api_client.go +++ b/service/networkmanager/api_client.go @@ -5,7 +5,9 @@ package networkmanager import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/nimble/api_client.go b/service/nimble/api_client.go index cb17a1b7886..c11a0a04711 100644 --- a/service/nimble/api_client.go +++ b/service/nimble/api_client.go @@ -5,7 +5,9 @@ package nimble import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/opensearch/api_client.go b/service/opensearch/api_client.go index e74881c4f9d..cbabd5a1ecf 100644 --- a/service/opensearch/api_client.go +++ b/service/opensearch/api_client.go @@ -4,7 +4,9 @@ package opensearch import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/opsworks/api_client.go b/service/opsworks/api_client.go index c436653ab23..14425b81c1e 100644 --- a/service/opsworks/api_client.go +++ b/service/opsworks/api_client.go @@ -4,7 +4,9 @@ package opsworks import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/opsworkscm/api_client.go b/service/opsworkscm/api_client.go index 0f248c4ea28..d5826a8d860 100644 --- a/service/opsworkscm/api_client.go +++ b/service/opsworkscm/api_client.go @@ -4,7 +4,9 @@ package opsworkscm import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/organizations/api_client.go b/service/organizations/api_client.go index 0ce750bf99e..ab8c103b819 100644 --- a/service/organizations/api_client.go +++ b/service/organizations/api_client.go @@ -4,7 +4,9 @@ package organizations import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/outposts/api_client.go b/service/outposts/api_client.go index 9803e6c1925..93ed40a5223 100644 --- a/service/outposts/api_client.go +++ b/service/outposts/api_client.go @@ -4,7 +4,9 @@ package outposts import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/panorama/api_client.go b/service/panorama/api_client.go index 851f4742618..645ecad0812 100644 --- a/service/panorama/api_client.go +++ b/service/panorama/api_client.go @@ -4,7 +4,9 @@ package panorama import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/personalize/api_client.go b/service/personalize/api_client.go index 2c9ad427c64..6b0ae798763 100644 --- a/service/personalize/api_client.go +++ b/service/personalize/api_client.go @@ -4,7 +4,9 @@ package personalize import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/personalizeevents/api_client.go b/service/personalizeevents/api_client.go index 7b87a501aa7..44fd20902da 100644 --- a/service/personalizeevents/api_client.go +++ b/service/personalizeevents/api_client.go @@ -4,7 +4,9 @@ package personalizeevents import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/personalizeruntime/api_client.go b/service/personalizeruntime/api_client.go index 8576310fb69..fe475fa1182 100644 --- a/service/personalizeruntime/api_client.go +++ b/service/personalizeruntime/api_client.go @@ -4,7 +4,9 @@ package personalizeruntime import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/pi/api_client.go b/service/pi/api_client.go index 307eac2abfe..fe07aeeec96 100644 --- a/service/pi/api_client.go +++ b/service/pi/api_client.go @@ -4,7 +4,9 @@ package pi import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/pinpoint/api_client.go b/service/pinpoint/api_client.go index 5be5d300d71..58105b17a32 100644 --- a/service/pinpoint/api_client.go +++ b/service/pinpoint/api_client.go @@ -4,7 +4,9 @@ package pinpoint import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/pinpointemail/api_client.go b/service/pinpointemail/api_client.go index 8f89c7de9c7..5f3894ac5ab 100644 --- a/service/pinpointemail/api_client.go +++ b/service/pinpointemail/api_client.go @@ -4,7 +4,9 @@ package pinpointemail import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/pinpointsmsvoice/api_client.go b/service/pinpointsmsvoice/api_client.go index 1ffea969245..7072b245c3e 100644 --- a/service/pinpointsmsvoice/api_client.go +++ b/service/pinpointsmsvoice/api_client.go @@ -4,7 +4,9 @@ package pinpointsmsvoice import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/polly/api_client.go b/service/polly/api_client.go index 9a79d7de6b1..c726ef93902 100644 --- a/service/polly/api_client.go +++ b/service/polly/api_client.go @@ -4,7 +4,9 @@ package polly import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/pricing/api_client.go b/service/pricing/api_client.go index 4349b90cfa2..c3f03b4c722 100644 --- a/service/pricing/api_client.go +++ b/service/pricing/api_client.go @@ -4,7 +4,9 @@ package pricing import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/proton/api_client.go b/service/proton/api_client.go index 6d958cc5137..9f8f27011cb 100644 --- a/service/proton/api_client.go +++ b/service/proton/api_client.go @@ -5,7 +5,9 @@ package proton import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/qldb/api_client.go b/service/qldb/api_client.go index 26c0ac3b74c..7608c5b45bf 100644 --- a/service/qldb/api_client.go +++ b/service/qldb/api_client.go @@ -4,7 +4,9 @@ package qldb import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/qldbsession/api_client.go b/service/qldbsession/api_client.go index 3d386a80151..d669c332b7d 100644 --- a/service/qldbsession/api_client.go +++ b/service/qldbsession/api_client.go @@ -4,7 +4,9 @@ package qldbsession import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/quicksight/api_client.go b/service/quicksight/api_client.go index 7d2020e4495..6a0689f8c53 100644 --- a/service/quicksight/api_client.go +++ b/service/quicksight/api_client.go @@ -4,7 +4,9 @@ package quicksight import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ram/api_client.go b/service/ram/api_client.go index fe568838144..25225a97073 100644 --- a/service/ram/api_client.go +++ b/service/ram/api_client.go @@ -4,7 +4,9 @@ package ram import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/rbin/api_client.go b/service/rbin/api_client.go index ac8290e525e..91582ba688e 100644 --- a/service/rbin/api_client.go +++ b/service/rbin/api_client.go @@ -4,7 +4,9 @@ package rbin import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/rds/api_client.go b/service/rds/api_client.go index 143d13f6779..bd2c3844e27 100644 --- a/service/rds/api_client.go +++ b/service/rds/api_client.go @@ -4,7 +4,9 @@ package rds import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/protocol/query" "github.com/aws/aws-sdk-go-v2/aws/retry" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -69,6 +74,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -88,9 +97,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -118,6 +140,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +198,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +215,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +307,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/rdsdata/api_client.go b/service/rdsdata/api_client.go index 41a14ca6746..e2b3bc0a511 100644 --- a/service/rdsdata/api_client.go +++ b/service/rdsdata/api_client.go @@ -4,7 +4,9 @@ package rdsdata import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/redshift/api_client.go b/service/redshift/api_client.go index c272628c214..b027f68c3a5 100644 --- a/service/redshift/api_client.go +++ b/service/redshift/api_client.go @@ -4,7 +4,9 @@ package redshift import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/redshiftdata/api_client.go b/service/redshiftdata/api_client.go index 81c586e0399..f666f977c72 100644 --- a/service/redshiftdata/api_client.go +++ b/service/redshiftdata/api_client.go @@ -4,7 +4,9 @@ package redshiftdata import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/rekognition/api_client.go b/service/rekognition/api_client.go index 2ca1f462349..f9963c278cf 100644 --- a/service/rekognition/api_client.go +++ b/service/rekognition/api_client.go @@ -4,7 +4,9 @@ package rekognition import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/resiliencehub/api_client.go b/service/resiliencehub/api_client.go index 90f47c10ec8..94a6e8c485f 100644 --- a/service/resiliencehub/api_client.go +++ b/service/resiliencehub/api_client.go @@ -5,7 +5,9 @@ package resiliencehub import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/resourcegroups/api_client.go b/service/resourcegroups/api_client.go index 31bd8d6a029..621a824a5a0 100644 --- a/service/resourcegroups/api_client.go +++ b/service/resourcegroups/api_client.go @@ -4,7 +4,9 @@ package resourcegroups import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/resourcegroupstaggingapi/api_client.go b/service/resourcegroupstaggingapi/api_client.go index 4a7118600ed..f84918e6744 100644 --- a/service/resourcegroupstaggingapi/api_client.go +++ b/service/resourcegroupstaggingapi/api_client.go @@ -4,7 +4,9 @@ package resourcegroupstaggingapi import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/robomaker/api_client.go b/service/robomaker/api_client.go index fd386046380..3f59a93addc 100644 --- a/service/robomaker/api_client.go +++ b/service/robomaker/api_client.go @@ -5,7 +5,9 @@ package robomaker import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/route53/api_client.go b/service/route53/api_client.go index 631a0379ccf..905b3c01e30 100644 --- a/service/route53/api_client.go +++ b/service/route53/api_client.go @@ -4,7 +4,9 @@ package route53 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -16,6 +18,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "strings" "time" @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -68,6 +73,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -87,9 +96,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -117,6 +139,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -169,12 +197,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -184,10 +214,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -242,6 +306,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/route53domains/api_client.go b/service/route53domains/api_client.go index f14e4a921f0..a5b1bc60be7 100644 --- a/service/route53domains/api_client.go +++ b/service/route53domains/api_client.go @@ -4,7 +4,9 @@ package route53domains import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/route53recoverycluster/api_client.go b/service/route53recoverycluster/api_client.go index 0adfa8838f1..d03e335f0e3 100644 --- a/service/route53recoverycluster/api_client.go +++ b/service/route53recoverycluster/api_client.go @@ -4,7 +4,9 @@ package route53recoverycluster import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/route53recoverycontrolconfig/api_client.go b/service/route53recoverycontrolconfig/api_client.go index d58501955f1..9b1e4b4279e 100644 --- a/service/route53recoverycontrolconfig/api_client.go +++ b/service/route53recoverycontrolconfig/api_client.go @@ -5,7 +5,9 @@ package route53recoverycontrolconfig import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/route53recoveryreadiness/api_client.go b/service/route53recoveryreadiness/api_client.go index 40bef15a63b..a91433ff55b 100644 --- a/service/route53recoveryreadiness/api_client.go +++ b/service/route53recoveryreadiness/api_client.go @@ -4,7 +4,9 @@ package route53recoveryreadiness import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/route53resolver/api_client.go b/service/route53resolver/api_client.go index 49ac37626c5..137ec0261a1 100644 --- a/service/route53resolver/api_client.go +++ b/service/route53resolver/api_client.go @@ -5,7 +5,9 @@ package route53resolver import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/rum/api_client.go b/service/rum/api_client.go index d652e38ca5c..160b1b03a84 100644 --- a/service/rum/api_client.go +++ b/service/rum/api_client.go @@ -4,7 +4,9 @@ package rum import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/s3/api_client.go b/service/s3/api_client.go index c5ab34de2d7..3fcb5310776 100644 --- a/service/s3/api_client.go +++ b/service/s3/api_client.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -22,6 +23,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -49,6 +51,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveHTTPSignerV4a(&options) @@ -78,6 +82,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // Allows you to disable S3 Multi-Region access points feature. DisableMultiRegionAccessPoints bool @@ -100,6 +108,12 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + // Allows you to enable arn region support for the service. UseARNRegion bool @@ -126,9 +140,16 @@ type Options struct { // Signature Version 4a (SigV4a) Signer httpSignerV4a httpSignerV4a + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -156,6 +177,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -212,12 +239,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -228,10 +257,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -287,6 +350,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/s3control/api_client.go b/service/s3control/api_client.go index db075282397..34be84e5a81 100644 --- a/service/s3control/api_client.go +++ b/service/s3control/api_client.go @@ -5,7 +5,9 @@ package s3control import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -19,6 +21,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -45,6 +48,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -72,6 +77,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -95,6 +104,12 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + // Allows you to enable arn region support for the service. UseARNRegion bool @@ -105,9 +120,16 @@ type Options struct { // field is set it overrides this field value. UseDualstack bool + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -135,6 +157,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -187,12 +215,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -203,10 +233,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -261,6 +325,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/s3outposts/api_client.go b/service/s3outposts/api_client.go index 306535ff155..a0920e85dcd 100644 --- a/service/s3outposts/api_client.go +++ b/service/s3outposts/api_client.go @@ -4,7 +4,9 @@ package s3outposts import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sagemaker/api_client.go b/service/sagemaker/api_client.go index 3ed0595b432..bcc6d9b5d51 100644 --- a/service/sagemaker/api_client.go +++ b/service/sagemaker/api_client.go @@ -5,7 +5,9 @@ package sagemaker import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/sagemakera2iruntime/api_client.go b/service/sagemakera2iruntime/api_client.go index a9079832011..5b6747e2b72 100644 --- a/service/sagemakera2iruntime/api_client.go +++ b/service/sagemakera2iruntime/api_client.go @@ -4,7 +4,9 @@ package sagemakera2iruntime import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sagemakeredge/api_client.go b/service/sagemakeredge/api_client.go index 452c86e4991..fc13088555b 100644 --- a/service/sagemakeredge/api_client.go +++ b/service/sagemakeredge/api_client.go @@ -4,7 +4,9 @@ package sagemakeredge import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sagemakerfeaturestoreruntime/api_client.go b/service/sagemakerfeaturestoreruntime/api_client.go index 7e6f2ba9b96..c58953fa35a 100644 --- a/service/sagemakerfeaturestoreruntime/api_client.go +++ b/service/sagemakerfeaturestoreruntime/api_client.go @@ -4,7 +4,9 @@ package sagemakerfeaturestoreruntime import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sagemakerruntime/api_client.go b/service/sagemakerruntime/api_client.go index dcc028e20f8..e1d018632f2 100644 --- a/service/sagemakerruntime/api_client.go +++ b/service/sagemakerruntime/api_client.go @@ -4,7 +4,9 @@ package sagemakerruntime import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/savingsplans/api_client.go b/service/savingsplans/api_client.go index d295bc95544..d40a8a880ff 100644 --- a/service/savingsplans/api_client.go +++ b/service/savingsplans/api_client.go @@ -5,7 +5,9 @@ package savingsplans import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/schemas/api_client.go b/service/schemas/api_client.go index 6ab9afce8ba..92168c733bd 100644 --- a/service/schemas/api_client.go +++ b/service/schemas/api_client.go @@ -5,7 +5,9 @@ package schemas import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/secretsmanager/api_client.go b/service/secretsmanager/api_client.go index 9e17bf16356..577e2cf2d33 100644 --- a/service/secretsmanager/api_client.go +++ b/service/secretsmanager/api_client.go @@ -5,7 +5,9 @@ package secretsmanager import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/securityhub/api_client.go b/service/securityhub/api_client.go index 6ea968c8b24..8f10015730f 100644 --- a/service/securityhub/api_client.go +++ b/service/securityhub/api_client.go @@ -4,7 +4,9 @@ package securityhub import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/serverlessapplicationrepository/api_client.go b/service/serverlessapplicationrepository/api_client.go index d8c9d2e6d43..8dc6a084c06 100644 --- a/service/serverlessapplicationrepository/api_client.go +++ b/service/serverlessapplicationrepository/api_client.go @@ -4,7 +4,9 @@ package serverlessapplicationrepository import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/servicecatalog/api_client.go b/service/servicecatalog/api_client.go index 54b30ce7274..f58a8a7e568 100644 --- a/service/servicecatalog/api_client.go +++ b/service/servicecatalog/api_client.go @@ -5,7 +5,9 @@ package servicecatalog import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/servicecatalogappregistry/api_client.go b/service/servicecatalogappregistry/api_client.go index ba4105d9ad2..02887215465 100644 --- a/service/servicecatalogappregistry/api_client.go +++ b/service/servicecatalogappregistry/api_client.go @@ -5,7 +5,9 @@ package servicecatalogappregistry import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/servicediscovery/api_client.go b/service/servicediscovery/api_client.go index be5cb36cae3..9766fd48217 100644 --- a/service/servicediscovery/api_client.go +++ b/service/servicediscovery/api_client.go @@ -5,7 +5,9 @@ package servicediscovery import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/servicequotas/api_client.go b/service/servicequotas/api_client.go index 6bd0dd0de3c..aafa343cd72 100644 --- a/service/servicequotas/api_client.go +++ b/service/servicequotas/api_client.go @@ -4,7 +4,9 @@ package servicequotas import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ses/api_client.go b/service/ses/api_client.go index ad666c79874..886cd8fae64 100644 --- a/service/ses/api_client.go +++ b/service/ses/api_client.go @@ -4,7 +4,9 @@ package ses import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sesv2/api_client.go b/service/sesv2/api_client.go index bc2c3db0a3f..e0749aa02f9 100644 --- a/service/sesv2/api_client.go +++ b/service/sesv2/api_client.go @@ -4,7 +4,9 @@ package sesv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sfn/api_client.go b/service/sfn/api_client.go index a392ed72ca5..204dd919a54 100644 --- a/service/sfn/api_client.go +++ b/service/sfn/api_client.go @@ -4,7 +4,9 @@ package sfn import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/shield/api_client.go b/service/shield/api_client.go index f4b645b74c8..b656d857f9f 100644 --- a/service/shield/api_client.go +++ b/service/shield/api_client.go @@ -4,7 +4,9 @@ package shield import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/signer/api_client.go b/service/signer/api_client.go index 21e91b6d9e1..67a6e963a01 100644 --- a/service/signer/api_client.go +++ b/service/signer/api_client.go @@ -5,7 +5,9 @@ package signer import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/sms/api_client.go b/service/sms/api_client.go index 6f8878f589f..f7da2a9282a 100644 --- a/service/sms/api_client.go +++ b/service/sms/api_client.go @@ -4,7 +4,9 @@ package sms import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/snowball/api_client.go b/service/snowball/api_client.go index 2a26cb45d37..9338eca52b1 100644 --- a/service/snowball/api_client.go +++ b/service/snowball/api_client.go @@ -4,7 +4,9 @@ package snowball import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/snowdevicemanagement/api_client.go b/service/snowdevicemanagement/api_client.go index 845af8419d6..90daf720b00 100644 --- a/service/snowdevicemanagement/api_client.go +++ b/service/snowdevicemanagement/api_client.go @@ -5,7 +5,9 @@ package snowdevicemanagement import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/sns/api_client.go b/service/sns/api_client.go index d32d2676926..400e08f0be2 100644 --- a/service/sns/api_client.go +++ b/service/sns/api_client.go @@ -4,7 +4,9 @@ package sns import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sqs/api_client.go b/service/sqs/api_client.go index eeecc931c50..928acfe4e33 100644 --- a/service/sqs/api_client.go +++ b/service/sqs/api_client.go @@ -4,7 +4,9 @@ package sqs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ssm/api_client.go b/service/ssm/api_client.go index a785b03947b..12638107098 100644 --- a/service/ssm/api_client.go +++ b/service/ssm/api_client.go @@ -5,7 +5,9 @@ package ssm import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/ssmcontacts/api_client.go b/service/ssmcontacts/api_client.go index 98d7f225829..e8f5c7c9c37 100644 --- a/service/ssmcontacts/api_client.go +++ b/service/ssmcontacts/api_client.go @@ -5,7 +5,9 @@ package ssmcontacts import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/ssmincidents/api_client.go b/service/ssmincidents/api_client.go index 9373c5702a9..ab374c571a1 100644 --- a/service/ssmincidents/api_client.go +++ b/service/ssmincidents/api_client.go @@ -5,7 +5,9 @@ package ssmincidents import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/sso/api_client.go b/service/sso/api_client.go index 4fed68b6f9d..916291b0811 100644 --- a/service/sso/api_client.go +++ b/service/sso/api_client.go @@ -4,7 +4,9 @@ package sso import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ssoadmin/api_client.go b/service/ssoadmin/api_client.go index 2607cb86215..2c854f3a0fc 100644 --- a/service/ssoadmin/api_client.go +++ b/service/ssoadmin/api_client.go @@ -4,7 +4,9 @@ package ssoadmin import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/ssooidc/api_client.go b/service/ssooidc/api_client.go index 0f2e100f801..003078fe9f5 100644 --- a/service/ssooidc/api_client.go +++ b/service/ssooidc/api_client.go @@ -4,7 +4,9 @@ package ssooidc import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/storagegateway/api_client.go b/service/storagegateway/api_client.go index 9b269399781..a68df7bf354 100644 --- a/service/storagegateway/api_client.go +++ b/service/storagegateway/api_client.go @@ -4,7 +4,9 @@ package storagegateway import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/sts/api_client.go b/service/sts/api_client.go index 6614d01b007..de29ca55cc9 100644 --- a/service/sts/api_client.go +++ b/service/sts/api_client.go @@ -4,7 +4,9 @@ package sts import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/protocol/query" "github.com/aws/aws-sdk-go-v2/aws/retry" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -69,6 +74,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -88,9 +97,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -118,6 +140,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +198,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +215,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +307,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/support/api_client.go b/service/support/api_client.go index 71b5174f53f..f1ff740640d 100644 --- a/service/support/api_client.go +++ b/service/support/api_client.go @@ -4,7 +4,9 @@ package support import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/swf/api_client.go b/service/swf/api_client.go index 485ffffa0ca..f443d92c796 100644 --- a/service/swf/api_client.go +++ b/service/swf/api_client.go @@ -4,7 +4,9 @@ package swf import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/synthetics/api_client.go b/service/synthetics/api_client.go index ee19b060b92..d2ecd24e07e 100644 --- a/service/synthetics/api_client.go +++ b/service/synthetics/api_client.go @@ -4,7 +4,9 @@ package synthetics import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/textract/api_client.go b/service/textract/api_client.go index fce4cafdcc1..e96639d35b9 100644 --- a/service/textract/api_client.go +++ b/service/textract/api_client.go @@ -4,7 +4,9 @@ package textract import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/timestreamquery/api_client.go b/service/timestreamquery/api_client.go index adafd4e65a0..f9a8987e7d6 100644 --- a/service/timestreamquery/api_client.go +++ b/service/timestreamquery/api_client.go @@ -7,6 +7,7 @@ import ( cryptorand "crypto/rand" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -19,6 +20,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "net/url" "strings" @@ -51,6 +53,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -82,6 +86,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // Allows configuring endpoint discovery EndpointDiscovery EndpointDiscoveryOptions @@ -108,9 +116,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -138,6 +159,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -190,12 +217,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -206,10 +235,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -264,6 +327,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/timestreamwrite/api_client.go b/service/timestreamwrite/api_client.go index 685a9c060cd..fe0d8754446 100644 --- a/service/timestreamwrite/api_client.go +++ b/service/timestreamwrite/api_client.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +18,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "net/url" "strings" @@ -49,6 +51,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveEnableEndpointDiscovery(&options) @@ -78,6 +82,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // Allows configuring endpoint discovery EndpointDiscovery EndpointDiscoveryOptions @@ -100,9 +108,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -130,6 +151,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -182,12 +209,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -198,10 +227,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -256,6 +319,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/transcribe/api_client.go b/service/transcribe/api_client.go index d95a696e6ce..f589c1ef53f 100644 --- a/service/transcribe/api_client.go +++ b/service/transcribe/api_client.go @@ -4,7 +4,9 @@ package transcribe import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/transcribestreaming/api_client.go b/service/transcribestreaming/api_client.go index c81dbdfdc5a..88a156df916 100644 --- a/service/transcribestreaming/api_client.go +++ b/service/transcribestreaming/api_client.go @@ -4,7 +4,9 @@ package transcribestreaming import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -170,12 +198,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -185,10 +215,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -243,6 +307,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/transfer/api_client.go b/service/transfer/api_client.go index ccf689c088d..cc4116c2802 100644 --- a/service/transfer/api_client.go +++ b/service/transfer/api_client.go @@ -4,7 +4,9 @@ package transfer import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/translate/api_client.go b/service/translate/api_client.go index 29f5555c466..b99f3cf87c2 100644 --- a/service/translate/api_client.go +++ b/service/translate/api_client.go @@ -5,7 +5,9 @@ package translate import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/voiceid/api_client.go b/service/voiceid/api_client.go index 2f8b253bc73..4e775890c12 100644 --- a/service/voiceid/api_client.go +++ b/service/voiceid/api_client.go @@ -5,7 +5,9 @@ package voiceid import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/waf/api_client.go b/service/waf/api_client.go index a6de09d8d78..eeea716c0c9 100644 --- a/service/waf/api_client.go +++ b/service/waf/api_client.go @@ -4,7 +4,9 @@ package waf import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/wafregional/api_client.go b/service/wafregional/api_client.go index 79177caa9ef..e0ef02ab7b4 100644 --- a/service/wafregional/api_client.go +++ b/service/wafregional/api_client.go @@ -4,7 +4,9 @@ package wafregional import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/wafv2/api_client.go b/service/wafv2/api_client.go index df8a314829d..7550a75814d 100644 --- a/service/wafv2/api_client.go +++ b/service/wafv2/api_client.go @@ -4,7 +4,9 @@ package wafv2 import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/wellarchitected/api_client.go b/service/wellarchitected/api_client.go index b94e8fdfabc..6d55c009ed6 100644 --- a/service/wellarchitected/api_client.go +++ b/service/wellarchitected/api_client.go @@ -5,7 +5,9 @@ package wellarchitected import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/wisdom/api_client.go b/service/wisdom/api_client.go index dbb1b4a9fac..384591b2db6 100644 --- a/service/wisdom/api_client.go +++ b/service/wisdom/api_client.go @@ -5,7 +5,9 @@ package wisdom import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/workdocs/api_client.go b/service/workdocs/api_client.go index 2e724d0f654..d830152689c 100644 --- a/service/workdocs/api_client.go +++ b/service/workdocs/api_client.go @@ -4,7 +4,9 @@ package workdocs import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/worklink/api_client.go b/service/worklink/api_client.go index b4676f6b85e..3ffd15411a4 100644 --- a/service/worklink/api_client.go +++ b/service/worklink/api_client.go @@ -4,7 +4,9 @@ package worklink import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/workmail/api_client.go b/service/workmail/api_client.go index 4bb3ff8f5e8..7b2ca86e13d 100644 --- a/service/workmail/api_client.go +++ b/service/workmail/api_client.go @@ -5,7 +5,9 @@ package workmail import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -43,6 +46,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -70,6 +75,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -93,9 +102,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -123,6 +145,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -175,12 +203,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -190,10 +220,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -248,6 +312,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/workmailmessageflow/api_client.go b/service/workmailmessageflow/api_client.go index 045cd2af6a5..e557aef2527 100644 --- a/service/workmailmessageflow/api_client.go +++ b/service/workmailmessageflow/api_client.go @@ -4,7 +4,9 @@ package workmailmessageflow import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -42,6 +45,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -67,6 +72,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -86,9 +95,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -116,6 +138,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -168,12 +196,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -183,10 +213,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -241,6 +305,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/workspaces/api_client.go b/service/workspaces/api_client.go index 030037a6c61..d92189207bd 100644 --- a/service/workspaces/api_client.go +++ b/service/workspaces/api_client.go @@ -4,7 +4,9 @@ package workspaces import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer, diff --git a/service/workspacesweb/api_client.go b/service/workspacesweb/api_client.go index 1bc7cc8d3c1..1677223c6f2 100644 --- a/service/workspacesweb/api_client.go +++ b/service/workspacesweb/api_client.go @@ -5,7 +5,9 @@ package workspacesweb import ( "context" cryptorand "crypto/rand" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -17,6 +19,7 @@ import ( "github.com/aws/smithy-go/middleware" smithyrand "github.com/aws/smithy-go/rand" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -44,6 +47,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) resolveIdempotencyTokenProvider(&options) @@ -71,6 +76,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -94,9 +103,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -124,6 +146,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -176,12 +204,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -191,10 +221,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -249,6 +313,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func resolveIdempotencyTokenProvider(o *Options) { if o.IdempotencyTokenProvider != nil { return diff --git a/service/xray/api_client.go b/service/xray/api_client.go index 5d6da2140d0..14991c5987f 100644 --- a/service/xray/api_client.go +++ b/service/xray/api_client.go @@ -4,7 +4,9 @@ package xray import ( "context" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/defaults" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" @@ -15,6 +17,7 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" + "net" "net/http" "time" ) @@ -41,6 +44,8 @@ func New(options Options, optFns ...func(*Options)) *Client { resolveHTTPSignerV4(&options) + setResolvedDefaultsMode(&options) + resolveDefaultEndpointConfiguration(&options) for _, fn := range optFns { @@ -66,6 +71,10 @@ type Options struct { // The credentials object to use when signing requests. Credentials aws.CredentialsProvider + // The configuration DefaultsMode that the SDK should use when constructing the + // clients initial default settings. + DefaultsMode aws.DefaultsMode + // The endpoint options to be used when attempting to resolve an endpoint. EndpointOptions EndpointResolverOptions @@ -85,9 +94,22 @@ type Options struct { // failures. When nil the API client will use a default retryer. Retryer aws.Retryer + // The RuntimeEnvironment configuration, only populated if the DefaultsMode is set + // to AutoDefaultsMode and is initialized using config.LoadDefaultConfig. You + // should not populate this structure programmatically, or rely on the values here + // within your applications. + RuntimeEnvironment aws.RuntimeEnvironment + + // The initial DefaultsMode used when the client options were constructed. If the + // DefaultsMode was set to aws.AutoDefaultsMode this will store what the resolved + // value was at that point in time. + resolvedDefaultsMode aws.DefaultsMode + // The HTTP client to invoke API calls with. Defaults to client's default HTTP // implementation if nil. HTTPClient HTTPClient + + clientInitializedOptions map[struct{}]interface{} } // WithAPIOptions returns a functional option for setting the Client's APIOptions @@ -115,6 +137,12 @@ func (o Options) Copy() Options { to := o to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) copy(to.APIOptions, o.APIOptions) + + to.clientInitializedOptions = make(map[struct{}]interface{}, len(o.clientInitializedOptions)) + for k, v := range o.clientInitializedOptions { + to.clientInitializedOptions[k] = v + } + return to } func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { @@ -167,12 +195,14 @@ func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { // NewFromConfig returns a new client from the provided config. func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { opts := Options{ - Region: cfg.Region, - HTTPClient: cfg.HTTPClient, - Credentials: cfg.Credentials, - APIOptions: cfg.APIOptions, - Logger: cfg.Logger, - ClientLogMode: cfg.ClientLogMode, + Region: cfg.Region, + DefaultsMode: cfg.DefaultsMode, + RuntimeEnvironment: cfg.RuntimeEnvironment, + HTTPClient: cfg.HTTPClient, + Credentials: cfg.Credentials, + APIOptions: cfg.APIOptions, + Logger: cfg.Logger, + ClientLogMode: cfg.ClientLogMode, } resolveAWSRetryerProvider(cfg, &opts) resolveAWSEndpointResolver(cfg, &opts) @@ -182,10 +212,44 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { } func resolveHTTPClient(o *Options) { + var buildable *awshttp.BuildableClient + if o.HTTPClient != nil { - return + var ok bool + buildable, ok = o.HTTPClient.(*awshttp.BuildableClient) + if !ok { + return + } + } else { + buildable = awshttp.NewBuildableClient() + } + + var mode aws.DefaultsMode + if ok := mode.SetFromString(string(o.DefaultsMode)); !ok { + panic(fmt.Errorf("unsupported defaults mode constant %v", mode)) + } + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) } - o.HTTPClient = awshttp.NewBuildableClient() + + if mode != aws.LegacyDefaultsMode { + modeConfig, _ := defaults.GetModeConfiguration(mode) + + buildable = buildable.WithDialerOptions(func(dialer *net.Dialer) { + if dialerTimeout, ok := modeConfig.GetConnectTimeout(); ok { + dialer.Timeout = dialerTimeout + } + }) + + buildable = buildable.WithTransportOptions(func(transport *http.Transport) { + if tlsHandshakeTimeout, ok := modeConfig.GetTLSNegotiationTimeout(); ok { + transport.TLSHandshakeTimeout = tlsHandshakeTimeout + } + }) + } + + o.HTTPClient = buildable } func resolveRetryer(o *Options) { @@ -240,6 +304,21 @@ func newDefaultV4Signer(o Options) *v4.Signer { }) } +func setResolvedDefaultsMode(o *Options) { + if len(o.resolvedDefaultsMode) > 0 { + return + } + + var mode aws.DefaultsMode + mode.SetFromString(string(o.DefaultsMode)) + + if mode == aws.AutoDefaultsMode { + mode = defaults.ResolveAutoDefaultsMode(o.Region, o.RuntimeEnvironment) + } + + o.resolvedDefaultsMode = mode +} + func addRetryMiddlewares(stack *middleware.Stack, o Options) error { mo := retry.AddRetryMiddlewaresOptions{ Retryer: o.Retryer,