-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
e40c8ae
to
f111f84
Compare
f111f84
to
c733c55
Compare
return cfg | ||
} | ||
|
||
func setEnvValue(dst *string, keys []string) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c733c55
to
0aec1ed
Compare
|
||
// Require logical grouping of credentials | ||
if len(cfg.Creds.AccessKeyID) == 0 || len(cfg.Creds.SecretAccessKey) == 0 { | ||
cfg.Creds = credentials.Value{} |
There was a problem hiding this comment.
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?
Looks good with the few comments I have. |
6f8b31c
to
a8f9089
Compare
return buildSession(envCfg, cfgs...) | ||
} | ||
|
||
func oldNewSession(cfgs ...*aws.Config) *Session { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
f082cb0
to
2c03fa3
Compare
@@ -58,7 +58,7 @@ func setup() { | |||
|
|||
// Delete the bucket | |||
func teardown() { | |||
svc := s3.New(session.New()) | |||
svc := s3.New(session.NewFromSharedConfig()) |
There was a problem hiding this comment.
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
092e1ea
to
86ca8d9
Compare
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" { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@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.
86ca8d9
to
f23263f
Compare
LGTM, |
update dependencies and snowball test
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