Skip to content

Commit

Permalink
Allow the AWS backend to get credentials from its environment.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
  • Loading branch information
tomwilkie committed Jul 25, 2018
1 parent 0967b51 commit 99769cf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ import (
// endpoint) or fully valid endpoint with dummy region assumed (e.g
// for URLs to emulated services).
func ConfigFromURL(awsURL *url.URL) (*aws.Config, error) {
if awsURL.User == nil {
return nil, fmt.Errorf("must specify escaped Access Key & Secret Access in URL")
}

password, _ := awsURL.User.Password()
creds := credentials.NewStaticCredentials(awsURL.User.Username(), password, "")
config := aws.NewConfig().
WithCredentials(creds).
// Use a custom http.Client with the golang defaults but also specifying
// MaxIdleConnsPerHost because of a bug in golang https://github.com/golang/go/issues/13801
// where MaxIdleConnsPerHost does not work as expected.
Expand All @@ -44,6 +37,13 @@ func ConfigFromURL(awsURL *url.URL) (*aws.Config, error) {
ExpectContinueTimeout: 1 * time.Second,
},
})

if awsURL.User != nil {
password, _ := awsURL.User.Password()
creds := credentials.NewStaticCredentials(awsURL.User.Username(), password, "")
config = config.WithCredentials(creds)
}

if strings.Contains(awsURL.Host, ".") {
return config.WithEndpoint(fmt.Sprintf("http://%s", awsURL.Host)).WithRegion("dummy"), nil
}
Expand Down

0 comments on commit 99769cf

Please sign in to comment.