Skip to content

Commit

Permalink
set config or creds file defaults only if unset
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Dec 22, 2020
1 parent ac08327 commit 910a750
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 9 additions & 7 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
)
}
Expand Down
10 changes: 10 additions & 0 deletions config/shared_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion config/testdata/load_config
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ region = us-west-2
[profile ]
region = ap-east-2

[profile\t]
[profile ]
region = ap-south-1

[profile-bar]
Expand Down

0 comments on commit 910a750

Please sign in to comment.