code.dwrz.net

Go monorepo.
Log | Files | Refs

load_options.go (36250B)


      1 package config
      2 
      3 import (
      4 	"context"
      5 	"io"
      6 
      7 	"github.com/aws/aws-sdk-go-v2/aws"
      8 	"github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds"
      9 	"github.com/aws/aws-sdk-go-v2/credentials/endpointcreds"
     10 	"github.com/aws/aws-sdk-go-v2/credentials/processcreds"
     11 	"github.com/aws/aws-sdk-go-v2/credentials/ssocreds"
     12 	"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
     13 	"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
     14 	smithybearer "github.com/aws/smithy-go/auth/bearer"
     15 	"github.com/aws/smithy-go/logging"
     16 	"github.com/aws/smithy-go/middleware"
     17 )
     18 
     19 // LoadOptionsFunc is a type alias for LoadOptions functional option
     20 type LoadOptionsFunc func(*LoadOptions) error
     21 
     22 // LoadOptions are discrete set of options that are valid for loading the
     23 // configuration
     24 type LoadOptions struct {
     25 
     26 	// Region is the region to send requests to.
     27 	Region string
     28 
     29 	// Credentials object to use when signing requests.
     30 	Credentials aws.CredentialsProvider
     31 
     32 	// Token provider for authentication operations with bearer authentication.
     33 	BearerAuthTokenProvider smithybearer.TokenProvider
     34 
     35 	// HTTPClient the SDK's API clients will use to invoke HTTP requests.
     36 	HTTPClient HTTPClient
     37 
     38 	// EndpointResolver that can be used to provide or override an endpoint for
     39 	// the given service and region.
     40 	//
     41 	// See the `aws.EndpointResolver` documentation on usage.
     42 	//
     43 	// Deprecated: See EndpointResolverWithOptions
     44 	EndpointResolver aws.EndpointResolver
     45 
     46 	// EndpointResolverWithOptions that can be used to provide or override an
     47 	// endpoint for the given service and region.
     48 	//
     49 	// See the `aws.EndpointResolverWithOptions` documentation on usage.
     50 	EndpointResolverWithOptions aws.EndpointResolverWithOptions
     51 
     52 	// RetryMaxAttempts specifies the maximum number attempts an API client
     53 	// will call an operation that fails with a retryable error.
     54 	//
     55 	// This value will only be used if Retryer option is nil.
     56 	RetryMaxAttempts int
     57 
     58 	// RetryMode specifies the retry model the API client will be created with.
     59 	//
     60 	// This value will only be used if Retryer option is nil.
     61 	RetryMode aws.RetryMode
     62 
     63 	// Retryer is a function that provides a Retryer implementation. A Retryer
     64 	// guides how HTTP requests should be retried in case of recoverable
     65 	// failures.
     66 	//
     67 	// If not nil, RetryMaxAttempts, and RetryMode will be ignored.
     68 	Retryer func() aws.Retryer
     69 
     70 	// APIOptions provides the set of middleware mutations modify how the API
     71 	// client requests will be handled. This is useful for adding additional
     72 	// tracing data to a request, or changing behavior of the SDK's client.
     73 	APIOptions []func(*middleware.Stack) error
     74 
     75 	// Logger writer interface to write logging messages to.
     76 	Logger logging.Logger
     77 
     78 	// ClientLogMode is used to configure the events that will be sent to the
     79 	// configured logger. This can be used to configure the logging of signing,
     80 	// retries, request, and responses of the SDK clients.
     81 	//
     82 	// See the ClientLogMode type documentation for the complete set of logging
     83 	// modes and available configuration.
     84 	ClientLogMode *aws.ClientLogMode
     85 
     86 	// SharedConfigProfile is the profile to be used when loading the SharedConfig
     87 	SharedConfigProfile string
     88 
     89 	// SharedConfigFiles is the slice of custom shared config files to use when
     90 	// loading the SharedConfig. A non-default profile used within config file
     91 	// must have name defined with prefix 'profile '. eg [profile xyz]
     92 	// indicates a profile with name 'xyz'. To read more on the format of the
     93 	// config file, please refer the documentation at
     94 	// https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-config
     95 	//
     96 	// If duplicate profiles are provided within the same, or across multiple
     97 	// shared config files, the next parsed profile will override only the
     98 	// properties that conflict with the previously defined profile. Note that
     99 	// if duplicate profiles are provided within the SharedCredentialsFiles and
    100 	// SharedConfigFiles, the properties defined in shared credentials file
    101 	// take precedence.
    102 	SharedConfigFiles []string
    103 
    104 	// SharedCredentialsFile is the slice of custom shared credentials files to
    105 	// use when loading the SharedConfig. The profile name used within
    106 	// credentials file must not prefix 'profile '. eg [xyz] indicates a
    107 	// profile with name 'xyz'. Profile declared as [profile xyz] will be
    108 	// ignored. To read more on the format of the credentials file, please
    109 	// refer the documentation at
    110 	// https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html#file-format-creds
    111 	//
    112 	// If duplicate profiles are provided with a same, or across multiple
    113 	// shared credentials files, the next parsed profile will override only
    114 	// properties that conflict with the previously defined profile. Note that
    115 	// if duplicate profiles are provided within the SharedCredentialsFiles and
    116 	// SharedConfigFiles, the properties defined in shared credentials file
    117 	// take precedence.
    118 	SharedCredentialsFiles []string
    119 
    120 	// CustomCABundle is CA bundle PEM bytes reader
    121 	CustomCABundle io.Reader
    122 
    123 	// DefaultRegion is the fall back region, used if a region was not resolved
    124 	// from other sources
    125 	DefaultRegion string
    126 
    127 	// UseEC2IMDSRegion indicates if SDK should retrieve the region
    128 	// from the EC2 Metadata service
    129 	UseEC2IMDSRegion *UseEC2IMDSRegion
    130 
    131 	// CredentialsCacheOptions is a function for setting the
    132 	// aws.CredentialsCacheOptions
    133 	CredentialsCacheOptions func(*aws.CredentialsCacheOptions)
    134 
    135 	// BearerAuthTokenCacheOptions is a function for setting the smithy-go
    136 	// auth/bearer#TokenCacheOptions
    137 	BearerAuthTokenCacheOptions func(*smithybearer.TokenCacheOptions)
    138 
    139 	// SSOTokenProviderOptions is a function for setting the
    140 	// credentials/ssocreds.SSOTokenProviderOptions
    141 	SSOTokenProviderOptions func(*ssocreds.SSOTokenProviderOptions)
    142 
    143 	// ProcessCredentialOptions is a function for setting
    144 	// the processcreds.Options
    145 	ProcessCredentialOptions func(*processcreds.Options)
    146 
    147 	// EC2RoleCredentialOptions is a function for setting
    148 	// the ec2rolecreds.Options
    149 	EC2RoleCredentialOptions func(*ec2rolecreds.Options)
    150 
    151 	// EndpointCredentialOptions is a function for setting
    152 	// the endpointcreds.Options
    153 	EndpointCredentialOptions func(*endpointcreds.Options)
    154 
    155 	// WebIdentityRoleCredentialOptions is a function for setting
    156 	// the stscreds.WebIdentityRoleOptions
    157 	WebIdentityRoleCredentialOptions func(*stscreds.WebIdentityRoleOptions)
    158 
    159 	// AssumeRoleCredentialOptions is a function for setting the
    160 	// stscreds.AssumeRoleOptions
    161 	AssumeRoleCredentialOptions func(*stscreds.AssumeRoleOptions)
    162 
    163 	// SSOProviderOptions is a function for setting
    164 	// the ssocreds.Options
    165 	SSOProviderOptions func(options *ssocreds.Options)
    166 
    167 	// LogConfigurationWarnings when set to true, enables logging
    168 	// configuration warnings
    169 	LogConfigurationWarnings *bool
    170 
    171 	// S3UseARNRegion specifies if the S3 service should allow ARNs to direct
    172 	// the region, the client's requests are sent to.
    173 	S3UseARNRegion *bool
    174 
    175 	// EnableEndpointDiscovery specifies if endpoint discovery is enable for
    176 	// the client.
    177 	EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
    178 
    179 	// Specifies if the EC2 IMDS service client is enabled.
    180 	//
    181 	// AWS_EC2_METADATA_DISABLED=true
    182 	EC2IMDSClientEnableState imds.ClientEnableState
    183 
    184 	// Specifies the EC2 Instance Metadata Service default endpoint selection
    185 	// mode (IPv4 or IPv6)
    186 	EC2IMDSEndpointMode imds.EndpointModeState
    187 
    188 	// Specifies the EC2 Instance Metadata Service endpoint to use. If
    189 	// specified it overrides EC2IMDSEndpointMode.
    190 	EC2IMDSEndpoint string
    191 
    192 	// Specifies that SDK clients must resolve a dual-stack endpoint for
    193 	// services.
    194 	UseDualStackEndpoint aws.DualStackEndpointState
    195 
    196 	// Specifies that SDK clients must resolve a FIPS endpoint for
    197 	// services.
    198 	UseFIPSEndpoint aws.FIPSEndpointState
    199 
    200 	// Specifies the SDK configuration mode for defaults.
    201 	DefaultsModeOptions DefaultsModeOptions
    202 }
    203 
    204 func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
    205 	if len(o.DefaultsModeOptions.Mode) == 0 {
    206 		return "", false, nil
    207 	}
    208 	return o.DefaultsModeOptions.Mode, true, nil
    209 }
    210 
    211 // GetRetryMaxAttempts returns the RetryMaxAttempts if specified in the
    212 // LoadOptions and not 0.
    213 func (o LoadOptions) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) {
    214 	if o.RetryMaxAttempts == 0 {
    215 		return 0, false, nil
    216 	}
    217 	return o.RetryMaxAttempts, true, nil
    218 }
    219 
    220 // GetRetryMode returns the RetryMode specified in the LoadOptions.
    221 func (o LoadOptions) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
    222 	if len(o.RetryMode) == 0 {
    223 		return "", false, nil
    224 	}
    225 	return o.RetryMode, true, nil
    226 }
    227 
    228 func (o LoadOptions) getDefaultsModeIMDSClient(ctx context.Context) (*imds.Client, bool, error) {
    229 	if o.DefaultsModeOptions.IMDSClient == nil {
    230 		return nil, false, nil
    231 	}
    232 	return o.DefaultsModeOptions.IMDSClient, true, nil
    233 }
    234 
    235 // getRegion returns Region from config's LoadOptions
    236 func (o LoadOptions) getRegion(ctx context.Context) (string, bool, error) {
    237 	if len(o.Region) == 0 {
    238 		return "", false, nil
    239 	}
    240 
    241 	return o.Region, true, nil
    242 }
    243 
    244 // WithRegion is a helper function to construct functional options
    245 // that sets Region on config's LoadOptions. Setting the region to
    246 // an empty string, will result in the region value being ignored.
    247 // If multiple WithRegion calls are made, the last call overrides
    248 // the previous call values.
    249 func WithRegion(v string) LoadOptionsFunc {
    250 	return func(o *LoadOptions) error {
    251 		o.Region = v
    252 		return nil
    253 	}
    254 }
    255 
    256 // getDefaultRegion returns DefaultRegion from config's LoadOptions
    257 func (o LoadOptions) getDefaultRegion(ctx context.Context) (string, bool, error) {
    258 	if len(o.DefaultRegion) == 0 {
    259 		return "", false, nil
    260 	}
    261 
    262 	return o.DefaultRegion, true, nil
    263 }
    264 
    265 // WithDefaultRegion is a helper function to construct functional options
    266 // that sets a DefaultRegion on config's LoadOptions. Setting the default
    267 // region to an empty string, will result in the default region value
    268 // being ignored. If multiple WithDefaultRegion calls are made, the last
    269 // call overrides the previous call values. Note that both WithRegion and
    270 // WithEC2IMDSRegion call takes precedence over WithDefaultRegion call
    271 // when resolving region.
    272 func WithDefaultRegion(v string) LoadOptionsFunc {
    273 	return func(o *LoadOptions) error {
    274 		o.DefaultRegion = v
    275 		return nil
    276 	}
    277 }
    278 
    279 // getSharedConfigProfile returns SharedConfigProfile from config's LoadOptions
    280 func (o LoadOptions) getSharedConfigProfile(ctx context.Context) (string, bool, error) {
    281 	if len(o.SharedConfigProfile) == 0 {
    282 		return "", false, nil
    283 	}
    284 
    285 	return o.SharedConfigProfile, true, nil
    286 }
    287 
    288 // WithSharedConfigProfile is a helper function to construct functional options
    289 // that sets SharedConfigProfile on config's LoadOptions. Setting the shared
    290 // config profile to an empty string, will result in the shared config profile
    291 // value being ignored.
    292 // If multiple WithSharedConfigProfile calls are made, the last call overrides
    293 // the previous call values.
    294 func WithSharedConfigProfile(v string) LoadOptionsFunc {
    295 	return func(o *LoadOptions) error {
    296 		o.SharedConfigProfile = v
    297 		return nil
    298 	}
    299 }
    300 
    301 // getSharedConfigFiles returns SharedConfigFiles set on config's LoadOptions
    302 func (o LoadOptions) getSharedConfigFiles(ctx context.Context) ([]string, bool, error) {
    303 	if o.SharedConfigFiles == nil {
    304 		return nil, false, nil
    305 	}
    306 
    307 	return o.SharedConfigFiles, true, nil
    308 }
    309 
    310 // WithSharedConfigFiles is a helper function to construct functional options
    311 // that sets slice of SharedConfigFiles on config's LoadOptions.
    312 // Setting the shared config files to an nil string slice, will result in the
    313 // shared config files value being ignored.
    314 // If multiple WithSharedConfigFiles calls are made, the last call overrides
    315 // the previous call values.
    316 func WithSharedConfigFiles(v []string) LoadOptionsFunc {
    317 	return func(o *LoadOptions) error {
    318 		o.SharedConfigFiles = v
    319 		return nil
    320 	}
    321 }
    322 
    323 // getSharedCredentialsFiles returns SharedCredentialsFiles set on config's LoadOptions
    324 func (o LoadOptions) getSharedCredentialsFiles(ctx context.Context) ([]string, bool, error) {
    325 	if o.SharedCredentialsFiles == nil {
    326 		return nil, false, nil
    327 	}
    328 
    329 	return o.SharedCredentialsFiles, true, nil
    330 }
    331 
    332 // WithSharedCredentialsFiles is a helper function to construct functional options
    333 // that sets slice of SharedCredentialsFiles on config's LoadOptions.
    334 // Setting the shared credentials files to an nil string slice, will result in the
    335 // shared credentials files value being ignored.
    336 // If multiple WithSharedCredentialsFiles calls are made, the last call overrides
    337 // the previous call values.
    338 func WithSharedCredentialsFiles(v []string) LoadOptionsFunc {
    339 	return func(o *LoadOptions) error {
    340 		o.SharedCredentialsFiles = v
    341 		return nil
    342 	}
    343 }
    344 
    345 // getCustomCABundle returns CustomCABundle from LoadOptions
    346 func (o LoadOptions) getCustomCABundle(ctx context.Context) (io.Reader, bool, error) {
    347 	if o.CustomCABundle == nil {
    348 		return nil, false, nil
    349 	}
    350 
    351 	return o.CustomCABundle, true, nil
    352 }
    353 
    354 // WithCustomCABundle is a helper function to construct functional options
    355 // that sets CustomCABundle on config's LoadOptions. Setting the custom CA Bundle
    356 // to nil will result in custom CA Bundle value being ignored.
    357 // If multiple WithCustomCABundle calls are made, the last call overrides the
    358 // previous call values.
    359 func WithCustomCABundle(v io.Reader) LoadOptionsFunc {
    360 	return func(o *LoadOptions) error {
    361 		o.CustomCABundle = v
    362 		return nil
    363 	}
    364 }
    365 
    366 // UseEC2IMDSRegion provides a regionProvider that retrieves the region
    367 // from the EC2 Metadata service.
    368 type UseEC2IMDSRegion struct {
    369 	// If unset will default to generic EC2 IMDS client.
    370 	Client *imds.Client
    371 }
    372 
    373 // getRegion attempts to retrieve the region from EC2 Metadata service.
    374 func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error) {
    375 	if ctx == nil {
    376 		ctx = context.Background()
    377 	}
    378 
    379 	client := p.Client
    380 	if client == nil {
    381 		client = imds.New(imds.Options{})
    382 	}
    383 
    384 	result, err := client.GetRegion(ctx, nil)
    385 	if err != nil {
    386 		return "", false, err
    387 	}
    388 	if len(result.Region) != 0 {
    389 		return result.Region, true, nil
    390 	}
    391 	return "", false, nil
    392 }
    393 
    394 // getEC2IMDSRegion returns the value of EC2 IMDS region.
    395 func (o LoadOptions) getEC2IMDSRegion(ctx context.Context) (string, bool, error) {
    396 	if o.UseEC2IMDSRegion == nil {
    397 		return "", false, nil
    398 	}
    399 
    400 	return o.UseEC2IMDSRegion.getRegion(ctx)
    401 }
    402 
    403 // WithEC2IMDSRegion is a helper function to construct functional options
    404 // that enables resolving EC2IMDS region. The function takes
    405 // in a UseEC2IMDSRegion functional option, and can be used to set the
    406 // EC2IMDS client which will be used to resolve EC2IMDSRegion.
    407 // If no functional option is provided, an EC2IMDS client is built and used
    408 // by the resolver. If multiple WithEC2IMDSRegion calls are made, the last
    409 // call overrides the previous call values. Note that the WithRegion calls takes
    410 // precedence over WithEC2IMDSRegion when resolving region.
    411 func WithEC2IMDSRegion(fnOpts ...func(o *UseEC2IMDSRegion)) LoadOptionsFunc {
    412 	return func(o *LoadOptions) error {
    413 		o.UseEC2IMDSRegion = &UseEC2IMDSRegion{}
    414 
    415 		for _, fn := range fnOpts {
    416 			fn(o.UseEC2IMDSRegion)
    417 		}
    418 		return nil
    419 	}
    420 }
    421 
    422 // getCredentialsProvider returns the credentials value
    423 func (o LoadOptions) getCredentialsProvider(ctx context.Context) (aws.CredentialsProvider, bool, error) {
    424 	if o.Credentials == nil {
    425 		return nil, false, nil
    426 	}
    427 
    428 	return o.Credentials, true, nil
    429 }
    430 
    431 // WithCredentialsProvider is a helper function to construct functional options
    432 // that sets Credential provider value on config's LoadOptions. If credentials
    433 // provider is set to nil, the credentials provider value will be ignored.
    434 // If multiple WithCredentialsProvider calls are made, the last call overrides
    435 // the previous call values.
    436 func WithCredentialsProvider(v aws.CredentialsProvider) LoadOptionsFunc {
    437 	return func(o *LoadOptions) error {
    438 		o.Credentials = v
    439 		return nil
    440 	}
    441 }
    442 
    443 // getCredentialsCacheOptionsProvider returns the wrapped function to set aws.CredentialsCacheOptions
    444 func (o LoadOptions) getCredentialsCacheOptions(ctx context.Context) (func(*aws.CredentialsCacheOptions), bool, error) {
    445 	if o.CredentialsCacheOptions == nil {
    446 		return nil, false, nil
    447 	}
    448 
    449 	return o.CredentialsCacheOptions, true, nil
    450 }
    451 
    452 // WithCredentialsCacheOptions is a helper function to construct functional
    453 // options that sets a function to modify the aws.CredentialsCacheOptions the
    454 // aws.CredentialsCache will be configured with, if the CredentialsCache is used
    455 // by the configuration loader.
    456 //
    457 // If multiple WithCredentialsCacheOptions calls are made, the last call
    458 // overrides the previous call values.
    459 func WithCredentialsCacheOptions(v func(*aws.CredentialsCacheOptions)) LoadOptionsFunc {
    460 	return func(o *LoadOptions) error {
    461 		o.CredentialsCacheOptions = v
    462 		return nil
    463 	}
    464 }
    465 
    466 // getBearerAuthTokenProvider returns the credentials value
    467 func (o LoadOptions) getBearerAuthTokenProvider(ctx context.Context) (smithybearer.TokenProvider, bool, error) {
    468 	if o.BearerAuthTokenProvider == nil {
    469 		return nil, false, nil
    470 	}
    471 
    472 	return o.BearerAuthTokenProvider, true, nil
    473 }
    474 
    475 // WithBearerAuthTokenProvider is a helper function to construct functional options
    476 // that sets Credential provider value on config's LoadOptions. If credentials
    477 // provider is set to nil, the credentials provider value will be ignored.
    478 // If multiple WithBearerAuthTokenProvider calls are made, the last call overrides
    479 // the previous call values.
    480 func WithBearerAuthTokenProvider(v smithybearer.TokenProvider) LoadOptionsFunc {
    481 	return func(o *LoadOptions) error {
    482 		o.BearerAuthTokenProvider = v
    483 		return nil
    484 	}
    485 }
    486 
    487 // getBearerAuthTokenCacheOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
    488 func (o LoadOptions) getBearerAuthTokenCacheOptions(ctx context.Context) (func(*smithybearer.TokenCacheOptions), bool, error) {
    489 	if o.BearerAuthTokenCacheOptions == nil {
    490 		return nil, false, nil
    491 	}
    492 
    493 	return o.BearerAuthTokenCacheOptions, true, nil
    494 }
    495 
    496 // WithBearerAuthTokenCacheOptions is a helper function to construct functional options
    497 // that sets a function to modify the TokenCacheOptions the smithy-go
    498 // auth/bearer#TokenCache will be configured with, if the TokenCache is used by
    499 // the configuration loader.
    500 //
    501 // If multiple WithBearerAuthTokenCacheOptions calls are made, the last call overrides
    502 // the previous call values.
    503 func WithBearerAuthTokenCacheOptions(v func(*smithybearer.TokenCacheOptions)) LoadOptionsFunc {
    504 	return func(o *LoadOptions) error {
    505 		o.BearerAuthTokenCacheOptions = v
    506 		return nil
    507 	}
    508 }
    509 
    510 // getSSOTokenProviderOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
    511 func (o LoadOptions) getSSOTokenProviderOptions(ctx context.Context) (func(*ssocreds.SSOTokenProviderOptions), bool, error) {
    512 	if o.SSOTokenProviderOptions == nil {
    513 		return nil, false, nil
    514 	}
    515 
    516 	return o.SSOTokenProviderOptions, true, nil
    517 }
    518 
    519 // WithSSOTokenProviderOptions is a helper function to construct functional
    520 // options that sets a function to modify the SSOtokenProviderOptions the SDK's
    521 // credentials/ssocreds#SSOProvider will be configured with, if the
    522 // SSOTokenProvider is used by the configuration loader.
    523 //
    524 // If multiple WithSSOTokenProviderOptions calls are made, the last call overrides
    525 // the previous call values.
    526 func WithSSOTokenProviderOptions(v func(*ssocreds.SSOTokenProviderOptions)) LoadOptionsFunc {
    527 	return func(o *LoadOptions) error {
    528 		o.SSOTokenProviderOptions = v
    529 		return nil
    530 	}
    531 }
    532 
    533 // getProcessCredentialOptions returns the wrapped function to set processcreds.Options
    534 func (o LoadOptions) getProcessCredentialOptions(ctx context.Context) (func(*processcreds.Options), bool, error) {
    535 	if o.ProcessCredentialOptions == nil {
    536 		return nil, false, nil
    537 	}
    538 
    539 	return o.ProcessCredentialOptions, true, nil
    540 }
    541 
    542 // WithProcessCredentialOptions is a helper function to construct functional options
    543 // that sets a function to use processcreds.Options on config's LoadOptions.
    544 // If process credential options is set to nil, the process credential value will
    545 // be ignored. If multiple WithProcessCredentialOptions calls are made, the last call
    546 // overrides the previous call values.
    547 func WithProcessCredentialOptions(v func(*processcreds.Options)) LoadOptionsFunc {
    548 	return func(o *LoadOptions) error {
    549 		o.ProcessCredentialOptions = v
    550 		return nil
    551 	}
    552 }
    553 
    554 // getEC2RoleCredentialOptions returns the wrapped function to set the ec2rolecreds.Options
    555 func (o LoadOptions) getEC2RoleCredentialOptions(ctx context.Context) (func(*ec2rolecreds.Options), bool, error) {
    556 	if o.EC2RoleCredentialOptions == nil {
    557 		return nil, false, nil
    558 	}
    559 
    560 	return o.EC2RoleCredentialOptions, true, nil
    561 }
    562 
    563 // WithEC2RoleCredentialOptions is a helper function to construct functional options
    564 // that sets a function to use ec2rolecreds.Options on config's LoadOptions. If
    565 // EC2 role credential options is set to nil, the EC2 role credential options value
    566 // will be ignored. If multiple WithEC2RoleCredentialOptions calls are made,
    567 // the last call overrides the previous call values.
    568 func WithEC2RoleCredentialOptions(v func(*ec2rolecreds.Options)) LoadOptionsFunc {
    569 	return func(o *LoadOptions) error {
    570 		o.EC2RoleCredentialOptions = v
    571 		return nil
    572 	}
    573 }
    574 
    575 // getEndpointCredentialOptions returns the wrapped function to set endpointcreds.Options
    576 func (o LoadOptions) getEndpointCredentialOptions(context.Context) (func(*endpointcreds.Options), bool, error) {
    577 	if o.EndpointCredentialOptions == nil {
    578 		return nil, false, nil
    579 	}
    580 
    581 	return o.EndpointCredentialOptions, true, nil
    582 }
    583 
    584 // WithEndpointCredentialOptions is a helper function to construct functional options
    585 // that sets a function to use endpointcreds.Options on config's LoadOptions. If
    586 // endpoint credential options is set to nil, the endpoint credential options
    587 // value will be ignored. If multiple WithEndpointCredentialOptions calls are made,
    588 // the last call overrides the previous call values.
    589 func WithEndpointCredentialOptions(v func(*endpointcreds.Options)) LoadOptionsFunc {
    590 	return func(o *LoadOptions) error {
    591 		o.EndpointCredentialOptions = v
    592 		return nil
    593 	}
    594 }
    595 
    596 // getWebIdentityRoleCredentialOptions returns the wrapped function
    597 func (o LoadOptions) getWebIdentityRoleCredentialOptions(context.Context) (func(*stscreds.WebIdentityRoleOptions), bool, error) {
    598 	if o.WebIdentityRoleCredentialOptions == nil {
    599 		return nil, false, nil
    600 	}
    601 
    602 	return o.WebIdentityRoleCredentialOptions, true, nil
    603 }
    604 
    605 // WithWebIdentityRoleCredentialOptions is a helper function to construct
    606 // functional options that sets a function to use stscreds.WebIdentityRoleOptions
    607 // on config's LoadOptions. If web identity role credentials options is set to nil,
    608 // the web identity role credentials value will be ignored. If multiple
    609 // WithWebIdentityRoleCredentialOptions calls are made, the last call
    610 // overrides the previous call values.
    611 func WithWebIdentityRoleCredentialOptions(v func(*stscreds.WebIdentityRoleOptions)) LoadOptionsFunc {
    612 	return func(o *LoadOptions) error {
    613 		o.WebIdentityRoleCredentialOptions = v
    614 		return nil
    615 	}
    616 }
    617 
    618 // getAssumeRoleCredentialOptions returns AssumeRoleCredentialOptions from LoadOptions
    619 func (o LoadOptions) getAssumeRoleCredentialOptions(context.Context) (func(options *stscreds.AssumeRoleOptions), bool, error) {
    620 	if o.AssumeRoleCredentialOptions == nil {
    621 		return nil, false, nil
    622 	}
    623 
    624 	return o.AssumeRoleCredentialOptions, true, nil
    625 }
    626 
    627 // WithAssumeRoleCredentialOptions  is a helper function to construct
    628 // functional options that sets a function to use stscreds.AssumeRoleOptions
    629 // on config's LoadOptions. If assume role credentials options is set to nil,
    630 // the assume role credentials value will be ignored. If multiple
    631 // WithAssumeRoleCredentialOptions calls are made, the last call overrides
    632 // the previous call values.
    633 func WithAssumeRoleCredentialOptions(v func(*stscreds.AssumeRoleOptions)) LoadOptionsFunc {
    634 	return func(o *LoadOptions) error {
    635 		o.AssumeRoleCredentialOptions = v
    636 		return nil
    637 	}
    638 }
    639 
    640 func (o LoadOptions) getHTTPClient(ctx context.Context) (HTTPClient, bool, error) {
    641 	if o.HTTPClient == nil {
    642 		return nil, false, nil
    643 	}
    644 
    645 	return o.HTTPClient, true, nil
    646 }
    647 
    648 // WithHTTPClient is a helper function to construct functional options
    649 // that sets HTTPClient on LoadOptions. If HTTPClient is set to nil,
    650 // the HTTPClient value will be ignored.
    651 // If multiple WithHTTPClient calls are made, the last call overrides
    652 // the previous call values.
    653 func WithHTTPClient(v HTTPClient) LoadOptionsFunc {
    654 	return func(o *LoadOptions) error {
    655 		o.HTTPClient = v
    656 		return nil
    657 	}
    658 }
    659 
    660 func (o LoadOptions) getAPIOptions(ctx context.Context) ([]func(*middleware.Stack) error, bool, error) {
    661 	if o.APIOptions == nil {
    662 		return nil, false, nil
    663 	}
    664 
    665 	return o.APIOptions, true, nil
    666 }
    667 
    668 // WithAPIOptions is a helper function to construct functional options
    669 // that sets APIOptions on LoadOptions. If APIOptions is set to nil, the
    670 // APIOptions value is ignored. If multiple WithAPIOptions calls are
    671 // made, the last call overrides the previous call values.
    672 func WithAPIOptions(v []func(*middleware.Stack) error) LoadOptionsFunc {
    673 	return func(o *LoadOptions) error {
    674 		if v == nil {
    675 			return nil
    676 		}
    677 
    678 		o.APIOptions = append(o.APIOptions, v...)
    679 		return nil
    680 	}
    681 }
    682 
    683 func (o LoadOptions) getRetryMaxAttempts(ctx context.Context) (int, bool, error) {
    684 	if o.RetryMaxAttempts == 0 {
    685 		return 0, false, nil
    686 	}
    687 
    688 	return o.RetryMaxAttempts, true, nil
    689 }
    690 
    691 // WithRetryMaxAttempts is a helper function to construct functional options that sets
    692 // RetryMaxAttempts on LoadOptions. If RetryMaxAttempts is unset, the RetryMaxAttempts value is
    693 // ignored. If multiple WithRetryMaxAttempts calls are made, the last call overrides
    694 // the previous call values.
    695 //
    696 // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
    697 func WithRetryMaxAttempts(v int) LoadOptionsFunc {
    698 	return func(o *LoadOptions) error {
    699 		o.RetryMaxAttempts = v
    700 		return nil
    701 	}
    702 }
    703 
    704 func (o LoadOptions) getRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
    705 	if o.RetryMode == "" {
    706 		return "", false, nil
    707 	}
    708 
    709 	return o.RetryMode, true, nil
    710 }
    711 
    712 // WithRetryMode is a helper function to construct functional options that sets
    713 // RetryMode on LoadOptions. If RetryMode is unset, the RetryMode value is
    714 // ignored. If multiple WithRetryMode calls are made, the last call overrides
    715 // the previous call values.
    716 //
    717 // Will be ignored of LoadOptions.Retryer or WithRetryer are used.
    718 func WithRetryMode(v aws.RetryMode) LoadOptionsFunc {
    719 	return func(o *LoadOptions) error {
    720 		o.RetryMode = v
    721 		return nil
    722 	}
    723 }
    724 
    725 func (o LoadOptions) getRetryer(ctx context.Context) (func() aws.Retryer, bool, error) {
    726 	if o.Retryer == nil {
    727 		return nil, false, nil
    728 	}
    729 
    730 	return o.Retryer, true, nil
    731 }
    732 
    733 // WithRetryer is a helper function to construct functional options
    734 // that sets Retryer on LoadOptions. If Retryer is set to nil, the
    735 // Retryer value is ignored. If multiple WithRetryer calls are
    736 // made, the last call overrides the previous call values.
    737 func WithRetryer(v func() aws.Retryer) LoadOptionsFunc {
    738 	return func(o *LoadOptions) error {
    739 		o.Retryer = v
    740 		return nil
    741 	}
    742 }
    743 
    744 func (o LoadOptions) getEndpointResolver(ctx context.Context) (aws.EndpointResolver, bool, error) {
    745 	if o.EndpointResolver == nil {
    746 		return nil, false, nil
    747 	}
    748 
    749 	return o.EndpointResolver, true, nil
    750 }
    751 
    752 // WithEndpointResolver is a helper function to construct functional options
    753 // that sets the EndpointResolver on LoadOptions. If the EndpointResolver is set to nil,
    754 // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
    755 // are made, the last call overrides the previous call values.
    756 //
    757 // Deprecated: See WithEndpointResolverWithOptions
    758 func WithEndpointResolver(v aws.EndpointResolver) LoadOptionsFunc {
    759 	return func(o *LoadOptions) error {
    760 		o.EndpointResolver = v
    761 		return nil
    762 	}
    763 }
    764 
    765 func (o LoadOptions) getEndpointResolverWithOptions(ctx context.Context) (aws.EndpointResolverWithOptions, bool, error) {
    766 	if o.EndpointResolverWithOptions == nil {
    767 		return nil, false, nil
    768 	}
    769 
    770 	return o.EndpointResolverWithOptions, true, nil
    771 }
    772 
    773 // WithEndpointResolverWithOptions is a helper function to construct functional options
    774 // that sets the EndpointResolverWithOptions on LoadOptions. If the EndpointResolverWithOptions is set to nil,
    775 // the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
    776 // are made, the last call overrides the previous call values.
    777 func WithEndpointResolverWithOptions(v aws.EndpointResolverWithOptions) LoadOptionsFunc {
    778 	return func(o *LoadOptions) error {
    779 		o.EndpointResolverWithOptions = v
    780 		return nil
    781 	}
    782 }
    783 
    784 func (o LoadOptions) getLogger(ctx context.Context) (logging.Logger, bool, error) {
    785 	if o.Logger == nil {
    786 		return nil, false, nil
    787 	}
    788 
    789 	return o.Logger, true, nil
    790 }
    791 
    792 // WithLogger is a helper function to construct functional options
    793 // that sets Logger on LoadOptions. If Logger is set to nil, the
    794 // Logger value will be ignored. If multiple WithLogger calls are made,
    795 // the last call overrides the previous call values.
    796 func WithLogger(v logging.Logger) LoadOptionsFunc {
    797 	return func(o *LoadOptions) error {
    798 		o.Logger = v
    799 		return nil
    800 	}
    801 }
    802 
    803 func (o LoadOptions) getClientLogMode(ctx context.Context) (aws.ClientLogMode, bool, error) {
    804 	if o.ClientLogMode == nil {
    805 		return 0, false, nil
    806 	}
    807 
    808 	return *o.ClientLogMode, true, nil
    809 }
    810 
    811 // WithClientLogMode is a helper function to construct functional options
    812 // that sets client log mode on LoadOptions. If client log mode is set to nil,
    813 // the client log mode value will be ignored. If multiple WithClientLogMode calls are made,
    814 // the last call overrides the previous call values.
    815 func WithClientLogMode(v aws.ClientLogMode) LoadOptionsFunc {
    816 	return func(o *LoadOptions) error {
    817 		o.ClientLogMode = &v
    818 		return nil
    819 	}
    820 }
    821 
    822 func (o LoadOptions) getLogConfigurationWarnings(ctx context.Context) (v bool, found bool, err error) {
    823 	if o.LogConfigurationWarnings == nil {
    824 		return false, false, nil
    825 	}
    826 	return *o.LogConfigurationWarnings, true, nil
    827 }
    828 
    829 // WithLogConfigurationWarnings is a helper function to construct
    830 // functional options that can be used to set LogConfigurationWarnings
    831 // on LoadOptions.
    832 //
    833 // If multiple WithLogConfigurationWarnings calls are made, the last call
    834 // overrides the previous call values.
    835 func WithLogConfigurationWarnings(v bool) LoadOptionsFunc {
    836 	return func(o *LoadOptions) error {
    837 		o.LogConfigurationWarnings = &v
    838 		return nil
    839 	}
    840 }
    841 
    842 // GetS3UseARNRegion returns whether to allow ARNs to direct the region
    843 // the S3 client's requests are sent to.
    844 func (o LoadOptions) GetS3UseARNRegion(ctx context.Context) (v bool, found bool, err error) {
    845 	if o.S3UseARNRegion == nil {
    846 		return false, false, nil
    847 	}
    848 	return *o.S3UseARNRegion, true, nil
    849 }
    850 
    851 // WithS3UseARNRegion is a helper function to construct functional options
    852 // that can be used to set S3UseARNRegion on LoadOptions.
    853 // If multiple WithS3UseARNRegion calls are made, the last call overrides
    854 // the previous call values.
    855 func WithS3UseARNRegion(v bool) LoadOptionsFunc {
    856 	return func(o *LoadOptions) error {
    857 		o.S3UseARNRegion = &v
    858 		return nil
    859 	}
    860 }
    861 
    862 // GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
    863 func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
    864 	if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {
    865 		return aws.EndpointDiscoveryUnset, false, nil
    866 	}
    867 	return o.EnableEndpointDiscovery, true, nil
    868 }
    869 
    870 // WithEndpointDiscovery is a helper function to construct functional options
    871 // that can be used to enable endpoint discovery on LoadOptions for supported clients.
    872 // If multiple WithEndpointDiscovery calls are made, the last call overrides
    873 // the previous call values.
    874 func WithEndpointDiscovery(v aws.EndpointDiscoveryEnableState) LoadOptionsFunc {
    875 	return func(o *LoadOptions) error {
    876 		o.EnableEndpointDiscovery = v
    877 		return nil
    878 	}
    879 }
    880 
    881 // getSSOProviderOptions returns AssumeRoleCredentialOptions from LoadOptions
    882 func (o LoadOptions) getSSOProviderOptions(context.Context) (func(options *ssocreds.Options), bool, error) {
    883 	if o.SSOProviderOptions == nil {
    884 		return nil, false, nil
    885 	}
    886 
    887 	return o.SSOProviderOptions, true, nil
    888 }
    889 
    890 // WithSSOProviderOptions is a helper function to construct
    891 // functional options that sets a function to use ssocreds.Options
    892 // on config's LoadOptions. If the SSO credential provider options is set to nil,
    893 // the sso provider options value will be ignored. If multiple
    894 // WithSSOProviderOptions calls are made, the last call overrides
    895 // the previous call values.
    896 func WithSSOProviderOptions(v func(*ssocreds.Options)) LoadOptionsFunc {
    897 	return func(o *LoadOptions) error {
    898 		o.SSOProviderOptions = v
    899 		return nil
    900 	}
    901 }
    902 
    903 // GetEC2IMDSClientEnableState implements a EC2IMDSClientEnableState options resolver interface.
    904 func (o LoadOptions) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error) {
    905 	if o.EC2IMDSClientEnableState == imds.ClientDefaultEnableState {
    906 		return imds.ClientDefaultEnableState, false, nil
    907 	}
    908 
    909 	return o.EC2IMDSClientEnableState, true, nil
    910 }
    911 
    912 // GetEC2IMDSEndpointMode implements a EC2IMDSEndpointMode option resolver interface.
    913 func (o LoadOptions) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error) {
    914 	if o.EC2IMDSEndpointMode == imds.EndpointModeStateUnset {
    915 		return imds.EndpointModeStateUnset, false, nil
    916 	}
    917 
    918 	return o.EC2IMDSEndpointMode, true, nil
    919 }
    920 
    921 // GetEC2IMDSEndpoint implements a EC2IMDSEndpoint option resolver interface.
    922 func (o LoadOptions) GetEC2IMDSEndpoint() (string, bool, error) {
    923 	if len(o.EC2IMDSEndpoint) == 0 {
    924 		return "", false, nil
    925 	}
    926 
    927 	return o.EC2IMDSEndpoint, true, nil
    928 }
    929 
    930 // WithEC2IMDSClientEnableState is a helper function to construct functional options that sets the EC2IMDSClientEnableState.
    931 func WithEC2IMDSClientEnableState(v imds.ClientEnableState) LoadOptionsFunc {
    932 	return func(o *LoadOptions) error {
    933 		o.EC2IMDSClientEnableState = v
    934 		return nil
    935 	}
    936 }
    937 
    938 // WithEC2IMDSEndpointMode is a helper function to construct functional options that sets the EC2IMDSEndpointMode.
    939 func WithEC2IMDSEndpointMode(v imds.EndpointModeState) LoadOptionsFunc {
    940 	return func(o *LoadOptions) error {
    941 		o.EC2IMDSEndpointMode = v
    942 		return nil
    943 	}
    944 }
    945 
    946 // WithEC2IMDSEndpoint is a helper function to construct functional options that sets the EC2IMDSEndpoint.
    947 func WithEC2IMDSEndpoint(v string) LoadOptionsFunc {
    948 	return func(o *LoadOptions) error {
    949 		o.EC2IMDSEndpoint = v
    950 		return nil
    951 	}
    952 }
    953 
    954 // WithUseDualStackEndpoint is a helper function to construct
    955 // functional options that can be used to set UseDualStackEndpoint on LoadOptions.
    956 func WithUseDualStackEndpoint(v aws.DualStackEndpointState) LoadOptionsFunc {
    957 	return func(o *LoadOptions) error {
    958 		o.UseDualStackEndpoint = v
    959 		return nil
    960 	}
    961 }
    962 
    963 // GetUseDualStackEndpoint returns whether the service's dual-stack endpoint should be
    964 // used for requests.
    965 func (o LoadOptions) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error) {
    966 	if o.UseDualStackEndpoint == aws.DualStackEndpointStateUnset {
    967 		return aws.DualStackEndpointStateUnset, false, nil
    968 	}
    969 	return o.UseDualStackEndpoint, true, nil
    970 }
    971 
    972 // WithUseFIPSEndpoint is a helper function to construct
    973 // functional options that can be used to set UseFIPSEndpoint on LoadOptions.
    974 func WithUseFIPSEndpoint(v aws.FIPSEndpointState) LoadOptionsFunc {
    975 	return func(o *LoadOptions) error {
    976 		o.UseFIPSEndpoint = v
    977 		return nil
    978 	}
    979 }
    980 
    981 // GetUseFIPSEndpoint returns whether the service's FIPS endpoint should be
    982 // used for requests.
    983 func (o LoadOptions) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEndpointState, found bool, err error) {
    984 	if o.UseFIPSEndpoint == aws.FIPSEndpointStateUnset {
    985 		return aws.FIPSEndpointStateUnset, false, nil
    986 	}
    987 	return o.UseFIPSEndpoint, true, nil
    988 }
    989 
    990 // WithDefaultsMode sets the SDK defaults configuration mode to the value provided.
    991 //
    992 // Zero or more functional options can be provided to provide configuration options for performing
    993 // environment discovery when using aws.DefaultsModeAuto.
    994 func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsModeOptions)) LoadOptionsFunc {
    995 	do := DefaultsModeOptions{
    996 		Mode: mode,
    997 	}
    998 	for _, fn := range optFns {
    999 		fn(&do)
   1000 	}
   1001 	return func(options *LoadOptions) error {
   1002 		options.DefaultsModeOptions = do
   1003 		return nil
   1004 	}
   1005 }