From a85437426a1117d92896e0e39f081f6fc05ba7b2 Mon Sep 17 00:00:00 2001 From: skotambkar Date: Tue, 22 Dec 2020 12:59:04 -0800 Subject: [PATCH] set config or creds file defaults only if unset --- config/shared_config.go | 16 +++++++++------- config/shared_config_test.go | 10 ++++++++++ config/testdata/load_config | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config/shared_config.go b/config/shared_config.go index fabebfb2cff..5b55570d677 100644 --- a/config/shared_config.go +++ b/config/shared_config.go @@ -259,9 +259,11 @@ type LoadSharedConfigOptions struct { // For example, given two files A and B. Both define credentials. If the order // of the files are A then B, B's credential values will be used instead of A's. // -// If no config files, credentials files are provided, the LoadSharedConfigProfile -// will default to location `.aws/config` for config files and `.aws/credentials` -// for credentials files respectively as per +// If config files are not set, SDK will default to using a file at location `.aws/config` if present. +// If credentials files are not set, SDK will default to using a file at location `.aws/credentials` if present. +// No default files are set, if files set to an empty slice. +// +// You can read more about shared config and credentials file location at // https://docs.aws.amazon.com/credref/latest/refdocs/file-location.html#file-location // func LoadSharedConfigProfile(ctx context.Context, profile string, optFns ...func(*LoadSharedConfigOptions)) (SharedConfig, error) { @@ -270,11 +272,11 @@ func LoadSharedConfigProfile(ctx context.Context, profile string, optFns ...func fn(&option) } - if len(option.ConfigFiles) == 0 { + if option.ConfigFiles == nil { option.ConfigFiles = DefaultSharedConfigFiles } - if len(option.CredentialsFiles) == 0 { + if option.CredentialsFiles == nil { option.CredentialsFiles = DefaultSharedCredentialsFiles } @@ -328,8 +330,8 @@ func processConfigSections(ctx context.Context, sections ini.Sections, logger lo if logger != nil { logger.Logf(logging.Debug, - "A profile defined with name `%v` is ignored. For use within a shared configuration file, " + - "a non-default profile must have `profile ` prefixed to the profile name.\n", + "A profile defined with name `%v` is ignored. For use within a shared configuration file, "+ + "a non-default profile must have `profile ` prefixed to the profile name.\n", section, ) } diff --git a/config/shared_config_test.go b/config/shared_config_test.go index c64c40dd3a8..b798e7d5723 100644 --- a/config/shared_config_test.go +++ b/config/shared_config_test.go @@ -910,6 +910,16 @@ func TestSharedConfigLoading(t *testing.T) { Err: "failed to get shared config profile, ignored-profile", ExpectLog: "profile defined with name `ignored-profile` is ignored.", }, + "config and creds files explicitly set to empty slice": { + LoadOptionFns: []func(*LoadOptions) error{ + WithSharedCredentialsFiles([]string{}), + WithSharedConfigFiles([]string{}), + WithLogConfigurationWarnings(true), + WithLogger(logger), + }, + LoadFn: loadSharedConfig, + Err: "failed to get shared config profile, default", + }, } for name, c := range cases { diff --git a/config/testdata/load_config b/config/testdata/load_config index 204a24b7099..f5b4391438f 100644 --- a/config/testdata/load_config +++ b/config/testdata/load_config @@ -33,7 +33,7 @@ region = us-west-2 [profile ] region = ap-east-2 -[profile\t] +[profile ] region = ap-south-1 [profile-bar]