chore: upgrade dependencies

This commit is contained in:
2022-06-09 12:30:53 +02:00
parent 7203f3d6a1
commit dcb93ec8f7
518 changed files with 27809 additions and 3222 deletions

View File

@@ -1,17 +1,19 @@
package config
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/aws-sdk-go-v2/internal/ini"
"github.com/aws/smithy-go/logging"
)
@@ -76,6 +78,14 @@ const (
s3DisableMultiRegionAccessPointsKey = `s3_disable_multiregion_access_points`
useFIPSEndpointKey = "use_fips_endpoint"
defaultsModeKey = "defaults_mode"
// Retry options
retryMaxAttemptsKey = "max_attempts"
retryModeKey = "retry_mode"
caBundleKey = "ca_bundle"
)
// defaultSharedConfigProfile allows for swapping the default profile for testing
@@ -166,12 +176,14 @@ type SharedConfig struct {
// s3_use_arn_region=true
S3UseARNRegion *bool
// Specifies the EC2 Instance Metadata Service default endpoint selection mode (IPv4 or IPv6)
// Specifies the EC2 Instance Metadata Service default endpoint selection
// mode (IPv4 or IPv6)
//
// ec2_metadata_service_endpoint_mode=IPv6
EC2IMDSEndpointMode imds.EndpointModeState
// Specifies the EC2 Instance Metadata Service endpoint to use. If specified it overrides EC2IMDSEndpointMode.
// Specifies the EC2 Instance Metadata Service endpoint to use. If
// specified it overrides EC2IMDSEndpointMode.
//
// ec2_metadata_service_endpoint=http://fd00:ec2::254
EC2IMDSEndpoint string
@@ -193,6 +205,65 @@ type SharedConfig struct {
//
// use_fips_endpoint=true
UseFIPSEndpoint aws.FIPSEndpointState
// Specifies which defaults mode should be used by services.
//
// defaults_mode=standard
DefaultsMode aws.DefaultsMode
// Specifies the maximum number attempts an API client will call an
// operation that fails with a retryable error.
//
// max_attempts=3
RetryMaxAttempts int
// Specifies the retry model the API client will be created with.
//
// retry_mode=standard
RetryMode aws.RetryMode
// Sets the path to a custom Credentials Authority (CA) Bundle PEM file
// that the SDK will use instead of the system's root CA bundle. Only use
// this if you want to configure the SDK to use a custom set of CAs.
//
// Enabling this option will attempt to merge the Transport into the SDK's
// HTTP client. If the client's Transport is not a http.Transport an error
// will be returned. If the Transport's TLS config is set this option will
// cause the SDK to overwrite the Transport's TLS config's RootCAs value.
//
// Setting a custom HTTPClient in the aws.Config options will override this
// setting. To use this option and custom HTTP client, the HTTP client
// needs to be provided when creating the config. Not the service client.
//
// ca_bundle=$HOME/my_custom_ca_bundle
CustomCABundle string
}
func (c SharedConfig) getDefaultsMode(ctx context.Context) (value aws.DefaultsMode, ok bool, err error) {
if len(c.DefaultsMode) == 0 {
return "", false, nil
}
return c.DefaultsMode, true, nil
}
// GetRetryMaxAttempts returns the maximum number of attempts an API client
// created Retryer should attempt an operation call before failing.
func (c SharedConfig) GetRetryMaxAttempts(ctx context.Context) (value int, ok bool, err error) {
if c.RetryMaxAttempts == 0 {
return 0, false, nil
}
return c.RetryMaxAttempts, true, nil
}
// GetRetryMode returns the model the API client should create its Retryer in.
func (c SharedConfig) GetRetryMode(ctx context.Context) (value aws.RetryMode, ok bool, err error) {
if len(c.RetryMode) == 0 {
return "", false, nil
}
return c.RetryMode, true, nil
}
// GetS3UseARNRegion returns if the S3 service should allow ARNs to direct the region
@@ -275,6 +346,19 @@ func (c SharedConfig) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEnd
return c.UseFIPSEndpoint, true, nil
}
// 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 {
return nil, false, nil
}
b, err := ioutil.ReadFile(c.CustomCABundle)
if err != nil {
return nil, false, err
}
return bytes.NewReader(b), true, 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.
@@ -549,12 +633,8 @@ func mergeSections(dst, src ini.Sections) error {
secretKey := srcSection.String(secretAccessKey)
if dstSection.Has(accessKeyIDKey) {
dstSection.Logs = append(dstSection.Logs,
fmt.Sprintf("For profile: %v, overriding credentials value for aws access key id, "+
"and aws secret access key, defined in %v, with values found in a duplicate profile "+
"defined at file %v. \n",
sectionName, dstSection.SourceFile[accessKeyIDKey],
srcSection.SourceFile[accessKeyIDKey]))
dstSection.Logs = append(dstSection.Logs, newMergeKeyLogMessage(sectionName, accessKeyIDKey,
dstSection.SourceFile[accessKeyIDKey], srcSection.SourceFile[accessKeyIDKey]))
}
// update access key
@@ -572,24 +652,8 @@ func mergeSections(dst, src ini.Sections) error {
dstSection.UpdateValue(secretAccessKey, v)
// update session token
if srcSection.Has(sessionTokenKey) {
sessionKey := srcSection.String(sessionTokenKey)
val, e := ini.NewStringValue(sessionKey)
if e != nil {
return fmt.Errorf("error merging session key, %w", e)
}
if dstSection.Has(sessionTokenKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, sessionTokenKey, dstSection.SourceFile[sessionTokenKey],
sessionTokenKey, srcSection.SourceFile[sessionTokenKey]))
}
dstSection.UpdateValue(sessionTokenKey, val)
dstSection.UpdateSourceFile(sessionTokenKey, srcSection.SourceFile[sessionTokenKey])
if err = mergeStringKey(&srcSection, &dstSection, sectionName, sessionTokenKey); err != nil {
return err
}
// update source file to reflect where the static creds came from
@@ -597,244 +661,40 @@ func mergeSections(dst, src ini.Sections) error {
dstSection.UpdateSourceFile(secretAccessKey, srcSection.SourceFile[secretAccessKey])
}
if srcSection.Has(roleArnKey) {
key := srcSection.String(roleArnKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging roleArnKey, %w", err)
stringKeys := []string{
roleArnKey,
sourceProfileKey,
credentialSourceKey,
externalIDKey,
mfaSerialKey,
roleSessionNameKey,
regionKey,
enableEndpointDiscoveryKey,
credentialProcessKey,
webIdentityTokenFileKey,
s3UseARNRegionKey,
s3DisableMultiRegionAccessPointsKey,
ec2MetadataServiceEndpointModeKey,
ec2MetadataServiceEndpointKey,
useDualStackEndpoint,
useFIPSEndpointKey,
defaultsModeKey,
retryModeKey,
}
for i := range stringKeys {
if err := mergeStringKey(&srcSection, &dstSection, sectionName, stringKeys[i]); err != nil {
return err
}
if dstSection.Has(roleArnKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, roleArnKey, dstSection.SourceFile[roleArnKey],
roleArnKey, srcSection.SourceFile[roleArnKey]))
}
dstSection.UpdateValue(roleArnKey, val)
dstSection.UpdateSourceFile(roleArnKey, srcSection.SourceFile[roleArnKey])
}
if srcSection.Has(sourceProfileKey) {
key := srcSection.String(sourceProfileKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging sourceProfileKey, %w", err)
}
if dstSection.Has(sourceProfileKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, sourceProfileKey, dstSection.SourceFile[sourceProfileKey],
sourceProfileKey, srcSection.SourceFile[sourceProfileKey]))
}
dstSection.UpdateValue(sourceProfileKey, val)
dstSection.UpdateSourceFile(sourceProfileKey, srcSection.SourceFile[sourceProfileKey])
intKeys := []string{
roleDurationSecondsKey,
retryMaxAttemptsKey,
}
if srcSection.Has(credentialSourceKey) {
key := srcSection.String(credentialSourceKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging credentialSourceKey, %w", err)
for i := range intKeys {
if err := mergeIntKey(&srcSection, &dstSection, sectionName, intKeys[i]); err != nil {
return err
}
if dstSection.Has(credentialSourceKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, credentialSourceKey, dstSection.SourceFile[credentialSourceKey],
credentialSourceKey, srcSection.SourceFile[credentialSourceKey]))
}
dstSection.UpdateValue(credentialSourceKey, val)
dstSection.UpdateSourceFile(credentialSourceKey, srcSection.SourceFile[credentialSourceKey])
}
if srcSection.Has(externalIDKey) {
key := srcSection.String(externalIDKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging externalIDKey, %w", err)
}
if dstSection.Has(externalIDKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, externalIDKey, dstSection.SourceFile[externalIDKey],
externalIDKey, srcSection.SourceFile[externalIDKey]))
}
dstSection.UpdateValue(externalIDKey, val)
dstSection.UpdateSourceFile(externalIDKey, srcSection.SourceFile[externalIDKey])
}
if srcSection.Has(mfaSerialKey) {
key := srcSection.String(mfaSerialKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging mfaSerialKey, %w", err)
}
if dstSection.Has(mfaSerialKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, mfaSerialKey, dstSection.SourceFile[mfaSerialKey],
mfaSerialKey, srcSection.SourceFile[mfaSerialKey]))
}
dstSection.UpdateValue(mfaSerialKey, val)
dstSection.UpdateSourceFile(mfaSerialKey, srcSection.SourceFile[mfaSerialKey])
}
if srcSection.Has(roleSessionNameKey) {
key := srcSection.String(roleSessionNameKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging roleSessionNameKey, %w", err)
}
if dstSection.Has(roleSessionNameKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, roleSessionNameKey, dstSection.SourceFile[roleSessionNameKey],
roleSessionNameKey, srcSection.SourceFile[roleSessionNameKey]))
}
dstSection.UpdateValue(roleSessionNameKey, val)
dstSection.UpdateSourceFile(roleSessionNameKey, srcSection.SourceFile[roleSessionNameKey])
}
// role duration seconds key update
if srcSection.Has(roleDurationSecondsKey) {
roleDurationSeconds := srcSection.Int(roleDurationSecondsKey)
v, err := ini.NewIntValue(roleDurationSeconds)
if err != nil {
return fmt.Errorf("error merging role duration seconds key, %w", err)
}
dstSection.UpdateValue(roleDurationSecondsKey, v)
dstSection.UpdateSourceFile(roleDurationSecondsKey, srcSection.SourceFile[roleDurationSecondsKey])
}
if srcSection.Has(regionKey) {
key := srcSection.String(regionKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging regionKey, %w", err)
}
if dstSection.Has(regionKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, regionKey, dstSection.SourceFile[regionKey],
regionKey, srcSection.SourceFile[regionKey]))
}
dstSection.UpdateValue(regionKey, val)
dstSection.UpdateSourceFile(regionKey, srcSection.SourceFile[regionKey])
}
if srcSection.Has(enableEndpointDiscoveryKey) {
key := srcSection.String(enableEndpointDiscoveryKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging enableEndpointDiscoveryKey, %w", err)
}
if dstSection.Has(enableEndpointDiscoveryKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, enableEndpointDiscoveryKey, dstSection.SourceFile[enableEndpointDiscoveryKey],
enableEndpointDiscoveryKey, srcSection.SourceFile[enableEndpointDiscoveryKey]))
}
dstSection.UpdateValue(enableEndpointDiscoveryKey, val)
dstSection.UpdateSourceFile(enableEndpointDiscoveryKey, srcSection.SourceFile[enableEndpointDiscoveryKey])
}
if srcSection.Has(credentialProcessKey) {
key := srcSection.String(credentialProcessKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging credentialProcessKey, %w", err)
}
if dstSection.Has(credentialProcessKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, credentialProcessKey, dstSection.SourceFile[credentialProcessKey],
credentialProcessKey, srcSection.SourceFile[credentialProcessKey]))
}
dstSection.UpdateValue(credentialProcessKey, val)
dstSection.UpdateSourceFile(credentialProcessKey, srcSection.SourceFile[credentialProcessKey])
}
if srcSection.Has(webIdentityTokenFileKey) {
key := srcSection.String(webIdentityTokenFileKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging webIdentityTokenFileKey, %w", err)
}
if dstSection.Has(webIdentityTokenFileKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, webIdentityTokenFileKey, dstSection.SourceFile[webIdentityTokenFileKey],
webIdentityTokenFileKey, srcSection.SourceFile[webIdentityTokenFileKey]))
}
dstSection.UpdateValue(webIdentityTokenFileKey, val)
dstSection.UpdateSourceFile(webIdentityTokenFileKey, srcSection.SourceFile[webIdentityTokenFileKey])
}
if srcSection.Has(s3UseARNRegionKey) {
key := srcSection.String(s3UseARNRegionKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging s3UseARNRegionKey, %w", err)
}
if dstSection.Has(s3UseARNRegionKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, s3UseARNRegionKey, dstSection.SourceFile[s3UseARNRegionKey],
s3UseARNRegionKey, srcSection.SourceFile[s3UseARNRegionKey]))
}
dstSection.UpdateValue(s3UseARNRegionKey, val)
dstSection.UpdateSourceFile(s3UseARNRegionKey, srcSection.SourceFile[s3UseARNRegionKey])
}
if srcSection.Has(s3DisableMultiRegionAccessPointsKey) {
key := srcSection.String(s3DisableMultiRegionAccessPointsKey)
val, err := ini.NewStringValue(key)
if err != nil {
return fmt.Errorf("error merging s3DisableMultiRegionAccessPointsKey, %w", err)
}
if dstSection.Has(s3DisableMultiRegionAccessPointsKey) {
dstSection.Logs = append(dstSection.Logs,
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",
sectionName, s3DisableMultiRegionAccessPointsKey, dstSection.SourceFile[s3DisableMultiRegionAccessPointsKey],
s3DisableMultiRegionAccessPointsKey, srcSection.SourceFile[s3DisableMultiRegionAccessPointsKey]))
}
dstSection.UpdateValue(s3DisableMultiRegionAccessPointsKey, val)
dstSection.UpdateSourceFile(s3DisableMultiRegionAccessPointsKey, srcSection.SourceFile[s3DisableMultiRegionAccessPointsKey])
}
// set srcSection on dst srcSection
@@ -844,6 +704,51 @@ func mergeSections(dst, src ini.Sections) error {
return nil
}
func mergeStringKey(srcSection *ini.Section, dstSection *ini.Section, sectionName, key string) error {
if srcSection.Has(key) {
srcValue := srcSection.String(key)
val, err := ini.NewStringValue(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, val)
dstSection.UpdateSourceFile(key, srcSection.SourceFile[key])
}
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",
sectionName, key, dstSourceFile, key, srcSourceFile)
}
// Returns an error if all of the files fail to load. If at least one file is
// successfully loaded and contains the profile, no error will be returned.
func (c *SharedConfig) setFromIniSections(profiles map[string]struct{}, profile string,
@@ -991,6 +896,19 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
updateUseDualStackEndpoint(&c.UseDualStackEndpoint, section, useDualStackEndpoint)
updateUseFIPSEndpoint(&c.UseFIPSEndpoint, section, useFIPSEndpointKey)
if err := updateDefaultsMode(&c.DefaultsMode, section, defaultsModeKey); err != nil {
return fmt.Errorf("failed to load %s from shared config, %w", defaultsModeKey, err)
}
if err := updateInt(&c.RetryMaxAttempts, section, retryMaxAttemptsKey); err != nil {
return fmt.Errorf("failed to load %s from shared config, %w", retryMaxAttemptsKey, err)
}
if err := updateRetryMode(&c.RetryMode, section, retryModeKey); err != nil {
return fmt.Errorf("failed to load %s from shared config, %w", retryModeKey, err)
}
updateString(&c.CustomCABundle, section, caBundleKey)
// Shared Credentials
creds := aws.Credentials{
AccessKeyID: section.String(accessKeyIDKey),
@@ -1006,6 +924,28 @@ func (c *SharedConfig) setFromIniSection(profile string, section ini.Section) er
return nil
}
func updateDefaultsMode(mode *aws.DefaultsMode, section ini.Section, key string) error {
if !section.Has(key) {
return nil
}
value := section.String(key)
if ok := mode.SetFromString(value); !ok {
return fmt.Errorf("invalid value: %s", value)
}
return nil
}
func updateRetryMode(mode *aws.RetryMode, section ini.Section, key string) (err error) {
if !section.Has(key) {
return nil
}
value := section.String(key)
if *mode, err = aws.ParseRetryMode(value); err != nil {
return err
}
return nil
}
func updateEC2MetadataServiceEndpointMode(endpointMode *imds.EndpointModeState, section ini.Section, key string) error {
if !section.Has(key) {
return nil
@@ -1204,12 +1144,9 @@ func (e CredentialRequiresARNError) Error() string {
}
func userHomeDir() string {
if runtime.GOOS == "windows" { // Windows
return os.Getenv("USERPROFILE")
}
// *nix
return os.Getenv("HOME")
// Ignore errors since we only care about Windows and *nix.
homedir, _ := os.UserHomeDir()
return homedir
}
func oneOrNone(bs ...bool) bool {
@@ -1236,6 +1173,24 @@ func updateString(dst *string, section ini.Section, key string) {
*dst = section.String(key)
}
// updateInt will only update the dst with the value in the section key, key
// is present in the section.
//
// Down casts the INI integer value from a int64 to an int, which could be
// different bit size depending on platform.
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))
}
*dst = int(section.Int(key))
return nil
}
// updateBool will only update the dst with the value in the section key, key
// is present in the section.
func updateBool(dst *bool, section ini.Section, key string) {