Optionally get access and secret keys from AWS CLI configuration
This commit is contained in:
@@ -19,10 +19,18 @@ deploy:
|
||||
bucket: <S3 bucket>
|
||||
aws_key: <AWS id key> // Optional, if the environment variable `AWS_ACCESS_KEY_ID` is set
|
||||
aws_secret: <AWS secret key> // Optional, if the environment variable `AWS_SECRET_ACCESS_KEY` is set
|
||||
aws_cli_profile: <an AWS CLI profile name, e.g. 'default'> // Optional
|
||||
concurrency: <number of connections> // Optional
|
||||
region: <region> // Optional, see https://github.com/LearnBoost/knox#region
|
||||
headers: <headers in JSON format> // pass any headers to S3, usefull for metadata cache setting of Hexo assets
|
||||
```
|
||||
|
||||
If you installed the AWS command-line tool and provided your credentials via `aws configure`,
|
||||
you can re-use those credentials. Specify a value for `aws_cli_profile`, such as "default",
|
||||
and leave `aws_key`, `aws_secret`, and `region` blank.
|
||||
If you provide key, secret, and/or region explicitly or via the environment,
|
||||
they will override what's in your AWS CLI profile.
|
||||
|
||||
#### Example: header Cache-Control
|
||||
|
||||
``` yaml
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^1.1.1",
|
||||
"ini": "^1.3.4",
|
||||
"s3": "^4.4.0",
|
||||
"xtend": "^4.0.1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user