Allow the user of Environment Variables

Instead of storing sensitive information in your hexo config, you can instead set environment variables for your S3 configuration.

Requires that the environment variables `AWS_KEY` and `AWS_SECRET` be set.
This commit is contained in:
Nicholas Terwoord
2014-09-01 18:55:30 -04:00
parent 74e7a6e5c1
commit f6cb56397a
2 changed files with 7 additions and 5 deletions

View File

@@ -27,8 +27,8 @@ Add `bucket`, `aws_key` and `aws_secret` to `deploy` in `_config.yml`.
deploy: deploy:
type: s3 type: s3
bucket: <S3 bucket> bucket: <S3 bucket>
aws_key: <AWS id key> aws_key: <AWS id key> //Optional, if the environment variable `AWS_KEY` is set
aws_secret: <AWS secret key> aws_secret: <AWS secret key> //Optional, if the environment variable `AWS_SECRET` is set
concurrency: <number of connections> //Optional concurrency: <number of connections> //Optional
region: <region> //Optional, see https://github.com/LearnBoost/knox#region region: <region> //Optional, see https://github.com/LearnBoost/knox#region
``` ```

View File

@@ -10,6 +10,9 @@ var public_dir = hexo.config.public_dir || './public';
hexo.extend.deployer.register('s3', function (args, callback) { hexo.extend.deployer.register('s3', function (args, callback) {
var config = hexo.config.deploy; var config = hexo.config.deploy;
config.aws_key = config.aws_key || process.env.AWS_KEY;
config.aws_secret = config.aws_secret || process.env.AWS_SECRET;
if (!config.bucket || !config.aws_key || !config.aws_secret){ if (!config.bucket || !config.aws_key || !config.aws_secret){
var help = [ var help = [
'You should configure deployment settings in _config.yml first!', 'You should configure deployment settings in _config.yml first!',
@@ -18,8 +21,8 @@ hexo.extend.deployer.register('s3', function (args, callback) {
' deploy:', ' deploy:',
' type: s3', ' type: s3',
' bucket: <bucket>', ' bucket: <bucket>',
' aws_key: <aws_key>', ' [aws_key]: <aws_key> # Optional, if provided as environment variable',
' aws_secret: <aws_secret>', ' [aws_secret]: <aws_secret> # Optional, if provided as environment variable',
' [concurrency]: <concurrency>', ' [concurrency]: <concurrency>',
' [region]: <region> # See https://github.com/LearnBoost/knox#region', ' [region]: <region> # See https://github.com/LearnBoost/knox#region',
'', '',
@@ -30,7 +33,6 @@ hexo.extend.deployer.register('s3', function (args, callback) {
return callback(); return callback();
} }
var files = readdirp({ var files = readdirp({
root: public_dir, root: public_dir,
entryType: 'both' entryType: 'both'