vendor: github.com/aws/aws-sdk-go-v2/config v1.26.6

vendor github.com/aws/aws-sdk-go-v2/config v1.26.6 and related dependencies.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-02-05 18:08:03 +01:00
parent 089982153f
commit 43ed470208
190 changed files with 12340 additions and 13837 deletions

View File

@ -1,3 +1,251 @@
# v1.26.6 (2024-01-22)
* **Bug Fix**: Remove invalid escaping of shared config values. All values in the shared config file will now be interpreted literally, save for fully-quoted strings which are unwrapped for legacy reasons.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.5 (2024-01-18)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.4 (2024-01-16)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.3 (2024-01-04)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.2 (2023-12-20)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.1 (2023-12-08)
* **Bug Fix**: Correct loading of [services *] sections into shared config.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.26.0 (2023-12-07)
* **Feature**: Support modeled request compression. The only algorithm supported at this time is `gzip`.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.12 (2023-12-06)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.11 (2023-12-01)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.10 (2023-11-30)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.9 (2023-11-29)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.8 (2023-11-28.3)
* **Bug Fix**: Correct resolution of S3Express auth disable toggle.
# v1.25.7 (2023-11-28.2)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.6 (2023-11-28)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.5 (2023-11-21)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.4 (2023-11-20)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.3 (2023-11-17)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.2 (2023-11-16)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.1 (2023-11-15)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.25.0 (2023-11-14)
* **Feature**: Add support for dynamic auth token from file and EKS container host in absolute/relative URIs in the HTTP credential provider.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.24.0 (2023-11-13)
* **Feature**: Replace the legacy config parser with a modern, less-strict implementation. Parsing failures within a section will now simply ignore the invalid line rather than silently drop the entire section.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.23.0 (2023-11-09.2)
* **Feature**: BREAKFIX: In order to support subproperty parsing, invalid property definitions must not be ignored
* **Dependency Update**: Updated to the latest SDK module versions
# v1.22.3 (2023-11-09)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.22.2 (2023-11-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.22.1 (2023-11-06)
* No change notes available for this release.
# v1.22.0 (2023-11-02)
* **Feature**: Add env and shared config settings for disabling IMDSv1 fallback.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.21.0 (2023-11-01)
* **Feature**: Adds support for configured endpoints via environment variables and the AWS shared configuration file.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.20.0 (2023-10-31)
* **Feature**: **BREAKING CHANGE**: Bump minimum go version to 1.19 per the revised [go version support policy](https://aws.amazon.com/blogs/developer/aws-sdk-for-go-aligns-with-go-release-policy-on-supported-runtimes/).
* **Dependency Update**: Updated to the latest SDK module versions
# v1.19.1 (2023-10-24)
* No change notes available for this release.
# v1.19.0 (2023-10-16)
* **Feature**: Modify logic of retrieving user agent appID from env config
# v1.18.45 (2023-10-12)
* **Bug Fix**: Fail to load config if an explicitly provided profile doesn't exist.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.44 (2023-10-06)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.43 (2023-10-02)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.42 (2023-09-22)
* **Bug Fix**: Fixed a bug where merging `max_attempts` or `duration_seconds` fields across shared config files with invalid values would silently default them to 0.
* **Bug Fix**: Move type assertion of config values out of the parsing stage, which resolves an issue where the contents of a profile would silently be dropped with certain numeric formats.
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.41 (2023-09-20)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.40 (2023-09-18)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.39 (2023-09-05)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.38 (2023-08-31)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.37 (2023-08-23)
* No change notes available for this release.
# v1.18.36 (2023-08-21)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.35 (2023-08-18)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.34 (2023-08-17)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.33 (2023-08-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.32 (2023-08-01)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.31 (2023-07-31)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.30 (2023-07-28)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.29 (2023-07-25)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.28 (2023-07-13)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.27 (2023-06-15)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.26 (2023-06-13)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.25 (2023-05-09)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.24 (2023-05-08)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.23 (2023-05-04)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.22 (2023-04-24)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.21 (2023-04-10)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.20 (2023-04-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.19 (2023-03-21)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.18 (2023-03-16)
* **Bug Fix**: Allow RoleARN to be set as functional option on STS WebIdentityRoleOptions. Fixes aws/aws-sdk-go-v2#2015.
# v1.18.17 (2023-03-14)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.18.16 (2023-03-10)
* **Dependency Update**: Updated to the latest SDK module versions

View File

@ -2,18 +2,11 @@ package config
import (
"context"
"os"
"github.com/aws/aws-sdk-go-v2/aws"
)
// defaultLoaders are a slice of functions that will read external configuration
// sources for configuration values. These values are read by the AWSConfigResolvers
// using interfaces to extract specific information from the external configuration.
var defaultLoaders = []loader{
loadEnvConfig,
loadSharedConfigIgnoreNotExist,
}
// defaultAWSConfigResolvers are a slice of functions that will resolve external
// configuration values into AWS configuration values.
//
@ -76,6 +69,17 @@ var defaultAWSConfigResolvers = []awsConfigResolver{
// 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,
}
// A Config represents a generic configuration value or set of values. This type
@ -167,7 +171,7 @@ func (cs configs) ResolveConfig(f func(configs []interface{}) error) error {
// or the custom data will be ignored by the resolvers and config loaders.
//
// cfg, err := config.LoadDefaultConfig( context.TODO(),
// WithSharedConfigProfile("test-profile"),
// config.WithSharedConfigProfile("test-profile"),
// )
// if err != nil {
// panic(fmt.Sprintf("failed loading config, %v", err))
@ -187,7 +191,7 @@ func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error)
// assign Load Options to configs
var cfgCpy = configs{options}
cfgCpy, err = cfgCpy.AppendFromLoaders(ctx, defaultLoaders)
cfgCpy, err = cfgCpy.AppendFromLoaders(ctx, resolveConfigLoaders(&options))
if err != nil {
return aws.Config{}, err
}
@ -199,3 +203,17 @@ func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error)
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
}

View File

@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression"
)
// CredentialsSourceName provides a name of the provider when config is
@ -57,7 +58,8 @@ const (
awsEc2MetadataServiceEndpointEnvVar = "AWS_EC2_METADATA_SERVICE_ENDPOINT"
awsEc2MetadataDisabled = "AWS_EC2_METADATA_DISABLED"
awsEc2MetadataDisabled = "AWS_EC2_METADATA_DISABLED"
awsEc2MetadataV1DisabledEnvVar = "AWS_EC2_METADATA_V1_DISABLED"
awsS3DisableMultiRegionAccessPointEnvVar = "AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS"
@ -69,6 +71,15 @@ const (
awsRetryMaxAttempts = "AWS_MAX_ATTEMPTS"
awsRetryMode = "AWS_RETRY_MODE"
awsSdkAppID = "AWS_SDK_UA_APP_ID"
awsIgnoreConfiguredEndpoints = "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS"
awsEndpointURL = "AWS_ENDPOINT_URL"
awsDisableRequestCompression = "AWS_DISABLE_REQUEST_COMPRESSION"
awsRequestMinCompressionSizeBytes = "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES"
awsS3DisableExpressSessionAuthEnv = "AWS_S3_DISABLE_EXPRESS_SESSION_AUTH"
)
var (
@ -205,6 +216,11 @@ type EnvConfig struct {
// AWS_EC2_METADATA_DISABLED=true
EC2IMDSClientEnableState imds.ClientEnableState
// Specifies if EC2 IMDSv1 fallback is disabled.
//
// AWS_EC2_METADATA_V1_DISABLED=true
EC2IMDSv1Disabled *bool
// Specifies the EC2 Instance Metadata Service default endpoint selection mode (IPv4 or IPv6)
//
// AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE=IPv6
@ -248,6 +264,32 @@ type EnvConfig struct {
//
// aws_retry_mode=standard
RetryMode aws.RetryMode
// aws sdk app ID that can be added to user agent header string
AppID string
// Flag used to disable configured endpoints.
IgnoreConfiguredEndpoints *bool
// Value to contain configured endpoints to be propagated to
// corresponding endpoint resolution field.
BaseEndpoint string
// determine if request compression is allowed, default to false
// retrieved from env var AWS_DISABLE_REQUEST_COMPRESSION
DisableRequestCompression *bool
// inclusive threshold request body size to trigger compression,
// default to 10240 and must be within 0 and 10485760 bytes inclusive
// retrieved from env var AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES
RequestMinCompressSizeBytes *int64
// Whether S3Express auth is disabled.
//
// This will NOT prevent requests from being made to S3Express buckets, it
// will only bypass the modified endpoint routing and signing behaviors
// associated with the feature.
S3DisableExpressAuth *bool
}
// loadEnvConfig reads configuration values from the OS's environment variables.
@ -288,6 +330,15 @@ func NewEnvConfig() (EnvConfig, error) {
cfg.RoleARN = os.Getenv(awsRoleARNEnvVar)
cfg.RoleSessionName = os.Getenv(awsRoleSessionNameEnvVar)
cfg.AppID = os.Getenv(awsSdkAppID)
if err := setBoolPtrFromEnvVal(&cfg.DisableRequestCompression, []string{awsDisableRequestCompression}); err != nil {
return cfg, err
}
if err := setInt64PtrFromEnvVal(&cfg.RequestMinCompressSizeBytes, []string{awsRequestMinCompressionSizeBytes}, smithyrequestcompression.MaxRequestMinCompressSizeBytes); err != nil {
return cfg, err
}
if err := setEndpointDiscoveryTypeFromEnvVal(&cfg.EnableEndpointDiscovery, []string{awsEnableEndpointDiscoveryEnvVar}); err != nil {
return cfg, err
}
@ -301,6 +352,9 @@ func NewEnvConfig() (EnvConfig, error) {
return cfg, err
}
cfg.EC2IMDSEndpoint = os.Getenv(awsEc2MetadataServiceEndpointEnvVar)
if err := setBoolPtrFromEnvVal(&cfg.EC2IMDSv1Disabled, []string{awsEc2MetadataV1DisabledEnvVar}); err != nil {
return cfg, err
}
if err := setBoolPtrFromEnvVal(&cfg.S3DisableMultiRegionAccessPoints, []string{awsS3DisableMultiRegionAccessPointEnvVar}); err != nil {
return cfg, err
@ -325,6 +379,16 @@ func NewEnvConfig() (EnvConfig, error) {
return cfg, err
}
setStringFromEnvVal(&cfg.BaseEndpoint, []string{awsEndpointURL})
if err := setBoolPtrFromEnvVal(&cfg.IgnoreConfiguredEndpoints, []string{awsIgnoreConfiguredEndpoints}); err != nil {
return cfg, err
}
if err := setBoolPtrFromEnvVal(&cfg.S3DisableExpressAuth, []string{awsS3DisableExpressSessionAuthEnv}); err != nil {
return cfg, err
}
return cfg, nil
}
@ -335,6 +399,24 @@ func (c EnvConfig) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool,
return c.DefaultsMode, true, nil
}
func (c EnvConfig) getAppID(context.Context) (string, bool, error) {
return c.AppID, len(c.AppID) > 0, nil
}
func (c EnvConfig) getDisableRequestCompression(context.Context) (bool, bool, error) {
if c.DisableRequestCompression == nil {
return false, false, nil
}
return *c.DisableRequestCompression, true, nil
}
func (c EnvConfig) getRequestMinCompressSizeBytes(context.Context) (int64, bool, error) {
if c.RequestMinCompressSizeBytes == nil {
return 0, false, nil
}
return *c.RequestMinCompressSizeBytes, true, nil
}
// GetRetryMaxAttempts returns the value of AWS_MAX_ATTEMPTS if was specified,
// and not 0.
func (c EnvConfig) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) {
@ -472,6 +554,34 @@ func (c EnvConfig) getCustomCABundle(context.Context) (io.Reader, bool, error) {
return bytes.NewReader(b), true, nil
}
// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
// endpoints feature.
func (c EnvConfig) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) {
if c.IgnoreConfiguredEndpoints == nil {
return false, false, nil
}
return *c.IgnoreConfiguredEndpoints, true, nil
}
func (c EnvConfig) getBaseEndpoint(context.Context) (string, bool, error) {
return c.BaseEndpoint, len(c.BaseEndpoint) > 0, nil
}
// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use
// with configured endpoints.
func (c EnvConfig) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) {
if endpt := os.Getenv(fmt.Sprintf("%s_%s", awsEndpointURL, normalizeEnv(sdkID))); endpt != "" {
return endpt, true, nil
}
return "", false, nil
}
func normalizeEnv(sdkID string) string {
upper := strings.ToUpper(sdkID)
return strings.ReplaceAll(upper, " ", "_")
}
// GetS3UseARNRegion returns whether to allow ARNs to direct the region
// the S3 client's requests are sent to.
func (c EnvConfig) GetS3UseARNRegion(ctx context.Context) (value, ok bool, err error) {
@ -482,9 +592,9 @@ func (c EnvConfig) GetS3UseARNRegion(ctx context.Context) (value, ok bool, err e
return *c.S3UseARNRegion, true, nil
}
// GetS3DisableMultRegionAccessPoints returns whether to disable multi-region access point
// GetS3DisableMultiRegionAccessPoints returns whether to disable multi-region access point
// support for the S3 client.
func (c EnvConfig) GetS3DisableMultRegionAccessPoints(ctx context.Context) (value, ok bool, err error) {
func (c EnvConfig) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (value, ok bool, err error) {
if c.S3DisableMultiRegionAccessPoints == nil {
return false, false, nil
}
@ -563,6 +673,30 @@ func setBoolPtrFromEnvVal(dst **bool, keys []string) error {
return nil
}
func setInt64PtrFromEnvVal(dst **int64, keys []string, max int64) error {
for _, k := range keys {
value := os.Getenv(k)
if len(value) == 0 {
continue
}
v, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return fmt.Errorf("invalid value for env var, %s=%s, need int64", k, value)
} else if v < 0 || v > max {
return fmt.Errorf("invalid range for env var min request compression size bytes %q, must be within 0 and 10485760 inclusively", v)
}
if *dst == nil {
*dst = new(int64)
}
**dst = v
break
}
return nil
}
func setEndpointDiscoveryTypeFromEnvVal(dst *aws.EndpointDiscoveryEnableState, keys []string) error {
for _, k := range keys {
value := os.Getenv(k)
@ -663,3 +797,23 @@ func (c EnvConfig) GetEC2IMDSEndpoint() (string, bool, error) {
return c.EC2IMDSEndpoint, true, nil
}
// GetEC2IMDSV1FallbackDisabled implements an EC2IMDSV1FallbackDisabled option
// resolver interface.
func (c EnvConfig) GetEC2IMDSV1FallbackDisabled() (bool, bool) {
if c.EC2IMDSv1Disabled == nil {
return false, false
}
return *c.EC2IMDSv1Disabled, true
}
// GetS3DisableExpressAuth returns the configured value for
// [EnvConfig.S3DisableExpressAuth].
func (c EnvConfig) GetS3DisableExpressAuth() (value, ok bool) {
if c.S3DisableExpressAuth == nil {
return false, false
}
return *c.S3DisableExpressAuth, true
}

View File

@ -3,4 +3,4 @@
package config
// goModuleVersion is the tagged release for this module
const goModuleVersion = "1.18.16"
const goModuleVersion = "1.26.6"

View File

@ -172,6 +172,10 @@ type LoadOptions struct {
// the region, the client's requests are sent to.
S3UseARNRegion *bool
// S3DisableMultiRegionAccessPoints specifies if the S3 service should disable
// the S3 Multi-Region access points feature.
S3DisableMultiRegionAccessPoints *bool
// EnableEndpointDiscovery specifies if endpoint discovery is enable for
// the client.
EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
@ -199,6 +203,18 @@ type LoadOptions struct {
// Specifies the SDK configuration mode for defaults.
DefaultsModeOptions DefaultsModeOptions
// The sdk app ID retrieved from env var or shared config to be added to request user agent header
AppID string
// Specifies whether an operation request could be compressed
DisableRequestCompression *bool
// The inclusive min bytes of a request body that could be compressed
RequestMinCompressSizeBytes *int64
// Whether S3 Express auth is disabled.
S3DisableExpressAuth *bool
}
func (o LoadOptions) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, error) {
@ -241,6 +257,27 @@ func (o LoadOptions) getRegion(ctx context.Context) (string, bool, error) {
return o.Region, true, nil
}
// getAppID returns AppID from config's LoadOptions
func (o LoadOptions) getAppID(ctx context.Context) (string, bool, error) {
return o.AppID, len(o.AppID) > 0, nil
}
// getDisableRequestCompression returns DisableRequestCompression from config's LoadOptions
func (o LoadOptions) getDisableRequestCompression(ctx context.Context) (bool, bool, error) {
if o.DisableRequestCompression == nil {
return false, false, nil
}
return *o.DisableRequestCompression, true, nil
}
// getRequestMinCompressSizeBytes returns RequestMinCompressSizeBytes from config's LoadOptions
func (o LoadOptions) getRequestMinCompressSizeBytes(ctx context.Context) (int64, bool, error) {
if o.RequestMinCompressSizeBytes == nil {
return 0, false, nil
}
return *o.RequestMinCompressSizeBytes, true, nil
}
// WithRegion is a helper function to construct functional options
// that sets Region on config's LoadOptions. Setting the region to
// an empty string, will result in the region value being ignored.
@ -253,6 +290,39 @@ func WithRegion(v string) LoadOptionsFunc {
}
}
// WithAppID is a helper function to construct functional options
// that sets AppID on config's LoadOptions.
func WithAppID(ID string) LoadOptionsFunc {
return func(o *LoadOptions) error {
o.AppID = ID
return nil
}
}
// WithDisableRequestCompression is a helper function to construct functional options
// that sets DisableRequestCompression on config's LoadOptions.
func WithDisableRequestCompression(DisableRequestCompression *bool) LoadOptionsFunc {
return func(o *LoadOptions) error {
if DisableRequestCompression == nil {
return nil
}
o.DisableRequestCompression = DisableRequestCompression
return nil
}
}
// WithRequestMinCompressSizeBytes is a helper function to construct functional options
// that sets RequestMinCompressSizeBytes on config's LoadOptions.
func WithRequestMinCompressSizeBytes(RequestMinCompressSizeBytes *int64) LoadOptionsFunc {
return func(o *LoadOptions) error {
if RequestMinCompressSizeBytes == nil {
return nil
}
o.RequestMinCompressSizeBytes = RequestMinCompressSizeBytes
return nil
}
}
// getDefaultRegion returns DefaultRegion from config's LoadOptions
func (o LoadOptions) getDefaultRegion(ctx context.Context) (string, bool, error) {
if len(o.DefaultRegion) == 0 {
@ -859,6 +929,26 @@ func WithS3UseARNRegion(v bool) LoadOptionsFunc {
}
}
// GetS3DisableMultiRegionAccessPoints returns whether to disable
// the S3 multi-region access points feature.
func (o LoadOptions) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (v bool, found bool, err error) {
if o.S3DisableMultiRegionAccessPoints == nil {
return false, false, nil
}
return *o.S3DisableMultiRegionAccessPoints, true, nil
}
// WithS3DisableMultiRegionAccessPoints is a helper function to construct functional options
// that can be used to set S3DisableMultiRegionAccessPoints on LoadOptions.
// If multiple WithS3DisableMultiRegionAccessPoints calls are made, the last call overrides
// the previous call values.
func WithS3DisableMultiRegionAccessPoints(v bool) LoadOptionsFunc {
return func(o *LoadOptions) error {
o.S3DisableMultiRegionAccessPoints = &v
return nil
}
}
// GetEnableEndpointDiscovery returns if the EnableEndpointDiscovery flag is set.
func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error) {
if o.EnableEndpointDiscovery == aws.EndpointDiscoveryUnset {
@ -1003,3 +1093,22 @@ func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsMod
return nil
}
}
// GetS3DisableExpressAuth returns the configured value for
// [EnvConfig.S3DisableExpressAuth].
func (o LoadOptions) GetS3DisableExpressAuth() (value, ok bool) {
if o.S3DisableExpressAuth == nil {
return false, false
}
return *o.S3DisableExpressAuth, true
}
// WithS3DisableExpressAuth sets [LoadOptions.S3DisableExpressAuth]
// to the value provided.
func WithS3DisableExpressAuth(v bool) LoadOptionsFunc {
return func(o *LoadOptions) error {
o.S3DisableExpressAuth = &v
return nil
}
}

View File

@ -122,6 +122,109 @@ func getRegion(ctx context.Context, configs configs) (value string, found bool,
return
}
// IgnoreConfiguredEndpointsProvider is needed to search for all providers
// that provide a flag to disable configured endpoints.
type IgnoreConfiguredEndpointsProvider interface {
GetIgnoreConfiguredEndpoints(ctx context.Context) (bool, bool, error)
}
// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
// endpoints feature.
func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []interface{}) (value bool, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(IgnoreConfiguredEndpointsProvider); ok {
value, found, err = p.GetIgnoreConfiguredEndpoints(ctx)
if err != nil || found {
break
}
}
}
return
}
type baseEndpointProvider interface {
getBaseEndpoint(ctx context.Context) (string, bool, error)
}
func getBaseEndpoint(ctx context.Context, configs configs) (value string, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(baseEndpointProvider); ok {
value, found, err = p.getBaseEndpoint(ctx)
if err != nil || found {
break
}
}
}
return
}
type servicesObjectProvider interface {
getServicesObject(ctx context.Context) (map[string]map[string]string, bool, error)
}
func getServicesObject(ctx context.Context, configs configs) (value map[string]map[string]string, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(servicesObjectProvider); ok {
value, found, err = p.getServicesObject(ctx)
if err != nil || found {
break
}
}
}
return
}
// appIDProvider provides access to the sdk app ID value
type appIDProvider interface {
getAppID(ctx context.Context) (string, bool, error)
}
func getAppID(ctx context.Context, configs configs) (value string, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(appIDProvider); ok {
value, found, err = p.getAppID(ctx)
if err != nil || found {
break
}
}
}
return
}
// disableRequestCompressionProvider provides access to the DisableRequestCompression
type disableRequestCompressionProvider interface {
getDisableRequestCompression(context.Context) (bool, bool, error)
}
func getDisableRequestCompression(ctx context.Context, configs configs) (value bool, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(disableRequestCompressionProvider); ok {
value, found, err = p.getDisableRequestCompression(ctx)
if err != nil || found {
break
}
}
}
return
}
// requestMinCompressSizeBytesProvider provides access to the MinCompressSizeBytes
type requestMinCompressSizeBytesProvider interface {
getRequestMinCompressSizeBytes(context.Context) (int64, bool, error)
}
func getRequestMinCompressSizeBytes(ctx context.Context, configs configs) (value int64, found bool, err error) {
for _, cfg := range configs {
if p, ok := cfg.(requestMinCompressSizeBytesProvider); ok {
value, found, err = p.getRequestMinCompressSizeBytes(ctx)
if err != nil || found {
break
}
}
}
return
}
// ec2IMDSRegionProvider provides access to the ec2 imds region
// configuration value
type ec2IMDSRegionProvider interface {

View File

@ -27,7 +27,6 @@ func resolveDefaultAWSConfig(ctx context.Context, cfg *aws.Config, cfgs configs)
}
*cfg = aws.Config{
Credentials: aws.AnonymousCredentials{},
Logger: logging.NewStandardLogger(os.Stderr),
ConfigSources: sources,
}
@ -106,6 +105,67 @@ func resolveRegion(ctx context.Context, cfg *aws.Config, configs configs) error
return nil
}
func resolveBaseEndpoint(ctx context.Context, cfg *aws.Config, configs configs) error {
var downcastCfgSources []interface{}
for _, cs := range configs {
downcastCfgSources = append(downcastCfgSources, interface{}(cs))
}
if val, found, err := GetIgnoreConfiguredEndpoints(ctx, downcastCfgSources); found && val && err == nil {
cfg.BaseEndpoint = nil
return nil
}
v, found, err := getBaseEndpoint(ctx, configs)
if err != nil {
return err
}
if !found {
return nil
}
cfg.BaseEndpoint = aws.String(v)
return nil
}
// resolveAppID extracts the sdk app ID from the configs slice's SharedConfig or env var
func resolveAppID(ctx context.Context, cfg *aws.Config, configs configs) error {
ID, _, err := getAppID(ctx, configs)
if err != nil {
return err
}
cfg.AppID = ID
return nil
}
// resolveDisableRequestCompression extracts the DisableRequestCompression from the configs slice's
// SharedConfig or EnvConfig
func resolveDisableRequestCompression(ctx context.Context, cfg *aws.Config, configs configs) error {
disable, _, err := getDisableRequestCompression(ctx, configs)
if err != nil {
return err
}
cfg.DisableRequestCompression = disable
return nil
}
// resolveRequestMinCompressSizeBytes extracts the RequestMinCompressSizeBytes from the configs slice's
// SharedConfig or EnvConfig
func resolveRequestMinCompressSizeBytes(ctx context.Context, cfg *aws.Config, configs configs) error {
minBytes, found, err := getRequestMinCompressSizeBytes(ctx, configs)
if err != nil {
return err
}
// must set a default min size 10240 if not configured
if !found {
minBytes = 10240
}
cfg.RequestMinCompressSizeBytes = minBytes
return nil
}
// resolveDefaultRegion extracts the first instance of a default region and sets `aws.Config.Region` to the default
// region if region had not been resolved from other sources.
func resolveDefaultRegion(ctx context.Context, cfg *aws.Config, configs configs) error {

View File

@ -3,7 +3,10 @@ package config
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
@ -21,11 +24,33 @@ import (
const (
// valid credential source values
credSourceEc2Metadata = "Ec2InstanceMetadata"
credSourceEnvironment = "Environment"
credSourceECSContainer = "EcsContainer"
credSourceEc2Metadata = "Ec2InstanceMetadata"
credSourceEnvironment = "Environment"
credSourceECSContainer = "EcsContainer"
httpProviderAuthFileEnvVar = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE"
)
// direct representation of the IPv4 address for the ECS container
// "169.254.170.2"
var ecsContainerIPv4 net.IP = []byte{
169, 254, 170, 2,
}
// direct representation of the IPv4 address for the EKS container
// "169.254.170.23"
var eksContainerIPv4 net.IP = []byte{
169, 254, 170, 23,
}
// direct representation of the IPv6 address for the EKS container
// "fd00:ec2::23"
var eksContainerIPv6 net.IP = []byte{
0xFD, 0, 0xE, 0xC2,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0x23,
}
var (
ecsContainerEndpoint = "http://169.254.170.2" // not constant to allow for swapping during unit-testing
)
@ -222,6 +247,36 @@ func processCredentials(ctx context.Context, cfg *aws.Config, sharedConfig *Shar
return nil
}
// isAllowedHost allows host to be loopback or known ECS/EKS container IPs
//
// host can either be an IP address OR an unresolved hostname - resolution will
// be automatically performed in the latter case
func isAllowedHost(host string) (bool, error) {
if ip := net.ParseIP(host); ip != nil {
return isIPAllowed(ip), nil
}
addrs, err := lookupHostFn(host)
if err != nil {
return false, err
}
for _, addr := range addrs {
if ip := net.ParseIP(addr); ip == nil || !isIPAllowed(ip) {
return false, nil
}
}
return true, nil
}
func isIPAllowed(ip net.IP) bool {
return ip.IsLoopback() ||
ip.Equal(ecsContainerIPv4) ||
ip.Equal(eksContainerIPv4) ||
ip.Equal(eksContainerIPv6)
}
func resolveLocalHTTPCredProvider(ctx context.Context, cfg *aws.Config, endpointURL, authToken string, configs configs) error {
var resolveErr error
@ -232,10 +287,12 @@ func resolveLocalHTTPCredProvider(ctx context.Context, cfg *aws.Config, endpoint
host := parsed.Hostname()
if len(host) == 0 {
resolveErr = fmt.Errorf("unable to parse host from local HTTP cred provider URL")
} else if isLoopback, loopbackErr := isLoopbackHost(host); loopbackErr != nil {
resolveErr = fmt.Errorf("failed to resolve host %q, %v", host, loopbackErr)
} else if !isLoopback {
resolveErr = fmt.Errorf("invalid endpoint host, %q, only loopback hosts are allowed", host)
} else if parsed.Scheme == "http" {
if isAllowedHost, allowHostErr := isAllowedHost(host); allowHostErr != nil {
resolveErr = fmt.Errorf("failed to resolve host %q, %v", host, allowHostErr)
} else if !isAllowedHost {
resolveErr = fmt.Errorf("invalid endpoint host, %q, only loopback/ecs/eks hosts are allowed", host)
}
}
}
@ -252,6 +309,16 @@ func resolveHTTPCredProvider(ctx context.Context, cfg *aws.Config, url, authToke
if len(authToken) != 0 {
options.AuthorizationToken = authToken
}
if authFilePath := os.Getenv(httpProviderAuthFileEnvVar); authFilePath != "" {
options.AuthorizationTokenProvider = endpointcreds.TokenProviderFunc(func() (string, error) {
var contents []byte
var err error
if contents, err = ioutil.ReadFile(authFilePath); err != nil {
return "", fmt.Errorf("failed to read authorization token from %v: %v", authFilePath, err)
}
return string(contents), nil
})
}
options.APIOptions = cfg.APIOptions
if cfg.Retryer != nil {
options.Retryer = cfg.Retryer()
@ -384,10 +451,6 @@ func assumeWebIdentity(ctx context.Context, cfg *aws.Config, filepath string, ro
return fmt.Errorf("token file path is not set")
}
if len(roleARN) == 0 {
return fmt.Errorf("role ARN is not set")
}
optFns := []func(*stscreds.WebIdentityRoleOptions){
func(options *stscreds.WebIdentityRoleOptions) {
options.RoleSessionName = sessionName
@ -398,11 +461,29 @@ func assumeWebIdentity(ctx context.Context, cfg *aws.Config, filepath string, ro
if err != nil {
return err
}
if found {
optFns = append(optFns, optFn)
}
provider := stscreds.NewWebIdentityRoleProvider(sts.NewFromConfig(*cfg), roleARN, stscreds.IdentityTokenFile(filepath), optFns...)
opts := stscreds.WebIdentityRoleOptions{
RoleARN: roleARN,
}
for _, fn := range optFns {
fn(&opts)
}
if len(opts.RoleARN) == 0 {
return fmt.Errorf("role ARN is not set")
}
client := opts.Client
if client == nil {
client = sts.NewFromConfig(*cfg)
}
provider := stscreds.NewWebIdentityRoleProvider(client, roleARN, stscreds.IdentityTokenFile(filepath), optFns...)
cfg.Credentials = provider

View File

@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go-v2/internal/ini"
"github.com/aws/aws-sdk-go-v2/internal/shareddefaults"
"github.com/aws/smithy-go/logging"
smithyrequestcompression "github.com/aws/smithy-go/private/requestcompression"
)
const (
@ -28,6 +29,10 @@ const (
// the shared config file, not the credentials file.
ssoSectionPrefix = `sso-session `
// Prefix for services section. It is referenced in profile via the services
// parameter to configure clients for service-specific parameters.
servicesPrefix = `services `
// string equivalent for boolean
endpointDiscoveryDisabled = `false`
endpointDiscoveryEnabled = `true`
@ -75,6 +80,8 @@ const (
ec2MetadataServiceEndpointKey = "ec2_metadata_service_endpoint"
ec2MetadataV1DisabledKey = "ec2_metadata_v1_disabled"
// Use DualStack Endpoint Resolution
useDualStackEndpoint = "use_dualstack_endpoint"
@ -95,6 +102,19 @@ const (
retryModeKey = "retry_mode"
caBundleKey = "ca_bundle"
sdkAppID = "sdk_ua_app_id"
ignoreConfiguredEndpoints = "ignore_configured_endpoint_urls"
endpointURL = "endpoint_url"
servicesSectionKey = "services"
disableRequestCompression = "disable_request_compression"
requestMinCompressionSizeBytes = "request_min_compression_size_bytes"
s3DisableExpressSessionAuthKey = "s3_disable_express_session_auth"
)
// defaultSharedConfigProfile allows for swapping the default profile for testing
@ -148,6 +168,24 @@ func (s *SSOSession) setFromIniSection(section ini.Section) {
updateString(&s.SSOStartURL, section, ssoStartURLKey)
}
// Services contains values configured in the services section
// of the AWS configuration file.
type Services struct {
// Services section values
// {"serviceId": {"key": "value"}}
// e.g. {"s3": {"endpoint_url": "example.com"}}
ServiceValues map[string]map[string]string
}
func (s *Services) setFromIniSection(section ini.Section) {
if s.ServiceValues == nil {
s.ServiceValues = make(map[string]map[string]string)
}
for _, service := range section.List() {
s.ServiceValues[service] = section.Map(service)
}
}
// SharedConfig represents the configuration fields of the SDK config files.
type SharedConfig struct {
Profile string
@ -218,6 +256,12 @@ type SharedConfig struct {
// ec2_metadata_service_endpoint=http://fd00:ec2::254
EC2IMDSEndpoint string
// Specifies that IMDS clients should not fallback to IMDSv1 if token
// requests fail.
//
// ec2_metadata_v1_disabled=true
EC2IMDSv1Disabled *bool
// Specifies if the S3 service should disable support for Multi-Region
// access-points
//
@ -267,6 +311,36 @@ type SharedConfig struct {
//
// ca_bundle=$HOME/my_custom_ca_bundle
CustomCABundle string
// aws sdk app ID that can be added to user agent header string
AppID string
// Flag used to disable configured endpoints.
IgnoreConfiguredEndpoints *bool
// Value to contain configured endpoints to be propagated to
// corresponding endpoint resolution field.
BaseEndpoint string
// Services section config.
ServicesSectionName string
Services Services
// determine if request compression is allowed, default to false
// retrieved from config file's profile field disable_request_compression
DisableRequestCompression *bool
// inclusive threshold request body size to trigger compression,
// default to 10240 and must be within 0 and 10485760 bytes inclusive
// retrieved from config file's profile field request_min_compression_size_bytes
RequestMinCompressSizeBytes *int64
// Whether S3Express auth is disabled.
//
// This will NOT prevent requests from being made to S3Express buckets, it
// will only bypass the modified endpoint routing and signing behaviors
// associated with the feature.
S3DisableExpressAuth *bool
}
func (c SharedConfig) getDefaultsMode(ctx context.Context) (value aws.DefaultsMode, ok bool, err error) {
@ -356,6 +430,16 @@ func (c SharedConfig) GetEC2IMDSEndpoint() (string, bool, error) {
return c.EC2IMDSEndpoint, true, nil
}
// GetEC2IMDSV1FallbackDisabled implements an EC2IMDSV1FallbackDisabled option
// resolver interface.
func (c SharedConfig) GetEC2IMDSV1FallbackDisabled() (bool, bool) {
if c.EC2IMDSv1Disabled == nil {
return false, false
}
return *c.EC2IMDSv1Disabled, true
}
// GetUseDualStackEndpoint returns whether the service's dual-stack endpoint should be
// used for requests.
func (c SharedConfig) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error) {
@ -376,6 +460,16 @@ func (c SharedConfig) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEnd
return c.UseFIPSEndpoint, true, nil
}
// GetS3DisableExpressAuth returns the configured value for
// [SharedConfig.S3DisableExpressAuth].
func (c SharedConfig) GetS3DisableExpressAuth() (value, ok bool) {
if c.S3DisableExpressAuth == nil {
return false, false
}
return *c.S3DisableExpressAuth, true
}
// GetCustomCABundle returns the custom CA bundle's PEM bytes if the file was
func (c SharedConfig) getCustomCABundle(context.Context) (io.Reader, bool, error) {
if len(c.CustomCABundle) == 0 {
@ -389,6 +483,45 @@ func (c SharedConfig) getCustomCABundle(context.Context) (io.Reader, bool, error
return bytes.NewReader(b), true, nil
}
// getAppID returns the sdk app ID if set in shared config profile
func (c SharedConfig) getAppID(context.Context) (string, bool, error) {
return c.AppID, len(c.AppID) > 0, nil
}
// GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
// endpoints feature.
func (c SharedConfig) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error) {
if c.IgnoreConfiguredEndpoints == nil {
return false, false, nil
}
return *c.IgnoreConfiguredEndpoints, true, nil
}
func (c SharedConfig) getBaseEndpoint(context.Context) (string, bool, error) {
return c.BaseEndpoint, len(c.BaseEndpoint) > 0, nil
}
// GetServiceBaseEndpoint is used to retrieve a normalized SDK ID for use
// with configured endpoints.
func (c SharedConfig) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error) {
if service, ok := c.Services.ServiceValues[normalizeShared(sdkID)]; ok {
if endpt, ok := service[endpointURL]; ok {
return endpt, true, nil
}
}
return "", false, nil
}
func normalizeShared(sdkID string) string {
lower := strings.ToLower(sdkID)
return strings.ReplaceAll(lower, " ", "_")
}
func (c SharedConfig) getServicesObject(context.Context) (map[string]map[string]string, bool, error) {
return c.Services.ServiceValues, c.Services.ServiceValues != nil, nil
}
// loadSharedConfigIgnoreNotExist is an alias for loadSharedConfig with the
// addition of ignoring when none of the files exist or when the profile
// is not found in any of the files.
@ -538,6 +671,7 @@ func LoadSharedConfigProfile(ctx context.Context, profile string, optFns ...func
cfg := SharedConfig{}
profiles := map[string]struct{}{}
if err = cfg.setFromIniSections(profiles, profile, configSections, option.Logger); err != nil {
return SharedConfig{}, err
}
@ -566,6 +700,7 @@ func processConfigSections(ctx context.Context, sections *ini.Sections, logger l
skipSections[newName] = struct{}{}
case strings.HasPrefix(section, ssoSectionPrefix):
case strings.HasPrefix(section, servicesPrefix):
case strings.EqualFold(section, "default"):
default:
// drop this section, as invalid profile name
@ -725,11 +860,14 @@ func mergeSections(dst *ini.Sections, src ini.Sections) error {
s3DisableMultiRegionAccessPointsKey,
ec2MetadataServiceEndpointModeKey,
ec2MetadataServiceEndpointKey,
ec2MetadataV1DisabledKey,
useDualStackEndpoint,
useFIPSEndpointKey,
defaultsModeKey,
retryModeKey,
caBundleKey,
roleDurationSecondsKey,
retryMaxAttemptsKey,
ssoSessionNameKey,
ssoAccountIDKey,
@ -743,16 +881,6 @@ func mergeSections(dst *ini.Sections, src ini.Sections) error {
}
}
intKeys := []string{
roleDurationSecondsKey,
retryMaxAttemptsKey,
}
for i := range intKeys {
if err := mergeIntKey(&srcSection, &dstSection, sectionName, intKeys[i]); err != nil {
return err
}
}
// set srcSection on dst srcSection
*dst = dst.SetSection(sectionName, dstSection)
}
@ -779,26 +907,6 @@ func mergeStringKey(srcSection *ini.Section, dstSection *ini.Section, sectionNam
return nil
}
func mergeIntKey(srcSection *ini.Section, dstSection *ini.Section, sectionName, key string) error {
if srcSection.Has(key) {
srcValue := srcSection.Int(key)
v, err := ini.NewIntValue(srcValue)
if err != nil {
return fmt.Errorf("error merging %s, %w", key, err)
}
if dstSection.Has(key) {
dstSection.Logs = append(dstSection.Logs, newMergeKeyLogMessage(sectionName, key,
dstSection.SourceFile[key], srcSection.SourceFile[key]))
}
dstSection.UpdateValue(key, v)
dstSection.UpdateSourceFile(key, srcSection.SourceFile[key])
}
return nil
}
func newMergeKeyLogMessage(sectionName, key, dstSourceFile, srcSourceFile string) string {
return fmt.Sprintf("For profile: %v, overriding %v value, defined in %v "+
"with a %v value found in a duplicate profile defined at file %v. \n",
@ -902,6 +1010,14 @@ func (c *SharedConfig) setFromIniSections(profiles map[string]struct{}, profile
c.SSOSession = &ssoSession
}
if len(c.ServicesSectionName) > 0 {
if section, ok := sections.GetSection(servicesPrefix + c.ServicesSectionName); ok {
var svcs Services
svcs.setFromIniSection(section)
c.Services = svcs
}
}
return nil
}
@ -952,9 +1068,16 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
updateString(&c.SSOAccountID, section, ssoAccountIDKey)
updateString(&c.SSORoleName, section, ssoRoleNameKey)
// we're retaining a behavioral quirk with this field that existed before
// the removal of literal parsing for #2276:
// - if the key is missing, the config field will not be set
// - if the key is set to a non-numeric, the config field will be set to 0
if section.Has(roleDurationSecondsKey) {
d := time.Duration(section.Int(roleDurationSecondsKey)) * time.Second
c.RoleDurationSeconds = &d
if v, ok := section.Int(roleDurationSecondsKey); ok {
c.RoleDurationSeconds = aws.Duration(time.Duration(v) * time.Second)
} else {
c.RoleDurationSeconds = aws.Duration(time.Duration(0))
}
}
updateString(&c.CredentialProcess, section, credentialProcessKey)
@ -963,11 +1086,13 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
updateEndpointDiscoveryType(&c.EnableEndpointDiscovery, section, enableEndpointDiscoveryKey)
updateBoolPtr(&c.S3UseARNRegion, section, s3UseARNRegionKey)
updateBoolPtr(&c.S3DisableMultiRegionAccessPoints, section, s3DisableMultiRegionAccessPointsKey)
updateBoolPtr(&c.S3DisableExpressAuth, section, s3DisableExpressSessionAuthKey)
if err := updateEC2MetadataServiceEndpointMode(&c.EC2IMDSEndpointMode, section, ec2MetadataServiceEndpointModeKey); err != nil {
return fmt.Errorf("failed to load %s from shared config, %v", ec2MetadataServiceEndpointModeKey, err)
}
updateString(&c.EC2IMDSEndpoint, section, ec2MetadataServiceEndpointKey)
updateBoolPtr(&c.EC2IMDSv1Disabled, section, ec2MetadataV1DisabledKey)
updateUseDualStackEndpoint(&c.UseDualStackEndpoint, section, useDualStackEndpoint)
updateUseFIPSEndpoint(&c.UseFIPSEndpoint, section, useFIPSEndpointKey)
@ -985,6 +1110,20 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
updateString(&c.CustomCABundle, section, caBundleKey)
// user agent app ID added to request User-Agent header
updateString(&c.AppID, section, sdkAppID)
updateBoolPtr(&c.IgnoreConfiguredEndpoints, section, ignoreConfiguredEndpoints)
updateString(&c.BaseEndpoint, section, endpointURL)
if err := updateDisableRequestCompression(&c.DisableRequestCompression, section, disableRequestCompression); err != nil {
return fmt.Errorf("failed to load %s from shared config, %w", disableRequestCompression, err)
}
if err := updateRequestMinCompressSizeBytes(&c.RequestMinCompressSizeBytes, section, requestMinCompressionSizeBytes); err != nil {
return fmt.Errorf("failed to load %s from shared config, %w", requestMinCompressionSizeBytes, err)
}
// Shared Credentials
creds := aws.Credentials{
AccessKeyID: section.String(accessKeyIDKey),
@ -997,9 +1136,61 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
c.Credentials = creds
}
updateString(&c.ServicesSectionName, section, servicesSectionKey)
return nil
}
func updateRequestMinCompressSizeBytes(bytes **int64, sec ini.Section, key string) error {
if !sec.Has(key) {
return nil
}
v, ok := sec.Int(key)
if !ok {
return fmt.Errorf("invalid value for min request compression size bytes %s, need int64", sec.String(key))
}
if v < 0 || v > smithyrequestcompression.MaxRequestMinCompressSizeBytes {
return fmt.Errorf("invalid range for min request compression size bytes %d, must be within 0 and 10485760 inclusively", v)
}
*bytes = new(int64)
**bytes = v
return nil
}
func updateDisableRequestCompression(disable **bool, sec ini.Section, key string) error {
if !sec.Has(key) {
return nil
}
v := sec.String(key)
switch {
case v == "true":
*disable = new(bool)
**disable = true
case v == "false":
*disable = new(bool)
**disable = false
default:
return fmt.Errorf("invalid value for shared config profile field, %s=%s, need true or false", key, v)
}
return nil
}
func (c SharedConfig) getRequestMinCompressSizeBytes(ctx context.Context) (int64, bool, error) {
if c.RequestMinCompressSizeBytes == nil {
return 0, false, nil
}
return *c.RequestMinCompressSizeBytes, true, nil
}
func (c SharedConfig) getDisableRequestCompression(ctx context.Context) (bool, bool, error) {
if c.DisableRequestCompression == nil {
return false, false, nil
}
return *c.DisableRequestCompression, true, nil
}
func updateDefaultsMode(mode *aws.DefaultsMode, section ini.Section, key string) error {
if !section.Has(key) {
return nil
@ -1301,12 +1492,13 @@ func updateInt(dst *int, section ini.Section, key string) error {
if !section.Has(key) {
return nil
}
if vt, _ := section.ValueType(key); vt != ini.IntegerType {
return fmt.Errorf("invalid value %s=%s, expect integer",
key, section.String(key))
v, ok := section.Int(key)
if !ok {
return fmt.Errorf("invalid value %s=%s, expect integer", key, section.String(key))
}
*dst = int(section.Int(key))
*dst = int(v)
return nil
}
@ -1316,7 +1508,10 @@ func updateBool(dst *bool, section ini.Section, key string) {
if !section.Has(key) {
return
}
*dst = section.Bool(key)
// retains pre-#2276 behavior where non-bool value would resolve to false
v, _ := section.Bool(key)
*dst = v
}
// updateBoolPtr will only update the dst with the value in the section key,
@ -1325,8 +1520,11 @@ func updateBoolPtr(dst **bool, section ini.Section, key string) {
if !section.Has(key) {
return
}
// retains pre-#2276 behavior where non-bool value would resolve to false
v, _ := section.Bool(key)
*dst = new(bool)
**dst = section.Bool(key)
**dst = v
}
// updateEndpointDiscoveryType will only update the dst with the value in the section, if
@ -1358,7 +1556,8 @@ func updateUseDualStackEndpoint(dst *aws.DualStackEndpointState, section ini.Sec
return
}
if section.Bool(key) {
// retains pre-#2276 behavior where non-bool value would resolve to false
if v, _ := section.Bool(key); v {
*dst = aws.DualStackEndpointStateEnabled
} else {
*dst = aws.DualStackEndpointStateDisabled
@ -1374,7 +1573,8 @@ func updateUseFIPSEndpoint(dst *aws.FIPSEndpointState, section ini.Section, key
return
}
if section.Bool(key) {
// retains pre-#2276 behavior where non-bool value would resolve to false
if v, _ := section.Bool(key); v {
*dst = aws.FIPSEndpointStateEnabled
} else {
*dst = aws.FIPSEndpointStateDisabled