-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load configuration and credentials from ~/.aws/config or path specifi…
…ed in AWS_CONFIG_FILE if AWS_SDK_LOAD_CONFIG is set
- Loading branch information
Showing
9 changed files
with
232 additions
and
61 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.changes/next-release/feature-EnvironmentVariable-6754fae2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "feature", | ||
"category": "EnvironmentVariable", | ||
"description": "Load config from ~/.aws/config if AWS_SDK_LOAD_CONFIG is set" | ||
} |
5 changes: 5 additions & 0 deletions
5
.changes/next-release/feature-EnvironmentVariable-99ebc879.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "feature", | ||
"category": "EnvironmentVariable", | ||
"description": "Add support for specifying the location of the shared config file via the AWS_CONFIG_FILE environment variable. This variable is only honored if AWS_SDK_LOAD_CONFIG is set to a truthy value." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var AWS = require('./core'); | ||
var os = require('os'); | ||
var path = require('path'); | ||
|
||
/** | ||
* @api private | ||
*/ | ||
AWS.SharedIniFile = AWS.util.inherit({ | ||
constructor: function SharedIniFile(options) { | ||
options = options || {}; | ||
|
||
this.filename = options.filename; | ||
this.isConfig = options.isConfig === true; | ||
}, | ||
|
||
ensureFileLoaded: function loadFile() { | ||
if (!this.parsedContents) { | ||
this.parsedContents = AWS.util.ini.parse( | ||
AWS.util.readFileSync(this.filename || this.getDefaultFilepath()) | ||
); | ||
} | ||
}, | ||
|
||
getDefaultFilepath: function getDefaultFilepath() { | ||
return path.join( | ||
this.getHomeDir(), | ||
'.aws', | ||
this.isConfig ? 'config' : 'credentials' | ||
); | ||
}, | ||
|
||
getHomeDir: function getHomeDir() { | ||
if (typeof os.homedir === 'function') { | ||
return os.homedir(); | ||
} | ||
|
||
var env = process.env; | ||
var home = env.HOME || | ||
env.USERPROFILE || | ||
(env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null); | ||
|
||
if (home) { | ||
return home; | ||
} | ||
|
||
throw AWS.util.error( | ||
new Error('Cannot load credentials, HOME path not set') | ||
); | ||
}, | ||
|
||
getProfile: function loadProfile(profile) { | ||
this.ensureFileLoaded(); | ||
|
||
var profileIndex = profile !== AWS.util.defaultProfile && this.isConfig ? | ||
'profile ' + profile : profile; | ||
|
||
return this.parsedContents[profileIndex]; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.