Bumps the aws-sdk-go-v2 group with 14 updates: | Package | From | To | | --- | --- | --- | | [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) | `1.28.9` | `1.29.0` | | [github.com/aws/aws-sdk-go-v2/credentials](https://github.com/aws/aws-sdk-go-v2) | `1.17.50` | `1.17.53` | | [github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue](https://github.com/aws/aws-sdk-go-v2) | `1.15.25` | `1.15.27` | | [github.com/aws/aws-sdk-go-v2/service/dynamodb](https://github.com/aws/aws-sdk-go-v2) | `1.39.2` | `1.39.4` | | [github.com/aws/aws-sdk-go-v2/service/kinesis](https://github.com/aws/aws-sdk-go-v2) | `1.32.10` | `1.32.12` | | [github.com/aws/aws-sdk-go-v2/feature/ec2/imds](https://github.com/aws/aws-sdk-go-v2) | `1.16.23` | `1.16.24` | | [github.com/aws/aws-sdk-go-v2/internal/configsources](https://github.com/aws/aws-sdk-go-v2) | `1.3.27` | `1.3.28` | | [github.com/aws/aws-sdk-go-v2/internal/endpoints/v2](https://github.com/aws/aws-sdk-go-v2) | `2.6.27` | `2.6.28` | | [github.com/aws/aws-sdk-go-v2/service/dynamodbstreams](https://github.com/aws/aws-sdk-go-v2) | `1.24.12` | `1.24.14` | | [github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery](https://github.com/aws/aws-sdk-go-v2) | `1.10.8` | `1.10.9` | | [github.com/aws/aws-sdk-go-v2/service/internal/presigned-url](https://github.com/aws/aws-sdk-go-v2) | `1.12.8` | `1.12.9` | | [github.com/aws/aws-sdk-go-v2/service/sso](https://github.com/aws/aws-sdk-go-v2) | `1.24.9` | `1.24.10` | | [github.com/aws/aws-sdk-go-v2/service/ssooidc](https://github.com/aws/aws-sdk-go-v2) | `1.28.8` | `1.28.9` | | [github.com/aws/aws-sdk-go-v2/service/sts](https://github.com/aws/aws-sdk-go-v2) | `1.33.5` | `1.33.8` | Updates `github.com/aws/aws-sdk-go-v2/config` from 1.28.9 to 1.29.0 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.28.9...v1.29.0) Updates `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.50 to 1.17.53 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.17.50...credentials/v1.17.53) Updates `github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue` from 1.15.25 to 1.15.27 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/kinesis/v1.15.25...service/apigateway/v1.15.27) Updates `github.com/aws/aws-sdk-go-v2/service/dynamodb` from 1.39.2 to 1.39.4 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/ivs/v1.39.2...service/ivs/v1.39.4) Updates `github.com/aws/aws-sdk-go-v2/service/kinesis` from 1.32.10 to 1.32.12 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/mgn/v1.32.10...service/kinesis/v1.32.12) Updates `github.com/aws/aws-sdk-go-v2/feature/ec2/imds` from 1.16.23 to 1.16.24 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/ram/v1.16.23...service/ram/v1.16.24) Updates `github.com/aws/aws-sdk-go-v2/internal/configsources` from 1.3.27 to 1.3.28 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/ini/v1.3.27...internal/ini/v1.3.28) Updates `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from 2.6.27 to 2.6.28 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/endpoints/v2.6.27...internal/endpoints/v2.6.28) Updates `github.com/aws/aws-sdk-go-v2/service/dynamodbstreams` from 1.24.12 to 1.24.14 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/fsx/v1.24.12...service/fsx/v1.24.14) Updates `github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery` from 1.10.8 to 1.10.9 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/m2/v1.10.8...service/rum/v1.10.9) Updates `github.com/aws/aws-sdk-go-v2/service/internal/presigned-url` from 1.12.8 to 1.12.9 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/fis/v1.12.8...service/fis/v1.12.9) Updates `github.com/aws/aws-sdk-go-v2/service/sso` from 1.24.9 to 1.24.10 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/fsx/v1.24.9...service/sso/v1.24.10) Updates `github.com/aws/aws-sdk-go-v2/service/ssooidc` from 1.28.8 to 1.28.9 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.28.8...config/v1.28.9) Updates `github.com/aws/aws-sdk-go-v2/service/sts` from 1.33.5 to 1.33.8 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/sts/v1.33.5...service/fms/v1.33.8) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go-v2/config dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/credentials dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodb dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/kinesis dependency-type: direct:production update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/feature/ec2/imds dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/internal/configsources dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodbstreams dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/presigned-url dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/sso dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/ssooidc dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 - dependency-name: github.com/aws/aws-sdk-go-v2/service/sts dependency-type: indirect update-type: version-update:semver-patch dependency-group: aws-sdk-go-v2 ... Signed-off-by: dependabot[bot] <support@github.com>
228 lines
7.8 KiB
Go
228 lines
7.8 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
)
|
|
|
|
// defaultAWSConfigResolvers are a slice of functions that will resolve external
|
|
// configuration values into AWS configuration values.
|
|
//
|
|
// This will setup the AWS configuration's Region,
|
|
var defaultAWSConfigResolvers = []awsConfigResolver{
|
|
// Resolves the default configuration the SDK's aws.Config will be
|
|
// initialized with.
|
|
resolveDefaultAWSConfig,
|
|
|
|
// Sets the logger to be used. Could be user provided logger, and client
|
|
// logging mode.
|
|
resolveLogger,
|
|
resolveClientLogMode,
|
|
|
|
// Sets the HTTP client and configuration to use for making requests using
|
|
// the HTTP transport.
|
|
resolveHTTPClient,
|
|
resolveCustomCABundle,
|
|
|
|
// Sets the endpoint resolving behavior the API Clients will use for making
|
|
// requests to. Clients default to their own clients this allows overrides
|
|
// to be specified. The resolveEndpointResolver option is deprecated, but
|
|
// we still need to set it for backwards compatibility on config
|
|
// construction.
|
|
resolveEndpointResolver,
|
|
resolveEndpointResolverWithOptions,
|
|
|
|
// Sets the retry behavior API clients will use within their retry attempt
|
|
// middleware. Defaults to unset, allowing API clients to define their own
|
|
// retry behavior.
|
|
resolveRetryer,
|
|
|
|
// Sets the region the API Clients should use for making requests to.
|
|
resolveRegion,
|
|
resolveEC2IMDSRegion,
|
|
resolveDefaultRegion,
|
|
|
|
// Sets the additional set of middleware stack mutators that will custom
|
|
// API client request pipeline middleware.
|
|
resolveAPIOptions,
|
|
|
|
// Resolves the DefaultsMode that should be used by SDK clients. If this
|
|
// mode is set to DefaultsModeAuto.
|
|
//
|
|
// Comes after HTTPClient and CustomCABundle to ensure the HTTP client is
|
|
// configured if provided before invoking IMDS if mode is auto. Comes
|
|
// before resolving credentials so that those subsequent clients use the
|
|
// configured auto mode.
|
|
resolveDefaultsModeOptions,
|
|
|
|
// Sets the resolved credentials the API clients will use for
|
|
// authentication. Provides the SDK's default credential chain.
|
|
//
|
|
// Should probably be the last step in the resolve chain to ensure that all
|
|
// other configurations are resolved first in case downstream credentials
|
|
// implementations depend on or can be configured with earlier resolved
|
|
// configuration options.
|
|
resolveCredentials,
|
|
|
|
// Sets the resolved bearer authentication token API clients will use for
|
|
// httpBearerAuth authentication scheme.
|
|
resolveBearerAuthToken,
|
|
|
|
// Sets the sdk app ID if present in env var or shared config profile
|
|
resolveAppID,
|
|
|
|
resolveBaseEndpoint,
|
|
|
|
// Sets the DisableRequestCompression if present in env var or shared config profile
|
|
resolveDisableRequestCompression,
|
|
|
|
// Sets the RequestMinCompressSizeBytes if present in env var or shared config profile
|
|
resolveRequestMinCompressSizeBytes,
|
|
|
|
// Sets the AccountIDEndpointMode if present in env var or shared config profile
|
|
resolveAccountIDEndpointMode,
|
|
|
|
// Sets the RequestChecksumCalculation if present in env var or shared config profile
|
|
resolveRequestChecksumCalculation,
|
|
|
|
// Sets the ResponseChecksumValidation if present in env var or shared config profile
|
|
resolveResponseChecksumValidation,
|
|
}
|
|
|
|
// A Config represents a generic configuration value or set of values. This type
|
|
// will be used by the AWSConfigResolvers to extract
|
|
//
|
|
// General the Config type will use type assertion against the Provider interfaces
|
|
// to extract specific data from the Config.
|
|
type Config interface{}
|
|
|
|
// A loader is used to load external configuration data and returns it as
|
|
// a generic Config type.
|
|
//
|
|
// The loader should return an error if it fails to load the external configuration
|
|
// or the configuration data is malformed, or required components missing.
|
|
type loader func(context.Context, configs) (Config, error)
|
|
|
|
// An awsConfigResolver will extract configuration data from the configs slice
|
|
// using the provider interfaces to extract specific functionality. The extracted
|
|
// configuration values will be written to the AWS Config value.
|
|
//
|
|
// The resolver should return an error if it it fails to extract the data, the
|
|
// data is malformed, or incomplete.
|
|
type awsConfigResolver func(ctx context.Context, cfg *aws.Config, configs configs) error
|
|
|
|
// configs is a slice of Config values. These values will be used by the
|
|
// AWSConfigResolvers to extract external configuration values to populate the
|
|
// AWS Config type.
|
|
//
|
|
// Use AppendFromLoaders to add additional external Config values that are
|
|
// loaded from external sources.
|
|
//
|
|
// Use ResolveAWSConfig after external Config values have been added or loaded
|
|
// to extract the loaded configuration values into the AWS Config.
|
|
type configs []Config
|
|
|
|
// AppendFromLoaders iterates over the slice of loaders passed in calling each
|
|
// loader function in order. The external config value returned by the loader
|
|
// will be added to the returned configs slice.
|
|
//
|
|
// If a loader returns an error this method will stop iterating and return
|
|
// that error.
|
|
func (cs configs) AppendFromLoaders(ctx context.Context, loaders []loader) (configs, error) {
|
|
for _, fn := range loaders {
|
|
cfg, err := fn(ctx, cs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cs = append(cs, cfg)
|
|
}
|
|
|
|
return cs, nil
|
|
}
|
|
|
|
// ResolveAWSConfig returns a AWS configuration populated with values by calling
|
|
// the resolvers slice passed in. Each resolver is called in order. Any resolver
|
|
// may overwrite the AWS Configuration value of a previous resolver.
|
|
//
|
|
// If an resolver returns an error this method will return that error, and stop
|
|
// iterating over the resolvers.
|
|
func (cs configs) ResolveAWSConfig(ctx context.Context, resolvers []awsConfigResolver) (aws.Config, error) {
|
|
var cfg aws.Config
|
|
|
|
for _, fn := range resolvers {
|
|
if err := fn(ctx, &cfg, cs); err != nil {
|
|
return aws.Config{}, err
|
|
}
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
// ResolveConfig calls the provide function passing slice of configuration sources.
|
|
// This implements the aws.ConfigResolver interface.
|
|
func (cs configs) ResolveConfig(f func(configs []interface{}) error) error {
|
|
var cfgs []interface{}
|
|
for i := range cs {
|
|
cfgs = append(cfgs, cs[i])
|
|
}
|
|
return f(cfgs)
|
|
}
|
|
|
|
// LoadDefaultConfig reads the SDK's default external configurations, and
|
|
// populates an AWS Config with the values from the external configurations.
|
|
//
|
|
// An optional variadic set of additional Config values can be provided as input
|
|
// that will be prepended to the configs slice. Use this to add custom configuration.
|
|
// The custom configurations must satisfy the respective providers for their data
|
|
// or the custom data will be ignored by the resolvers and config loaders.
|
|
//
|
|
// cfg, err := config.LoadDefaultConfig( context.TODO(),
|
|
// config.WithSharedConfigProfile("test-profile"),
|
|
// )
|
|
// if err != nil {
|
|
// panic(fmt.Sprintf("failed loading config, %v", err))
|
|
// }
|
|
//
|
|
// The default configuration sources are:
|
|
// * Environment Variables
|
|
// * Shared Configuration and Shared Credentials files.
|
|
func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) (cfg aws.Config, err error) {
|
|
var options LoadOptions
|
|
for _, optFn := range optFns {
|
|
if err := optFn(&options); err != nil {
|
|
return aws.Config{}, err
|
|
}
|
|
}
|
|
|
|
// assign Load Options to configs
|
|
var cfgCpy = configs{options}
|
|
|
|
cfgCpy, err = cfgCpy.AppendFromLoaders(ctx, resolveConfigLoaders(&options))
|
|
if err != nil {
|
|
return aws.Config{}, err
|
|
}
|
|
|
|
cfg, err = cfgCpy.ResolveAWSConfig(ctx, defaultAWSConfigResolvers)
|
|
if err != nil {
|
|
return aws.Config{}, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
func resolveConfigLoaders(options *LoadOptions) []loader {
|
|
loaders := make([]loader, 2)
|
|
loaders[0] = loadEnvConfig
|
|
|
|
// specification of a profile should cause a load failure if it doesn't exist
|
|
if os.Getenv(awsProfileEnvVar) != "" || options.SharedConfigProfile != "" {
|
|
loaders[1] = loadSharedConfig
|
|
} else {
|
|
loaders[1] = loadSharedConfigIgnoreNotExist
|
|
}
|
|
|
|
return loaders
|
|
}
|