-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
Exports the shared credentials and shared config filename helper functions to make it easier to get the filename of the credentials and config file. Corrects a bug in the shared credentials and config HOME path that would return an invalid filename on windows if the HOME environment variable was defined. Replaces #1293
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
### SDK Features | ||
|
||
### SDK Enhancements | ||
* `aws/defaults`: Exports shared credentials and config default filenames used by the SDK. [#1308](https://github.com/aws/aws-sdk-go/pull/1308) | ||
* Adds SharedCredentialsFilename and SharedConfigFilename functions to defaults package. | ||
|
||
### SDK Bugs | ||
* `aws/credentials`: Fixes shared credential provider's default filename on Windows. [#1308](https://github.com/aws/aws-sdk-go/pull/1308) | ||
* The shared credentials provider would attempt to use the wrong filename on Windows if the `HOME` environment variable was defined. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,18 @@ package credentials | |
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/go-ini/ini" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/internal/shareddefaults" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jasdel
Author
Contributor
|
||
) | ||
|
||
// SharedCredsProviderName provides a name of SharedCreds provider | ||
const SharedCredsProviderName = "SharedCredentialsProvider" | ||
|
||
var ( | ||
// ErrSharedCredentialsHomeNotFound is emitted when the user directory cannot be found. | ||
// | ||
// @readonly | ||
ErrSharedCredentialsHomeNotFound = awserr.New("UserHomeNotFound", "user home directory not found.", nil) | ||
) | ||
|
||
|
@@ -117,22 +115,23 @@ func loadProfile(filename, profile string) (Value, error) { | |
// | ||
// Will return an error if the user's home directory path cannot be found. | ||
func (p *SharedCredentialsProvider) filename() (string, error) { | ||
if p.Filename == "" { | ||
if p.Filename = os.Getenv("AWS_SHARED_CREDENTIALS_FILE"); p.Filename != "" { | ||
return p.Filename, nil | ||
} | ||
|
||
homeDir := os.Getenv("HOME") // *nix | ||
if homeDir == "" { // Windows | ||
homeDir = os.Getenv("USERPROFILE") | ||
} | ||
if homeDir == "" { | ||
return "", ErrSharedCredentialsHomeNotFound | ||
} | ||
|
||
p.Filename = filepath.Join(homeDir, ".aws", "credentials") | ||
if len(p.Filename) != 0 { | ||
return p.Filename, nil | ||
} | ||
|
||
if p.Filename = os.Getenv("AWS_SHARED_CREDENTIALS_FILE"); len(p.Filename) != 0 { | ||
return p.Filename, nil | ||
} | ||
|
||
if home := shareddefaults.UserHomeDir(); len(home) == 0 { | ||
// Backwards compatibility of home directly not found error being returned. | ||
// This error is too verbose, failure when opening the file would of been | ||
// a better error to return. | ||
return "", ErrSharedCredentialsHomeNotFound | ||
} | ||
|
||
p.Filename = shareddefaults.SharedConfigFilename() | ||
|
||
return p.Filename, nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package defaults | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/internal/shareddefaults" | ||
) | ||
|
||
// SharedCredentialsFilename returns the SDK's default file path | ||
// for the shared credentials file. | ||
// | ||
// Builds the shared config file path based on the OS's platform. | ||
// | ||
// - Linux/Unix: $HOME/.aws/credentials | ||
// - Windows: %USERPROFILE%\.aws\credentials | ||
func SharedCredentialsFilename() string { | ||
return shareddefaults.SharedCredentialsFilename() | ||
} | ||
|
||
// SharedConfigFilename returns the SDK's default file path for | ||
// the shared config file. | ||
// | ||
// Builds the shared config file path based on the OS's platform. | ||
// | ||
// - Linux/Unix: $HOME/.aws/config | ||
// - Windows: %USERPROFILE%\.aws\config | ||
func SharedConfigFilename() string { | ||
return shareddefaults.SharedConfigFilename() | ||
} |
After adding this internal dependency I started receiving the message bellow when importing (vendor) the
aws-sdk-go
into my project.