load_options.go

   1package config
   2
   3import (
   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
  20type LoadOptionsFunc func(*LoadOptions) error
  21
  22// LoadOptions are discrete set of options that are valid for loading the
  23// configuration
  24type 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	// S3DisableMultiRegionAccessPoints specifies if the S3 service should disable
 176	// the S3 Multi-Region access points feature.
 177	S3DisableMultiRegionAccessPoints *bool
 178
 179	// EnableEndpointDiscovery specifies if endpoint discovery is enable for
 180	// the client.
 181	EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
 182
 183	// Specifies if the EC2 IMDS service client is enabled.
 184	//
 185	// AWS_EC2_METADATA_DISABLED=true
 186	EC2IMDSClientEnableState imds.ClientEnableState
 187
 188	// Specifies the EC2 Instance Metadata Service default endpoint selection
 189	// mode (IPv4 or IPv6)
 190	EC2IMDSEndpointMode imds.EndpointModeState
 191
 192	// Specifies the EC2 Instance Metadata Service endpoint to use. If
 193	// specified it overrides EC2IMDSEndpointMode.
 194	EC2IMDSEndpoint string
 195
 196	// Specifies that SDK clients must resolve a dual-stack endpoint for
 197	// services.
 198	UseDualStackEndpoint aws.DualStackEndpointState
 199
 200	// Specifies that SDK clients must resolve a FIPS endpoint for
 201	// services.
 202	UseFIPSEndpoint aws.FIPSEndpointState
 203
 204	// Specifies the SDK configuration mode for defaults.
 205	DefaultsModeOptions DefaultsModeOptions
 206
 207	// The sdk app ID retrieved from env var or shared config to be added to request user agent header
 208	AppID string
 209
 210	// Specifies whether an operation request could be compressed
 211	DisableRequestCompression *bool
 212
 213	// The inclusive min bytes of a request body that could be compressed
 214	RequestMinCompressSizeBytes *int64
 215
 216	// Whether S3 Express auth is disabled.
 217	S3DisableExpressAuth *bool
 218
 219	AccountIDEndpointMode aws.AccountIDEndpointMode
 220}
 221
 222func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
 223	if len(o.DefaultsModeOptions.Mode) == 0 {
 224		return "", false, nil
 225	}
 226	return o.DefaultsModeOptions.Mode, true, nil
 227}
 228
 229// GetRetryMaxAttempts returns the RetryMaxAttempts if specified in the
 230// LoadOptions and not 0.
 231func (o LoadOptions) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) {
 232	if o.RetryMaxAttempts == 0 {
 233		return 0, false, nil
 234	}
 235	return o.RetryMaxAttempts, true, nil
 236}
 237
 238// GetRetryMode returns the RetryMode specified in the LoadOptions.
 239func (o LoadOptions) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
 240	if len(o.RetryMode) == 0 {
 241		return "", false, nil
 242	}
 243	return o.RetryMode, true, nil
 244}
 245
 246func (o LoadOptions) getDefaultsModeIMDSClient(ctx context.Context) (*imds.Client, bool, error) {
 247	if o.DefaultsModeOptions.IMDSClient == nil {
 248		return nil, false, nil
 249	}
 250	return o.DefaultsModeOptions.IMDSClient, true, nil
 251}
 252
 253// getRegion returns Region from config's LoadOptions
 254func (o LoadOptions) getRegion(ctx context.Context) (string, bool, error) {
 255	if len(o.Region) == 0 {
 256		return "", false, nil
 257	}
 258
 259	return o.Region, true, nil
 260}
 261
 262// getAppID returns AppID from config's LoadOptions
 263func (o LoadOptions) getAppID(ctx context.Context) (string, bool, error) {
 264	return o.AppID, len(o.AppID) > 0, nil
 265}
 266
 267// getDisableRequestCompression returns DisableRequestCompression from config's LoadOptions
 268func (o LoadOptions) getDisableRequestCompression(ctx context.Context) (bool, bool, error) {
 269	if o.DisableRequestCompression == nil {
 270		return false, false, nil
 271	}
 272	return *o.DisableRequestCompression, true, nil
 273}
 274
 275// getRequestMinCompressSizeBytes returns RequestMinCompressSizeBytes from config's LoadOptions
 276func (o LoadOptions) getRequestMinCompressSizeBytes(ctx context.Context) (int64, bool, error) {
 277	if o.RequestMinCompressSizeBytes == nil {
 278		return 0, false, nil
 279	}
 280	return *o.RequestMinCompressSizeBytes, true, nil
 281}
 282
 283func (o LoadOptions) getAccountIDEndpointMode(ctx context.Context) (aws.AccountIDEndpointMode, bool, error) {
 284	return o.AccountIDEndpointMode, len(o.AccountIDEndpointMode) > 0, nil
 285}
 286
 287// WithRegion is a helper function to construct functional options
 288// that sets Region on config's LoadOptions. Setting the region to
 289// an empty string, will result in the region value being ignored.
 290// If multiple WithRegion calls are made, the last call overrides
 291// the previous call values.
 292func WithRegion(v string) LoadOptionsFunc {
 293	return func(o *LoadOptions) error {
 294		o.Region = v
 295		return nil
 296	}
 297}
 298
 299// WithAppID is a helper function to construct functional options
 300// that sets AppID on config's LoadOptions.
 301func WithAppID(ID string) LoadOptionsFunc {
 302	return func(o *LoadOptions) error {
 303		o.AppID = ID
 304		return nil
 305	}
 306}
 307
 308// WithDisableRequestCompression is a helper function to construct functional options
 309// that sets DisableRequestCompression on config's LoadOptions.
 310func WithDisableRequestCompression(DisableRequestCompression *bool) LoadOptionsFunc {
 311	return func(o *LoadOptions) error {
 312		if DisableRequestCompression == nil {
 313			return nil
 314		}
 315		o.DisableRequestCompression = DisableRequestCompression
 316		return nil
 317	}
 318}
 319
 320// WithRequestMinCompressSizeBytes is a helper function to construct functional options
 321// that sets RequestMinCompressSizeBytes on config's LoadOptions.
 322func WithRequestMinCompressSizeBytes(RequestMinCompressSizeBytes *int64) LoadOptionsFunc {
 323	return func(o *LoadOptions) error {
 324		if RequestMinCompressSizeBytes == nil {
 325			return nil
 326		}
 327		o.RequestMinCompressSizeBytes = RequestMinCompressSizeBytes
 328		return nil
 329	}
 330}
 331
 332// WithAccountIDEndpointMode is a helper function to construct functional options
 333// that sets AccountIDEndpointMode on config's LoadOptions
 334func WithAccountIDEndpointMode(m aws.AccountIDEndpointMode) LoadOptionsFunc {
 335	return func(o *LoadOptions) error {
 336		if m != "" {
 337			o.AccountIDEndpointMode = m
 338		}
 339		return nil
 340	}
 341}
 342
 343// getDefaultRegion returns DefaultRegion from config's LoadOptions
 344func (o LoadOptions) getDefaultRegion(ctx context.Context) (string, bool, error) {
 345	if len(o.DefaultRegion) == 0 {
 346		return "", false, nil
 347	}
 348
 349	return o.DefaultRegion, true, nil
 350}
 351
 352// WithDefaultRegion is a helper function to construct functional options
 353// that sets a DefaultRegion on config's LoadOptions. Setting the default
 354// region to an empty string, will result in the default region value
 355// being ignored. If multiple WithDefaultRegion calls are made, the last
 356// call overrides the previous call values. Note that both WithRegion and
 357// WithEC2IMDSRegion call takes precedence over WithDefaultRegion call
 358// when resolving region.
 359func WithDefaultRegion(v string) LoadOptionsFunc {
 360	return func(o *LoadOptions) error {
 361		o.DefaultRegion = v
 362		return nil
 363	}
 364}
 365
 366// getSharedConfigProfile returns SharedConfigProfile from config's LoadOptions
 367func (o LoadOptions) getSharedConfigProfile(ctx context.Context) (string, bool, error) {
 368	if len(o.SharedConfigProfile) == 0 {
 369		return "", false, nil
 370	}
 371
 372	return o.SharedConfigProfile, true, nil
 373}
 374
 375// WithSharedConfigProfile is a helper function to construct functional options
 376// that sets SharedConfigProfile on config's LoadOptions. Setting the shared
 377// config profile to an empty string, will result in the shared config profile
 378// value being ignored.
 379// If multiple WithSharedConfigProfile calls are made, the last call overrides
 380// the previous call values.
 381func WithSharedConfigProfile(v string) LoadOptionsFunc {
 382	return func(o *LoadOptions) error {
 383		o.SharedConfigProfile = v
 384		return nil
 385	}
 386}
 387
 388// getSharedConfigFiles returns SharedConfigFiles set on config's LoadOptions
 389func (o LoadOptions) getSharedConfigFiles(ctx context.Context) ([]string, bool, error) {
 390	if o.SharedConfigFiles == nil {
 391		return nil, false, nil
 392	}
 393
 394	return o.SharedConfigFiles, true, nil
 395}
 396
 397// WithSharedConfigFiles is a helper function to construct functional options
 398// that sets slice of SharedConfigFiles on config's LoadOptions.
 399// Setting the shared config files to an nil string slice, will result in the
 400// shared config files value being ignored.
 401// If multiple WithSharedConfigFiles calls are made, the last call overrides
 402// the previous call values.
 403func WithSharedConfigFiles(v []string) LoadOptionsFunc {
 404	return func(o *LoadOptions) error {
 405		o.SharedConfigFiles = v
 406		return nil
 407	}
 408}
 409
 410// getSharedCredentialsFiles returns SharedCredentialsFiles set on config's LoadOptions
 411func (o LoadOptions) getSharedCredentialsFiles(ctx context.Context) ([]string, bool, error) {
 412	if o.SharedCredentialsFiles == nil {
 413		return nil, false, nil
 414	}
 415
 416	return o.SharedCredentialsFiles, true, nil
 417}
 418
 419// WithSharedCredentialsFiles is a helper function to construct functional options
 420// that sets slice of SharedCredentialsFiles on config's LoadOptions.
 421// Setting the shared credentials files to an nil string slice, will result in the
 422// shared credentials files value being ignored.
 423// If multiple WithSharedCredentialsFiles calls are made, the last call overrides
 424// the previous call values.
 425func WithSharedCredentialsFiles(v []string) LoadOptionsFunc {
 426	return func(o *LoadOptions) error {
 427		o.SharedCredentialsFiles = v
 428		return nil
 429	}
 430}
 431
 432// getCustomCABundle returns CustomCABundle from LoadOptions
 433func (o LoadOptions) getCustomCABundle(ctx context.Context) (io.Reader, bool, error) {
 434	if o.CustomCABundle == nil {
 435		return nil, false, nil
 436	}
 437
 438	return o.CustomCABundle, true, nil
 439}
 440
 441// WithCustomCABundle is a helper function to construct functional options
 442// that sets CustomCABundle on config's LoadOptions. Setting the custom CA Bundle
 443// to nil will result in custom CA Bundle value being ignored.
 444// If multiple WithCustomCABundle calls are made, the last call overrides the
 445// previous call values.
 446func WithCustomCABundle(v io.Reader) LoadOptionsFunc {
 447	return func(o *LoadOptions) error {
 448		o.CustomCABundle = v
 449		return nil
 450	}
 451}
 452
 453// UseEC2IMDSRegion provides a regionProvider that retrieves the region
 454// from the EC2 Metadata service.
 455type UseEC2IMDSRegion struct {
 456	// If unset will default to generic EC2 IMDS client.
 457	Client *imds.Client
 458}
 459
 460// getRegion attempts to retrieve the region from EC2 Metadata service.
 461func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error) {
 462	if ctx == nil {
 463		ctx = context.Background()
 464	}
 465
 466	client := p.Client
 467	if client == nil {
 468		client = imds.New(imds.Options{})
 469	}
 470
 471	result, err := client.GetRegion(ctx, nil)
 472	if err != nil {
 473		return "", false, err
 474	}
 475	if len(result.Region) != 0 {
 476		return result.Region, true, nil
 477	}
 478	return "", false, nil
 479}
 480
 481// getEC2IMDSRegion returns the value of EC2 IMDS region.
 482func (o LoadOptions) getEC2IMDSRegion(ctx context.Context) (string, bool, error) {
 483	if o.UseEC2IMDSRegion == nil {
 484		return "", false, nil
 485	}
 486
 487	return o.UseEC2IMDSRegion.getRegion(ctx)
 488}
 489
 490// WithEC2IMDSRegion is a helper function to construct functional options
 491// that enables resolving EC2IMDS region. The function takes
 492// in a UseEC2IMDSRegion functional option, and can be used to set the
 493// EC2IMDS client which will be used to resolve EC2IMDSRegion.
 494// If no functional option is provided, an EC2IMDS client is built and used
 495// by the resolver. If multiple WithEC2IMDSRegion calls are made, the last
 496// call overrides the previous call values. Note that the WithRegion calls takes
 497// precedence over WithEC2IMDSRegion when resolving region.
 498func WithEC2IMDSRegion(fnOpts ...func(o *UseEC2IMDSRegion)) LoadOptionsFunc {
 499	return func(o *LoadOptions) error {
 500		o.UseEC2IMDSRegion = &UseEC2IMDSRegion{}
 501
 502		for _, fn := range fnOpts {
 503			fn(o.UseEC2IMDSRegion)
 504		}
 505		return nil
 506	}
 507}
 508
 509// getCredentialsProvider returns the credentials value
 510func (o LoadOptions) getCredentialsProvider(ctx context.Context) (aws.CredentialsProvider, bool, error) {
 511	if o.Credentials == nil {
 512		return nil, false, nil
 513	}
 514
 515	return o.Credentials, true, nil
 516}
 517
 518// WithCredentialsProvider is a helper function to construct functional options
 519// that sets Credential provider value on config's LoadOptions. If credentials
 520// provider is set to nil, the credentials provider value will be ignored.
 521// If multiple WithCredentialsProvider calls are made, the last call overrides
 522// the previous call values.
 523func WithCredentialsProvider(v aws.CredentialsProvider) LoadOptionsFunc {
 524	return func(o *LoadOptions) error {
 525		o.Credentials = v
 526		return nil
 527	}
 528}
 529
 530// getCredentialsCacheOptionsProvider returns the wrapped function to set aws.CredentialsCacheOptions
 531func (o LoadOptions) getCredentialsCacheOptions(ctx context.Context) (func(*aws.CredentialsCacheOptions), bool, error) {
 532	if o.CredentialsCacheOptions == nil {
 533		return nil, false, nil
 534	}
 535
 536	return o.CredentialsCacheOptions, true, nil
 537}
 538
 539// WithCredentialsCacheOptions is a helper function to construct functional
 540// options that sets a function to modify the aws.CredentialsCacheOptions the
 541// aws.CredentialsCache will be configured with, if the CredentialsCache is used
 542// by the configuration loader.
 543//
 544// If multiple WithCredentialsCacheOptions calls are made, the last call
 545// overrides the previous call values.
 546func WithCredentialsCacheOptions(v func(*aws.CredentialsCacheOptions)) LoadOptionsFunc {
 547	return func(o *LoadOptions) error {
 548		o.CredentialsCacheOptions = v
 549		return nil
 550	}
 551}
 552
 553// getBearerAuthTokenProvider returns the credentials value
 554func (o LoadOptions) getBearerAuthTokenProvider(ctx context.Context) (smithybearer.TokenProvider, bool, error) {
 555	if o.BearerAuthTokenProvider == nil {
 556		return nil, false, nil
 557	}
 558
 559	return o.BearerAuthTokenProvider, true, nil
 560}
 561
 562// WithBearerAuthTokenProvider is a helper function to construct functional options
 563// that sets Credential provider value on config's LoadOptions. If credentials
 564// provider is set to nil, the credentials provider value will be ignored.
 565// If multiple WithBearerAuthTokenProvider calls are made, the last call overrides
 566// the previous call values.
 567func WithBearerAuthTokenProvider(v smithybearer.TokenProvider) LoadOptionsFunc {
 568	return func(o *LoadOptions) error {
 569		o.BearerAuthTokenProvider = v
 570		return nil
 571	}
 572}
 573
 574// getBearerAuthTokenCacheOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
 575func (o LoadOptions) getBearerAuthTokenCacheOptions(ctx context.Context) (func(*smithybearer.TokenCacheOptions), bool, error) {
 576	if o.BearerAuthTokenCacheOptions == nil {
 577		return nil, false, nil
 578	}
 579
 580	return o.BearerAuthTokenCacheOptions, true, nil
 581}
 582
 583// WithBearerAuthTokenCacheOptions is a helper function to construct functional options
 584// that sets a function to modify the TokenCacheOptions the smithy-go
 585// auth/bearer#TokenCache will be configured with, if the TokenCache is used by
 586// the configuration loader.
 587//
 588// If multiple WithBearerAuthTokenCacheOptions calls are made, the last call overrides
 589// the previous call values.
 590func WithBearerAuthTokenCacheOptions(v func(*smithybearer.TokenCacheOptions)) LoadOptionsFunc {
 591	return func(o *LoadOptions) error {
 592		o.BearerAuthTokenCacheOptions = v
 593		return nil
 594	}
 595}
 596
 597// getSSOTokenProviderOptionsProvider returns the wrapped function to set smithybearer.TokenCacheOptions
 598func (o LoadOptions) getSSOTokenProviderOptions(ctx context.Context) (func(*ssocreds.SSOTokenProviderOptions), bool, error) {
 599	if o.SSOTokenProviderOptions == nil {
 600		return nil, false, nil
 601	}
 602
 603	return o.SSOTokenProviderOptions, true, nil
 604}
 605
 606// WithSSOTokenProviderOptions is a helper function to construct functional
 607// options that sets a function to modify the SSOtokenProviderOptions the SDK's
 608// credentials/ssocreds#SSOProvider will be configured with, if the
 609// SSOTokenProvider is used by the configuration loader.
 610//
 611// If multiple WithSSOTokenProviderOptions calls are made, the last call overrides
 612// the previous call values.
 613func WithSSOTokenProviderOptions(v func(*ssocreds.SSOTokenProviderOptions)) LoadOptionsFunc {
 614	return func(o *LoadOptions) error {
 615		o.SSOTokenProviderOptions = v
 616		return nil
 617	}
 618}
 619
 620// getProcessCredentialOptions returns the wrapped function to set processcreds.Options
 621func (o LoadOptions) getProcessCredentialOptions(ctx context.Context) (func(*processcreds.Options), bool, error) {
 622	if o.ProcessCredentialOptions == nil {
 623		return nil, false, nil
 624	}
 625
 626	return o.ProcessCredentialOptions, true, nil
 627}
 628
 629// WithProcessCredentialOptions is a helper function to construct functional options
 630// that sets a function to use processcreds.Options on config's LoadOptions.
 631// If process credential options is set to nil, the process credential value will
 632// be ignored. If multiple WithProcessCredentialOptions calls are made, the last call
 633// overrides the previous call values.
 634func WithProcessCredentialOptions(v func(*processcreds.Options)) LoadOptionsFunc {
 635	return func(o *LoadOptions) error {
 636		o.ProcessCredentialOptions = v
 637		return nil
 638	}
 639}
 640
 641// getEC2RoleCredentialOptions returns the wrapped function to set the ec2rolecreds.Options
 642func (o LoadOptions) getEC2RoleCredentialOptions(ctx context.Context) (func(*ec2rolecreds.Options), bool, error) {
 643	if o.EC2RoleCredentialOptions == nil {
 644		return nil, false, nil
 645	}
 646
 647	return o.EC2RoleCredentialOptions, true, nil
 648}
 649
 650// WithEC2RoleCredentialOptions is a helper function to construct functional options
 651// that sets a function to use ec2rolecreds.Options on config's LoadOptions. If
 652// EC2 role credential options is set to nil, the EC2 role credential options value
 653// will be ignored. If multiple WithEC2RoleCredentialOptions calls are made,
 654// the last call overrides the previous call values.
 655func WithEC2RoleCredentialOptions(v func(*ec2rolecreds.Options)) LoadOptionsFunc {
 656	return func(o *LoadOptions) error {
 657		o.EC2RoleCredentialOptions = v
 658		return nil
 659	}
 660}
 661
 662// getEndpointCredentialOptions returns the wrapped function to set endpointcreds.Options
 663func (o LoadOptions) getEndpointCredentialOptions(context.Context) (func(*endpointcreds.Options), bool, error) {
 664	if o.EndpointCredentialOptions == nil {
 665		return nil, false, nil
 666	}
 667
 668	return o.EndpointCredentialOptions, true, nil
 669}
 670
 671// WithEndpointCredentialOptions is a helper function to construct functional options
 672// that sets a function to use endpointcreds.Options on config's LoadOptions. If
 673// endpoint credential options is set to nil, the endpoint credential options
 674// value will be ignored. If multiple WithEndpointCredentialOptions calls are made,
 675// the last call overrides the previous call values.
 676func WithEndpointCredentialOptions(v func(*endpointcreds.Options)) LoadOptionsFunc {
 677	return func(o *LoadOptions) error {
 678		o.EndpointCredentialOptions = v
 679		return nil
 680	}
 681}
 682
 683// getWebIdentityRoleCredentialOptions returns the wrapped function
 684func (o LoadOptions) getWebIdentityRoleCredentialOptions(context.Context) (func(*stscreds.WebIdentityRoleOptions), bool, error) {
 685	if o.WebIdentityRoleCredentialOptions == nil {
 686		return nil, false, nil
 687	}
 688
 689	return o.WebIdentityRoleCredentialOptions, true, nil
 690}
 691
 692// WithWebIdentityRoleCredentialOptions is a helper function to construct
 693// functional options that sets a function to use stscreds.WebIdentityRoleOptions
 694// on config's LoadOptions. If web identity role credentials options is set to nil,
 695// the web identity role credentials value will be ignored. If multiple
 696// WithWebIdentityRoleCredentialOptions calls are made, the last call
 697// overrides the previous call values.
 698func WithWebIdentityRoleCredentialOptions(v func(*stscreds.WebIdentityRoleOptions)) LoadOptionsFunc {
 699	return func(o *LoadOptions) error {
 700		o.WebIdentityRoleCredentialOptions = v
 701		return nil
 702	}
 703}
 704
 705// getAssumeRoleCredentialOptions returns AssumeRoleCredentialOptions from LoadOptions
 706func (o LoadOptions) getAssumeRoleCredentialOptions(context.Context) (func(options *stscreds.AssumeRoleOptions), bool, error) {
 707	if o.AssumeRoleCredentialOptions == nil {
 708		return nil, false, nil
 709	}
 710
 711	return o.AssumeRoleCredentialOptions, true, nil
 712}
 713
 714// WithAssumeRoleCredentialOptions  is a helper function to construct
 715// functional options that sets a function to use stscreds.AssumeRoleOptions
 716// on config's LoadOptions. If assume role credentials options is set to nil,
 717// the assume role credentials value will be ignored. If multiple
 718// WithAssumeRoleCredentialOptions calls are made, the last call overrides
 719// the previous call values.
 720func WithAssumeRoleCredentialOptions(v func(*stscreds.AssumeRoleOptions)) LoadOptionsFunc {
 721	return func(o *LoadOptions) error {
 722		o.AssumeRoleCredentialOptions = v
 723		return nil
 724	}
 725}
 726
 727func (o LoadOptions) getHTTPClient(ctx context.Context) (HTTPClient, bool, error) {
 728	if o.HTTPClient == nil {
 729		return nil, false, nil
 730	}
 731
 732	return o.HTTPClient, true, nil
 733}
 734
 735// WithHTTPClient is a helper function to construct functional options
 736// that sets HTTPClient on LoadOptions. If HTTPClient is set to nil,
 737// the HTTPClient value will be ignored.
 738// If multiple WithHTTPClient calls are made, the last call overrides
 739// the previous call values.
 740func WithHTTPClient(v HTTPClient) LoadOptionsFunc {
 741	return func(o *LoadOptions) error {
 742		o.HTTPClient = v
 743		return nil
 744	}
 745}
 746
 747func (o LoadOptions) getAPIOptions(ctx context.Context) ([]func(*middleware.Stack) error, bool, error) {
 748	if o.APIOptions == nil {
 749		return nil, false, nil
 750	}
 751
 752	return o.APIOptions, true, nil
 753}
 754
 755// WithAPIOptions is a helper function to construct functional options
 756// that sets APIOptions on LoadOptions. If APIOptions is set to nil, the
 757// APIOptions value is ignored. If multiple WithAPIOptions calls are
 758// made, the last call overrides the previous call values.
 759func WithAPIOptions(v []func(*middleware.Stack) error) LoadOptionsFunc {
 760	return func(o *LoadOptions) error {
 761		if v == nil {
 762			return nil
 763		}
 764
 765		o.APIOptions = append(o.APIOptions, v...)
 766		return nil
 767	}
 768}
 769
 770func (o LoadOptions) getRetryMaxAttempts(ctx context.Context) (int, bool, error) {
 771	if o.RetryMaxAttempts == 0 {
 772		return 0, false, nil
 773	}
 774
 775	return o.RetryMaxAttempts, true, nil
 776}
 777
 778// WithRetryMaxAttempts is a helper function to construct functional options that sets
 779// RetryMaxAttempts on LoadOptions. If RetryMaxAttempts is unset, the RetryMaxAttempts value is
 780// ignored. If multiple WithRetryMaxAttempts calls are made, the last call overrides
 781// the previous call values.
 782//
 783// Will be ignored of LoadOptions.Retryer or WithRetryer are used.
 784func WithRetryMaxAttempts(v int) LoadOptionsFunc {
 785	return func(o *LoadOptions) error {
 786		o.RetryMaxAttempts = v
 787		return nil
 788	}
 789}
 790
 791func (o LoadOptions) getRetryMode(ctx context.Context) (aws.RetryMode, bool, error) {
 792	if o.RetryMode == "" {
 793		return "", false, nil
 794	}
 795
 796	return o.RetryMode, true, nil
 797}
 798
 799// WithRetryMode is a helper function to construct functional options that sets
 800// RetryMode on LoadOptions. If RetryMode is unset, the RetryMode value is
 801// ignored. If multiple WithRetryMode calls are made, the last call overrides
 802// the previous call values.
 803//
 804// Will be ignored of LoadOptions.Retryer or WithRetryer are used.
 805func WithRetryMode(v aws.RetryMode) LoadOptionsFunc {
 806	return func(o *LoadOptions) error {
 807		o.RetryMode = v
 808		return nil
 809	}
 810}
 811
 812func (o LoadOptions) getRetryer(ctx context.Context) (func() aws.Retryer, bool, error) {
 813	if o.Retryer == nil {
 814		return nil, false, nil
 815	}
 816
 817	return o.Retryer, true, nil
 818}
 819
 820// WithRetryer is a helper function to construct functional options
 821// that sets Retryer on LoadOptions. If Retryer is set to nil, the
 822// Retryer value is ignored. If multiple WithRetryer calls are
 823// made, the last call overrides the previous call values.
 824func WithRetryer(v func() aws.Retryer) LoadOptionsFunc {
 825	return func(o *LoadOptions) error {
 826		o.Retryer = v
 827		return nil
 828	}
 829}
 830
 831func (o LoadOptions) getEndpointResolver(ctx context.Context) (aws.EndpointResolver, bool, error) {
 832	if o.EndpointResolver == nil {
 833		return nil, false, nil
 834	}
 835
 836	return o.EndpointResolver, true, nil
 837}
 838
 839// WithEndpointResolver is a helper function to construct functional options
 840// that sets the EndpointResolver on LoadOptions. If the EndpointResolver is set to nil,
 841// the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
 842// are made, the last call overrides the previous call values.
 843//
 844// Deprecated: The global endpoint resolution interface is deprecated. The API
 845// for endpoint resolution is now unique to each service and is set via the
 846// EndpointResolverV2 field on service client options. Use of
 847// WithEndpointResolver or WithEndpointResolverWithOptions will prevent you
 848// from using any endpoint-related service features released after the
 849// introduction of EndpointResolverV2. You may also encounter broken or
 850// unexpected behavior when using the old global interface with services that
 851// use many endpoint-related customizations such as S3.
 852func WithEndpointResolver(v aws.EndpointResolver) LoadOptionsFunc {
 853	return func(o *LoadOptions) error {
 854		o.EndpointResolver = v
 855		return nil
 856	}
 857}
 858
 859func (o LoadOptions) getEndpointResolverWithOptions(ctx context.Context) (aws.EndpointResolverWithOptions, bool, error) {
 860	if o.EndpointResolverWithOptions == nil {
 861		return nil, false, nil
 862	}
 863
 864	return o.EndpointResolverWithOptions, true, nil
 865}
 866
 867// WithEndpointResolverWithOptions is a helper function to construct functional options
 868// that sets the EndpointResolverWithOptions on LoadOptions. If the EndpointResolverWithOptions is set to nil,
 869// the EndpointResolver value is ignored. If multiple WithEndpointResolver calls
 870// are made, the last call overrides the previous call values.
 871//
 872// Deprecated: The global endpoint resolution interface is deprecated. See
 873// deprecation docs on [WithEndpointResolver].
 874func WithEndpointResolverWithOptions(v aws.EndpointResolverWithOptions) LoadOptionsFunc {
 875	return func(o *LoadOptions) error {
 876		o.EndpointResolverWithOptions = v
 877		return nil
 878	}
 879}
 880
 881func (o LoadOptions) getLogger(ctx context.Context) (logging.Logger, bool, error) {
 882	if o.Logger == nil {
 883		return nil, false, nil
 884	}
 885
 886	return o.Logger, true, nil
 887}
 888
 889// WithLogger is a helper function to construct functional options
 890// that sets Logger on LoadOptions. If Logger is set to nil, the
 891// Logger value will be ignored. If multiple WithLogger calls are made,
 892// the last call overrides the previous call values.
 893func WithLogger(v logging.Logger) LoadOptionsFunc {
 894	return func(o *LoadOptions) error {
 895		o.Logger = v
 896		return nil
 897	}
 898}
 899
 900func (o LoadOptions) getClientLogMode(ctx context.Context) (aws.ClientLogMode, bool, error) {
 901	if o.ClientLogMode == nil {
 902		return 0, false, nil
 903	}
 904
 905	return *o.ClientLogMode, true, nil
 906}
 907
 908// WithClientLogMode is a helper function to construct functional options
 909// that sets client log mode on LoadOptions. If client log mode is set to nil,
 910// the client log mode value will be ignored. If multiple WithClientLogMode calls are made,
 911// the last call overrides the previous call values.
 912func WithClientLogMode(v aws.ClientLogMode) LoadOptionsFunc {
 913	return func(o *LoadOptions) error {
 914		o.ClientLogMode = &v
 915		return nil
 916	}
 917}
 918
 919func (o LoadOptions) getLogConfigurationWarnings(ctx context.Context) (v bool, found bool, err error) {
 920	if o.LogConfigurationWarnings == nil {
 921		return false, false, nil
 922	}
 923	return *o.LogConfigurationWarnings, true, nil
 924}
 925
 926// WithLogConfigurationWarnings is a helper function to construct
 927// functional options that can be used to set LogConfigurationWarnings
 928// on LoadOptions.
 929//
 930// If multiple WithLogConfigurationWarnings calls are made, the last call
 931// overrides the previous call values.
 932func WithLogConfigurationWarnings(v bool) LoadOptionsFunc {
 933	return func(o *LoadOptions) error {
 934		o.LogConfigurationWarnings = &v
 935		return nil
 936	}
 937}
 938
 939// GetS3UseARNRegion returns whether to allow ARNs to direct the region
 940// the S3 client's requests are sent to.
 941func (o LoadOptions) GetS3UseARNRegion(ctx context.Context) (v bool, found bool, err error) {
 942	if o.S3UseARNRegion == nil {
 943		return false, false, nil
 944	}
 945	return *o.S3UseARNRegion, true, nil
 946}
 947
 948// WithS3UseARNRegion is a helper function to construct functional options
 949// that can be used to set S3UseARNRegion on LoadOptions.
 950// If multiple WithS3UseARNRegion calls are made, the last call overrides
 951// the previous call values.
 952func WithS3UseARNRegion(v bool) LoadOptionsFunc {
 953	return func(o *LoadOptions) error {
 954		o.S3UseARNRegion = &v
 955		return nil
 956	}
 957}
 958
 959// GetS3DisableMultiRegionAccessPoints returns whether to disable
 960// the S3 multi-region access points feature.
 961func (o LoadOptions) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (v bool, found bool, err error) {
 962	if o.S3DisableMultiRegionAccessPoints == nil {
 963		return false, false, nil
 964	}
 965	return *o.S3DisableMultiRegionAccessPoints, true, nil
 966}
 967
 968// WithS3DisableMultiRegionAccessPoints is a helper function to construct functional options
 969// that can be used to set S3DisableMultiRegionAccessPoints on LoadOptions.
 970// If multiple WithS3DisableMultiRegionAccessPoints calls are made, the last call overrides
 971// the previous call values.
 972func WithS3DisableMultiRegionAccessPoints(v bool) LoadOptionsFunc {
 973	return func(o *LoadOptions) error {
 974		o.S3DisableMultiRegionAccessPoints = &v
 975		return nil
 976	}
 977}
 978
 979// GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
 980func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
 981	if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {
 982		return aws.EndpointDiscoveryUnset, false, nil
 983	}
 984	return o.EnableEndpointDiscovery, true, nil
 985}
 986
 987// WithEndpointDiscovery is a helper function to construct functional options
 988// that can be used to enable endpoint discovery on LoadOptions for supported clients.
 989// If multiple WithEndpointDiscovery calls are made, the last call overrides
 990// the previous call values.
 991func WithEndpointDiscovery(v aws.EndpointDiscoveryEnableState) LoadOptionsFunc {
 992	return func(o *LoadOptions) error {
 993		o.EnableEndpointDiscovery = v
 994		return nil
 995	}
 996}
 997
 998// getSSOProviderOptions returns AssumeRoleCredentialOptions from LoadOptions
 999func (o LoadOptions) getSSOProviderOptions(context.Context) (func(options *ssocreds.Options), bool, error) {
1000	if o.SSOProviderOptions == nil {
1001		return nil, false, nil
1002	}
1003
1004	return o.SSOProviderOptions, true, nil
1005}
1006
1007// WithSSOProviderOptions is a helper function to construct
1008// functional options that sets a function to use ssocreds.Options
1009// on config's LoadOptions. If the SSO credential provider options is set to nil,
1010// the sso provider options value will be ignored. If multiple
1011// WithSSOProviderOptions calls are made, the last call overrides
1012// the previous call values.
1013func WithSSOProviderOptions(v func(*ssocreds.Options)) LoadOptionsFunc {
1014	return func(o *LoadOptions) error {
1015		o.SSOProviderOptions = v
1016		return nil
1017	}
1018}
1019
1020// GetEC2IMDSClientEnableState implements a EC2IMDSClientEnableState options resolver interface.
1021func (o LoadOptions) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error) {
1022	if o.EC2IMDSClientEnableState == imds.ClientDefaultEnableState {
1023		return imds.ClientDefaultEnableState, false, nil
1024	}
1025
1026	return o.EC2IMDSClientEnableState, true, nil
1027}
1028
1029// GetEC2IMDSEndpointMode implements a EC2IMDSEndpointMode option resolver interface.
1030func (o LoadOptions) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error) {
1031	if o.EC2IMDSEndpointMode == imds.EndpointModeStateUnset {
1032		return imds.EndpointModeStateUnset, false, nil
1033	}
1034
1035	return o.EC2IMDSEndpointMode, true, nil
1036}
1037
1038// GetEC2IMDSEndpoint implements a EC2IMDSEndpoint option resolver interface.
1039func (o LoadOptions) GetEC2IMDSEndpoint() (string, bool, error) {
1040	if len(o.EC2IMDSEndpoint) == 0 {
1041		return "", false, nil
1042	}
1043
1044	return o.EC2IMDSEndpoint, true, nil
1045}
1046
1047// WithEC2IMDSClientEnableState is a helper function to construct functional options that sets the EC2IMDSClientEnableState.
1048func WithEC2IMDSClientEnableState(v imds.ClientEnableState) LoadOptionsFunc {
1049	return func(o *LoadOptions) error {
1050		o.EC2IMDSClientEnableState = v
1051		return nil
1052	}
1053}
1054
1055// WithEC2IMDSEndpointMode is a helper function to construct functional options that sets the EC2IMDSEndpointMode.
1056func WithEC2IMDSEndpointMode(v imds.EndpointModeState) LoadOptionsFunc {
1057	return func(o *LoadOptions) error {
1058		o.EC2IMDSEndpointMode = v
1059		return nil
1060	}
1061}
1062
1063// WithEC2IMDSEndpoint is a helper function to construct functional options that sets the EC2IMDSEndpoint.
1064func WithEC2IMDSEndpoint(v string) LoadOptionsFunc {
1065	return func(o *LoadOptions) error {
1066		o.EC2IMDSEndpoint = v
1067		return nil
1068	}
1069}
1070
1071// WithUseDualStackEndpoint is a helper function to construct
1072// functional options that can be used to set UseDualStackEndpoint on LoadOptions.
1073func WithUseDualStackEndpoint(v aws.DualStackEndpointState) LoadOptionsFunc {
1074	return func(o *LoadOptions) error {
1075		o.UseDualStackEndpoint = v
1076		return nil
1077	}
1078}
1079
1080// GetUseDualStackEndpoint returns whether the service's dual-stack endpoint should be
1081// used for requests.
1082func (o LoadOptions) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error) {
1083	if o.UseDualStackEndpoint == aws.DualStackEndpointStateUnset {
1084		return aws.DualStackEndpointStateUnset, false, nil
1085	}
1086	return o.UseDualStackEndpoint, true, nil
1087}
1088
1089// WithUseFIPSEndpoint is a helper function to construct
1090// functional options that can be used to set UseFIPSEndpoint on LoadOptions.
1091func WithUseFIPSEndpoint(v aws.FIPSEndpointState) LoadOptionsFunc {
1092	return func(o *LoadOptions) error {
1093		o.UseFIPSEndpoint = v
1094		return nil
1095	}
1096}
1097
1098// GetUseFIPSEndpoint returns whether the service's FIPS endpoint should be
1099// used for requests.
1100func (o LoadOptions) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEndpointState, found bool, err error) {
1101	if o.UseFIPSEndpoint == aws.FIPSEndpointStateUnset {
1102		return aws.FIPSEndpointStateUnset, false, nil
1103	}
1104	return o.UseFIPSEndpoint, true, nil
1105}
1106
1107// WithDefaultsMode sets the SDK defaults configuration mode to the value provided.
1108//
1109// Zero or more functional options can be provided to provide configuration options for performing
1110// environment discovery when using aws.DefaultsModeAuto.
1111func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsModeOptions)) LoadOptionsFunc {
1112	do := DefaultsModeOptions{
1113		Mode: mode,
1114	}
1115	for _, fn := range optFns {
1116		fn(&do)
1117	}
1118	return func(options *LoadOptions) error {
1119		options.DefaultsModeOptions = do
1120		return nil
1121	}
1122}
1123
1124// GetS3DisableExpressAuth returns the configured value for
1125// [EnvConfig.S3DisableExpressAuth].
1126func (o LoadOptions) GetS3DisableExpressAuth() (value, ok bool) {
1127	if o.S3DisableExpressAuth == nil {
1128		return false, false
1129	}
1130
1131	return *o.S3DisableExpressAuth, true
1132}
1133
1134// WithS3DisableExpressAuth sets [LoadOptions.S3DisableExpressAuth]
1135// to the value provided.
1136func WithS3DisableExpressAuth(v bool) LoadOptionsFunc {
1137	return func(o *LoadOptions) error {
1138		o.S3DisableExpressAuth = &v
1139		return nil
1140	}
1141}