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