Optionally get access and secret keys from AWS CLI configuration
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
var fs = require('fs');
|
||||
var ini = require('ini');
|
||||
var path = require('path');
|
||||
var s3 = require('s3');
|
||||
var chalk = require('chalk');
|
||||
var xtend = require('xtend');
|
||||
@@ -12,6 +15,18 @@ module.exports = function(args) {
|
||||
region: args.region
|
||||
}
|
||||
};
|
||||
if (!config.s3Options.accessKeyId && !config.s3Options.secretAccessKey && args.aws_cli_profile) {
|
||||
/* User configured their access and secret keys in ~/.aws/credentials, check there */
|
||||
var iniFile = path.join(process.env.HOME, '.aws');
|
||||
var iniCredentials = ini.parse(fs.readFileSync(path.join(iniFile, 'credentials'), 'utf-8'));
|
||||
config.s3Options.accessKeyId = (iniCredentials[args.aws_cli_profile] || {}).aws_access_key_id;
|
||||
config.s3Options.secretAccessKey = (iniCredentials[args.aws_cli_profile] || {}).aws_secret_access_key;
|
||||
if (!config.s3Options.region) {
|
||||
var iniConfig = ini.parse(fs.readFileSync(path.join(iniFile, 'config'), 'utf-8'));
|
||||
var profilePath = (args.aws_cli_profile === 'default') ? args.aws_cli_profile : "profile " + args.aws_cli_profile;
|
||||
config.s3Options.region = (iniConfig[profilePath] || {}).region;
|
||||
}
|
||||
}
|
||||
var client = s3.createClient(config);
|
||||
|
||||
var publicDir = this.config.public_dir;
|
||||
|
||||
Reference in New Issue
Block a user