Merge pull request #1813 from svanharmelen/b-aws-creds-fix

Fixing PR #1804
This commit is contained in:
Mitchell Hashimoto 2015-05-05 13:05:35 -07:00
commit a07f07bbf2
1 changed files with 14 additions and 3 deletions

View File

@ -26,19 +26,30 @@ func s3Factory(conf map[string]string) (Client, error) {
if !ok { if !ok {
regionName = os.Getenv("AWS_DEFAULT_REGION") regionName = os.Getenv("AWS_DEFAULT_REGION")
if regionName == "" { if regionName == "" {
return nil, fmt.Errorf("missing 'region' configuration or AWS_DEFAULT_REGION environment variable") return nil, fmt.Errorf(
"missing 'region' configuration or AWS_DEFAULT_REGION environment variable")
} }
} }
accessKeyId := conf["access_key"] accessKeyId := conf["access_key"]
secretAccessKey := conf["secret_key"] secretAccessKey := conf["secret_key"]
credentialsProvider := credentials.NewStaticCredentials(accessKeyId, secretAccessKey, "") credentialsProvider := credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{Value: credentials.Value{
AccessKeyID: accessKeyId,
SecretAccessKey: secretAccessKey,
SessionToken: "",
}},
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{Filename: "", Profile: ""},
&credentials.EC2RoleProvider{},
})
// Make sure we got some sort of working credentials. // Make sure we got some sort of working credentials.
_, err := credentialsProvider.Get() _, err := credentialsProvider.Get()
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to determine AWS credentials. Set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.\n(error was: %s)", err) return nil, fmt.Errorf("Unable to determine AWS credentials. Set the AWS_ACCESS_KEY_ID and "+
"AWS_SECRET_ACCESS_KEY environment variables.\n(error was: %s)", err)
} }
awsConfig := &aws.Config{ awsConfig := &aws.Config{