src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

options.go (10354B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package sts
      4 
      5 import (
      6 	"context"
      7 	"fmt"
      8 	"net/http"
      9 
     10 	"github.com/aws/aws-sdk-go-v2/aws"
     11 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
     12 	internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
     13 	"github.com/aws/aws-sdk-go-v2/internal/v4a"
     14 	smithyauth "github.com/aws/smithy-go/auth"
     15 	"github.com/aws/smithy-go/logging"
     16 	"github.com/aws/smithy-go/metrics"
     17 	"github.com/aws/smithy-go/middleware"
     18 	"github.com/aws/smithy-go/tracing"
     19 	smithyhttp "github.com/aws/smithy-go/transport/http"
     20 )
     21 
     22 type HTTPClient interface {
     23 	Do(*http.Request) (*http.Response, error)
     24 }
     25 
     26 type Options struct {
     27 	// Set of options to modify how an operation is invoked. These apply to all
     28 	// operations invoked for this client. Use functional options on operation call to
     29 	// modify this list for per operation behavior.
     30 	APIOptions []func(*middleware.Stack) error
     31 
     32 	// The optional application specific identifier appended to the User-Agent header.
     33 	AppID string
     34 
     35 	// This endpoint will be given as input to an EndpointResolverV2. It is used for
     36 	// providing a custom base endpoint that is subject to modifications by the
     37 	// processing EndpointResolverV2.
     38 	BaseEndpoint *string
     39 
     40 	// Configures the events that will be sent to the configured logger.
     41 	ClientLogMode aws.ClientLogMode
     42 
     43 	// The credentials object to use when signing requests.
     44 	Credentials aws.CredentialsProvider
     45 
     46 	// The configuration DefaultsMode that the SDK should use when constructing the
     47 	// clients initial default settings.
     48 	DefaultsMode aws.DefaultsMode
     49 
     50 	// Disables SDK clock skew correction. When set, the SDK will not adjust request
     51 	// signing timestamps to compensate for clock drift between the client and the
     52 	// service.
     53 	DisableClockSkewCorrection bool
     54 
     55 	// The endpoint options to be used when attempting to resolve an endpoint.
     56 	EndpointOptions EndpointResolverOptions
     57 
     58 	// The service endpoint resolver.
     59 	//
     60 	// Deprecated: Deprecated: EndpointResolver and WithEndpointResolver. Providing a
     61 	// value for this field will likely prevent you from using any endpoint-related
     62 	// service features released after the introduction of EndpointResolverV2 and
     63 	// BaseEndpoint.
     64 	//
     65 	// To migrate an EndpointResolver implementation that uses a custom endpoint, set
     66 	// the client option BaseEndpoint instead.
     67 	EndpointResolver EndpointResolver
     68 
     69 	// Resolves the endpoint used for a particular service operation.
     70 	EndpointResolverV2 EndpointResolverV2
     71 
     72 	// Signature Version 4 (SigV4) Signer
     73 	HTTPSignerV4 HTTPSignerV4
     74 
     75 	// The logger writer interface to write logging messages to.
     76 	Logger logging.Logger
     77 
     78 	// The client meter provider.
     79 	MeterProvider metrics.MeterProvider
     80 
     81 	// The region to send requests to. (Required)
     82 	Region string
     83 
     84 	// RetryMaxAttempts specifies the maximum number attempts an API client will call
     85 	// an operation that fails with a retryable error. A value of 0 is ignored, and
     86 	// will not be used to configure the API client created default retryer, or modify
     87 	// per operation call's retry max attempts.
     88 	//
     89 	// If specified in an operation call's functional options with a value that is
     90 	// different than the constructed client's Options, the Client's Retryer will be
     91 	// wrapped to use the operation's specific RetryMaxAttempts value.
     92 	RetryMaxAttempts int
     93 
     94 	// RetryMode specifies the retry mode the API client will be created with, if
     95 	// Retryer option is not also specified.
     96 	//
     97 	// When creating a new API Clients this member will only be used if the Retryer
     98 	// Options member is nil. This value will be ignored if Retryer is not nil.
     99 	//
    100 	// Currently does not support per operation call overrides, may in the future.
    101 	RetryMode aws.RetryMode
    102 
    103 	// Retryer guides how HTTP requests should be retried in case of recoverable
    104 	// failures. When nil the API client will use a default retryer. The kind of
    105 	// default retry created by the API client can be changed with the RetryMode
    106 	// option.
    107 	Retryer aws.Retryer
    108 
    109 	// The RuntimeEnvironment configuration, only populated if the DefaultsMode is set
    110 	// to DefaultsModeAuto and is initialized using config.LoadDefaultConfig . You
    111 	// should not populate this structure programmatically, or rely on the values here
    112 	// within your applications.
    113 	RuntimeEnvironment aws.RuntimeEnvironment
    114 
    115 	// The client tracer provider.
    116 	TracerProvider tracing.TracerProvider
    117 
    118 	// Signature Version 4a (SigV4a) Signer
    119 	httpSignerV4a httpSignerV4a
    120 
    121 	// The initial DefaultsMode used when the client options were constructed. If the
    122 	// DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
    123 	// value was at that point in time.
    124 	//
    125 	// Currently does not support per operation call overrides, may in the future.
    126 	resolvedDefaultsMode aws.DefaultsMode
    127 
    128 	// The HTTP client to invoke API calls with. Defaults to client's default HTTP
    129 	// implementation if nil.
    130 	HTTPClient HTTPClient
    131 
    132 	// Client registry of operation interceptors.
    133 	Interceptors smithyhttp.InterceptorRegistry
    134 
    135 	// The auth scheme resolver which determines how to authenticate for each
    136 	// operation.
    137 	AuthSchemeResolver AuthSchemeResolver
    138 
    139 	// The list of auth schemes supported by the client.
    140 	AuthSchemes []smithyhttp.AuthScheme
    141 
    142 	// Priority list of preferred auth scheme names (e.g. sigv4a).
    143 	AuthSchemePreference []string
    144 }
    145 
    146 // Copy creates a clone where the APIOptions list is deep copied.
    147 func (o Options) Copy() Options {
    148 	to := o
    149 	to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions))
    150 	copy(to.APIOptions, o.APIOptions)
    151 	to.Interceptors = o.Interceptors.Copy()
    152 
    153 	return to
    154 }
    155 
    156 func (o Options) GetIdentityResolver(schemeID string) smithyauth.IdentityResolver {
    157 	if schemeID == "aws.auth#sigv4" {
    158 		return getSigV4IdentityResolver(o)
    159 	}
    160 	if schemeID == "aws.auth#sigv4a" {
    161 		return getSigV4AIdentityResolver(o)
    162 	}
    163 	if schemeID == "smithy.api#noAuth" {
    164 		return &smithyauth.AnonymousIdentityResolver{}
    165 	}
    166 	return nil
    167 }
    168 
    169 // WithAPIOptions returns a functional option for setting the Client's APIOptions
    170 // option.
    171 func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) {
    172 	return func(o *Options) {
    173 		o.APIOptions = append(o.APIOptions, optFns...)
    174 	}
    175 }
    176 
    177 // Deprecated: EndpointResolver and WithEndpointResolver. Providing a value for
    178 // this field will likely prevent you from using any endpoint-related service
    179 // features released after the introduction of EndpointResolverV2 and BaseEndpoint.
    180 //
    181 // To migrate an EndpointResolver implementation that uses a custom endpoint, set
    182 // the client option BaseEndpoint instead.
    183 func WithEndpointResolver(v EndpointResolver) func(*Options) {
    184 	return func(o *Options) {
    185 		o.EndpointResolver = v
    186 	}
    187 }
    188 
    189 // WithEndpointResolverV2 returns a functional option for setting the Client's
    190 // EndpointResolverV2 option.
    191 func WithEndpointResolverV2(v EndpointResolverV2) func(*Options) {
    192 	return func(o *Options) {
    193 		o.EndpointResolverV2 = v
    194 	}
    195 }
    196 
    197 func getSigV4IdentityResolver(o Options) smithyauth.IdentityResolver {
    198 	if o.Credentials != nil {
    199 		return &internalauthsmithy.CredentialsProviderAdapter{Provider: o.Credentials}
    200 	}
    201 	return nil
    202 }
    203 
    204 // WithSigV4SigningName applies an override to the authentication workflow to
    205 // use the given signing name for SigV4-authenticated operations.
    206 //
    207 // This is an advanced setting. The value here is FINAL, taking precedence over
    208 // the resolved signing name from both auth scheme resolution and endpoint
    209 // resolution.
    210 func WithSigV4SigningName(name string) func(*Options) {
    211 	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
    212 		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
    213 	) {
    214 		return next.HandleInitialize(awsmiddleware.SetSigningName(ctx, name), in)
    215 	}
    216 	return func(o *Options) {
    217 		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
    218 			return s.Initialize.Add(
    219 				middleware.InitializeMiddlewareFunc("withSigV4SigningName", fn),
    220 				middleware.Before,
    221 			)
    222 		})
    223 	}
    224 }
    225 
    226 // WithSigV4SigningRegion applies an override to the authentication workflow to
    227 // use the given signing region for SigV4-authenticated operations.
    228 //
    229 // This is an advanced setting. The value here is FINAL, taking precedence over
    230 // the resolved signing region from both auth scheme resolution and endpoint
    231 // resolution.
    232 func WithSigV4SigningRegion(region string) func(*Options) {
    233 	fn := func(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
    234 		out middleware.InitializeOutput, metadata middleware.Metadata, err error,
    235 	) {
    236 		return next.HandleInitialize(awsmiddleware.SetSigningRegion(ctx, region), in)
    237 	}
    238 	return func(o *Options) {
    239 		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
    240 			return s.Initialize.Add(
    241 				middleware.InitializeMiddlewareFunc("withSigV4SigningRegion", fn),
    242 				middleware.Before,
    243 			)
    244 		})
    245 	}
    246 }
    247 
    248 func getSigV4AIdentityResolver(o Options) smithyauth.IdentityResolver {
    249 	if o.Credentials != nil {
    250 		return &v4a.CredentialsProviderAdapter{
    251 			Provider: &v4a.SymmetricCredentialAdaptor{
    252 				SymmetricProvider: o.Credentials,
    253 			},
    254 		}
    255 	}
    256 	return nil
    257 }
    258 
    259 // WithSigV4ASigningRegions applies an override to the authentication workflow to
    260 // use the given signing region set for SigV4A-authenticated operations.
    261 //
    262 // This is an advanced setting. The value here is FINAL, taking precedence over
    263 // the resolved signing region set from both auth scheme resolution and endpoint
    264 // resolution.
    265 func WithSigV4ASigningRegions(regions []string) func(*Options) {
    266 	fn := func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
    267 		out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
    268 	) {
    269 		rscheme := getResolvedAuthScheme(ctx)
    270 		if rscheme == nil {
    271 			return out, metadata, fmt.Errorf("no resolved auth scheme")
    272 		}
    273 
    274 		smithyhttp.SetSigV4ASigningRegions(&rscheme.SignerProperties, regions)
    275 		return next.HandleFinalize(ctx, in)
    276 	}
    277 	return func(o *Options) {
    278 		o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
    279 			return s.Finalize.Insert(
    280 				middleware.FinalizeMiddlewareFunc("withSigV4ASigningRegions", fn),
    281 				"Signing",
    282 				middleware.Before,
    283 			)
    284 		})
    285 	}
    286 }
    287 
    288 func ignoreAnonymousAuth(options *Options) {
    289 	if aws.IsCredentialsProvider(options.Credentials, (*aws.AnonymousCredentials)(nil)) {
    290 		options.Credentials = nil
    291 	}
    292 }