From c8a0b65307e4af3a17f9133fb574bb93a072ba39 Mon Sep 17 00:00:00 2001 From: Nick Sloan Date: Wed, 29 Apr 2015 00:32:42 -0400 Subject: [PATCH 1/2] Allow for specifying profiles. --- index.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 424fc2b..9e60ba6 100644 --- a/index.js +++ b/index.js @@ -8,19 +8,22 @@ var PLUGIN_NAME = 'gulp-aws'; function s3(bucket, options) { _.defaults(options, { - aws_cli_path: '/usr/local/bin/aws' + aws_cli_path: '/usr/local/bin/aws', + aws_region: undefined, + aws_key: undefined, + aws_secret: undefined }); - if (!options.aws_region) { - throw new PluginError(PLUGIN_NAME, '`options.aws_region` must be specified'); + if (!options.aws_region && !options.aws_profile) { + throw new PluginError(PLUGIN_NAME, '`options.aws_region` or `options.aws_profile` must be specified'); } - if (!options.aws_key) { - throw new PluginError(PLUGIN_NAME, '`options.aws_key` must be specified'); + if (!options.aws_key && !options.aws_profile) { + throw new PluginError(PLUGIN_NAME, '`options.aws_key` or `options.aws_profile` must be specified'); } - if (!options.aws_secret) { - throw new PluginError(PLUGIN_NAME, '`options.aws_secret` must be specified'); + if (!options.aws_secret && !options.aws_profile) { + throw new PluginError(PLUGIN_NAME, '`options.aws_secret` or `options.aws_profile` must be specified'); } return through.obj(function(file, enc, done) { @@ -37,11 +40,23 @@ function s3(bucket, options) { return done(); } - var env = { - AWS_DEFAULT_REGION: options.aws_region, - AWS_ACCESS_KEY_ID: options.aws_key, - AWS_SECRET_ACCESS_KEY: options.aws_secret, - }; + var env = {}; + + if (options.aws_key) { + evn.AWS_ACCESS_KEY_ID = options.aws_key; + } + + if (options.aws_secret) { + env.AWS_SECRET_ACCESS_KEY = options.aws_secret; + } + + if (options.aws_region) { + env.AWS_DEFAULT_REGION = options.aws_region; + } + + if (options.aws_profile) { + env.AWS_DEFAULT_PROFILE = options.aws_profile; + } var filepath; if (options.prefix_path) { @@ -50,13 +65,12 @@ function s3(bucket, options) { filepath = path.basename(file.path); } - var command = [ options.aws_cli_path, 's3', 'cp', file.path, - 's3://' + bucket + '/' + filepath + 's3://' + bucket + '/' + filepath, ]; require('child_process').exec(command.join(' '), { env: env }, function(error, stdout, stderr){ From 6c358e1889473444276b26f52d6045fa21aeecdd Mon Sep 17 00:00:00 2001 From: Nick Sloan Date: Wed, 29 Apr 2015 08:40:02 -0400 Subject: [PATCH 2/2] Fixes #5: Specify preserve_paths: true in options to keep path. --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9e60ba6..968aa22 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,8 @@ function s3(bucket, options) { aws_cli_path: '/usr/local/bin/aws', aws_region: undefined, aws_key: undefined, - aws_secret: undefined + aws_secret: undefined, + preseve_paths: false }); if (!options.aws_region && !options.aws_profile) { @@ -61,6 +62,8 @@ function s3(bucket, options) { var filepath; if (options.prefix_path) { filepath = path.join(options.prefix_path, path.basename(file.path)); + } else if (options.preserve_paths) { + filepath = file.relative; } else { filepath = path.basename(file.path); }