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:
280
vendor/github.com/aws/aws-sdk-go-v2/config/shared_config.go
generated
vendored
280
vendor/github.com/aws/aws-sdk-go-v2/config/shared_config.go
generated
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user