diff --git a/awsauth.go b/awsauth.go index c11a0d1d..99aac164 100644 --- a/awsauth.go +++ b/awsauth.go @@ -20,6 +20,7 @@ import ( "github.com/aws/aws-sdk-go/service/sts" "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-multierror" + homedir "github.com/mitchellh/go-homedir" ) const ( @@ -303,6 +304,12 @@ func GetCredentialsFromMetadata(c *Config) (*awsCredentials.Credentials, error) // GetCredentials also validates the credentials and the ability to assume a role // or will return an error if unsuccessful. func GetCredentials(c *Config) (*awsCredentials.Credentials, error) { + sharedCredentialsFilename, err := homedir.Expand(c.CredsFilename) + + if err != nil { + return nil, fmt.Errorf("error expanding shared credentials filename: %w", err) + } + // build a chain provider, lazy-evaluated by aws-sdk providers := []awsCredentials.Provider{ &awsCredentials.StaticProvider{Value: awsCredentials.Value{ @@ -312,7 +319,7 @@ func GetCredentials(c *Config) (*awsCredentials.Credentials, error) { }}, &awsCredentials.EnvProvider{}, &awsCredentials.SharedCredentialsProvider{ - Filename: c.CredsFilename, + Filename: sharedCredentialsFilename, Profile: c.Profile, }, } diff --git a/go.mod b/go.mod index 1af445d2..fc166d86 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ require ( github.com/aws/aws-sdk-go v1.25.3 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/go-multierror v1.0.0 + github.com/mitchellh/go-homedir v1.1.0 github.com/stretchr/testify v1.3.0 // indirect golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect golang.org/x/text v0.3.0 // indirect diff --git a/go.sum b/go.sum index fb779dfa..e63d9c0d 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=