mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
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:
160
vendor/github.com/aws/aws-sdk-go-v2/config/env_config.go
generated
vendored
160
vendor/github.com/aws/aws-sdk-go-v2/config/env_config.go
generated
vendored
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user