Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/session: Add support for shared config (~/.aws/config) file #761

Merged
merged 3 commits into from
Aug 2, 2016

Conversation

jasdel
Copy link
Contributor

@jasdel jasdel commented Jul 18, 2016

Updates the SDK to take advantage of the new AWS_SDK_LOAD_CONFIG environment variable. When set to a truthy value, as defined in strconv.ParseBool, the SDK will load both shared config file (/.aws/config), and the shared credentials file (/.aws/credentials). The shared credentials file has precedence over the shared config.

Both config files share the same format. Both [name] and [profile name] are accepted as section names. The first, [name] will be looked for first before falling back to [profile name] per config file.

See the session package docs for more information.

Deprecates the session.New method since it cannot return an error when the session fails to load until a request is made. session.NewSession corrects this by returning an error when creating the session.

Fix #384

return cfg
}

func setEnvValue(dst *string, keys []string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a little confusing to me by the name. I was thinking this was exporting to some environment variable. Perhaps getEnvValue(key []string) string may make more sense or something along those lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point that makes a lot more sense. I'll update the naming.


// Require logical grouping of credentials
if len(cfg.Creds.AccessKeyID) == 0 || len(cfg.Creds.SecretAccessKey) == 0 {
cfg.Creds = credentials.Value{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the provider name here? Do we care about empty ProviderName's?

@xibz
Copy link
Contributor

xibz commented Jul 22, 2016

Looks good with the few comments I have.

@jasdel jasdel force-pushed the feature/SharedConfig branch 4 times, most recently from 6f8b31c to a8f9089 Compare July 26, 2016 20:35
return buildSession(envCfg, cfgs...)
}

func oldNewSession(cfgs ...*aws.Config) *Session {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming this to something more obvious like newSessionFallback or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I'll take a look at refactoring these methods to see if I can create a better naming scheme for them, that fits in.

@jasdel
Copy link
Contributor Author

jasdel commented Jul 27, 2016

Fixed loading environment variable for the shared config file, and updated New error handling to not panic, and be inline with how errors would of been reported when requests are made.

@@ -58,7 +58,7 @@ func setup() {

// Delete the bucket
func teardown() {
svc := s3.New(session.New())
svc := s3.New(session.NewFromSharedConfig())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update integ tests for correct way to create session.

Adds opt-in support for loading the SDK's configuration from the shared
config file (~/.aws/config) in addition to the current shared configuration
file (~/.aws/credentials). This option can be enabled with the env var
`AWS_SDK_LOAD_CONFIG` set to a truthy value, or creating a session with the
`session.NewFromSharedConfig()` helper instead of `session.New()`.

In addition to loading from the shared config file the SDK will also now
load region from the shared credentials file when the share config is
enabled. This changes also treats the syntax of both shared config and
credentials as the same.

See the session package for more information and examples.

Adds shared config support for aws#384
@jasdel jasdel force-pushed the feature/SharedConfig branch 2 times, most recently from 092e1ea to 86ca8d9 Compare July 29, 2016 17:54
@jasdel
Copy link
Contributor Author

jasdel commented Jul 29, 2016

examples will be updated in another PR

// Trim files from the list that don't exist.
for _, f := range files {
if err := cfg.setFromIniFile(profile, f); err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "SharedConfigProfileNotExist" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedConfigProfileNotExist probably should be a const, since used in multiple places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good was thinking about converting these to typed errors for simplicity anyways, so this would work out well.

@xibz
Copy link
Contributor

xibz commented Jul 29, 2016

@jasdel - Looks pretty good! I have added few comments.

Updates the SDK to take advantage of the new `AWS_SDK_LOAD_CONFIG`
environment variable. When set to a truthy value, as defined in
strconv.ParseBool, the SDK will load both shared config file
(~/.aws/config), and the shared credentials file (~/.aws/credentials).
The shared credentials file has precedence over the shared config.

Both config files share the same format. Both `[name]` and `[profile name]`
are accepted as section names. The first, `[name]` will be looked for
first before falling back to `[profile name]` per config file.

See the [session](http://docs.aws.amazon.com/sdk-for-go/api/aws/session/) package docs for more information.

Deprecates the `session.New` method since it cannot return an error
when the session fails to load until a request is made.
`session.NewSession` corrects this by returning an error when creating
the session.
@xibz
Copy link
Contributor

xibz commented Aug 2, 2016

LGTM, :shipit:

@jasdel jasdel merged commit beae13f into aws:master Aug 2, 2016
@jasdel jasdel deleted the feature/SharedConfig branch August 2, 2016 18:28
jasdel added a commit that referenced this pull request Aug 2, 2016
skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this pull request May 20, 2021
update dependencies and snowball test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants