gulp-s3-upload
Advanced tools
Comparing version 1.0.4 to 1.0.5
# Changelog | ||
## Version 1.0.5 | ||
* Added SDK config discovery + https_proxy support from [pull request #12](https://github.com/clineamb/gulp-s3-upload/pull/12). | ||
* Removed requirement to have AWS Key/Secret (due to settings be in IAM), as per [pull request #13](https://github.com/clineamb/gulp-s3-upload/pull/13). | ||
## Version 1.0.4 | ||
@@ -4,0 +8,0 @@ * Forgot to add a Readme entry for `charset` option. |
35
index.js
@@ -112,3 +112,3 @@ var through = require('through2') | ||
if(getErr && getErr.statusCode !== 404) { | ||
return callback(new gutil.PluginError(PLUGIN_NAME, "S3 Error: " + getErr.message)); | ||
return callback(new gutil.PluginError(PLUGIN_NAME, "S3 headObject Error: " + getErr.stack)); | ||
} | ||
@@ -128,3 +128,3 @@ | ||
if(err) { | ||
return callback(new gutil.PluginError(PLUGIN_NAME, "S3 Error: " + err.message)); | ||
return callback(new gutil.PluginError(PLUGIN_NAME, "S3 putObject Error: " + err.stack)); | ||
} | ||
@@ -160,13 +160,34 @@ | ||
aws_config.accessKeyId = config.accessKeyId || config.key; | ||
aws_config.secretAccessKey = config.secretAccessKey || config.secret; | ||
// Maintain backwards compatibility with legacy key and secret options | ||
if (config.key) { | ||
aws_config.accessKeyId = config.key; | ||
} | ||
if (config.secret) { | ||
aws_config.secretAccessKey = config.secret; | ||
} | ||
if(!aws_config.accessKeyId || !aws_config.secretAccessKey) { | ||
throw new PluginError(PLUGIN_NAME, "Missing AWS Key & Secret."); | ||
// Intentionally not mandating the accessKeyId and secretAccessKey as they | ||
// will be loaded automatically by the SDK from either environment variables | ||
// or the credentials file. | ||
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html | ||
// Configure the proxy if an environment variable is present. | ||
if (process.env.HTTPS_PROXY) { | ||
gutil.log("setting https proxy to %s", process.env.HTTPS_PROXY); | ||
if (!aws_config.httpOptions) | ||
aws_config.httpOptions = {}; | ||
var HttpsProxyAgent = require('https-proxy-agent'); | ||
aws_config.httpOptions.agent = new HttpsProxyAgent(process.env.HTTPS_PROXY); | ||
} | ||
// Update the global AWS config if we have any overrides | ||
if (Object.keys(aws_config).length) { | ||
AWS.config.update(aws_config); | ||
} | ||
AWS.config.update(aws_config); | ||
return gulpPrefixer(AWS); | ||
}; | ||
}; |
{ | ||
"name": "gulp-s3-upload", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A gulp task to upload/update assets to an S3 account.", | ||
@@ -28,2 +28,3 @@ "main": "index.js", | ||
"gulp-util": "^3.0.4", | ||
"https-proxy-agent": "^0.3.5", | ||
"mime": "1.3.4", | ||
@@ -30,0 +31,0 @@ "through2": "0.6.3", |
@@ -16,27 +16,40 @@ # gulp-s3-upload | ||
Put in your AWS Developer key/secret. These are required, or else the plugin doesn't have access to the bucket you want to upload to. | ||
### Including + Setting Up Config | ||
```js | ||
var gulp = require('gulp'); | ||
var s3 = require('gulp-s3-upload')({ | ||
accessKeyId: "YOUR DEV ID", | ||
secretAccessKey: "YOUR SECRET" | ||
}); | ||
var s3 = require('gulp-s3-upload')(config); | ||
``` | ||
The other options not mentioned above (like `region`) available in the [AWS Config Constructor](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property) are also available, though by default are `undefined`. | ||
Option names `key` and `secret` are also alternative option names, though the use of `accessKeyId` and `secretAccessKey` are encouraged to match the AWS Config Constructor. | ||
The optional `config` argument can include any option available (like `region`) available in the [AWS Config Constructor](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property). By default all settings are undefined. | ||
Per AWS best practices, the recommended approach for loading credentials is to use the shared credentials file (`~/.aws/credentials`). You can also set the `aws_access_key_id` and `aws_secret_access_key` environment variables or specify values directly in the gulpfile via the `accessKeyId` and `secretAccessKey` options. If you have multiple profiles configured in your AWS credentials file, you can specify the profile name inline with the call to gulp. | ||
```sh | ||
AWS_PROFILE=myprofile gulp | ||
``` | ||
You can also use a node_module like [config](https://www.npmjs.com/package/config) (+ [js-yaml](https://www.npmjs.com/package/js-yaml)) to load config files in your `gulpfile.js`. You can also use `fs.readFileSync` to read from a local file to load your config. | ||
Feel free to also include credentials straight into your `gulpfile.js`, though be careful about committing files with secret credentials in your projects! | ||
Having AWS Key/Secrets may not be required by your AWS/IAM settings. Errors thrown by the request should give your permission errors. | ||
### Gulp Task | ||
Create a task. | ||
```js | ||
gulp.task("upload", function() { | ||
gulp.src("./dir/to/upload/**") | ||
.pipe(s3({ | ||
Bucket: 'your-bucket-name', // Required | ||
ACL: 'public-read' // Needs to be user-defined | ||
})) | ||
; | ||
}); | ||
gulp.task("upload", function() { | ||
gulp.src("./dir/to/upload/**") | ||
.pipe(s3({ | ||
Bucket: 'your-bucket-name', // Required | ||
ACL: 'public-read' // Needs to be user-defined | ||
})) | ||
; | ||
}); | ||
``` | ||
## Options | ||
@@ -118,3 +131,3 @@ | ||
```js | ||
```js | ||
// ... setup gulp-s3-upload ... | ||
@@ -149,3 +162,3 @@ var path = require('path'); | ||
your S3 bucket, e.g. you can get "example.txt" or "docs/example.txt" | ||
depending on how it was structured locally (hence why in the example, | ||
depending on how it was structured locally (hence why in the example, | ||
the `path` module is used to just get the filename). | ||
@@ -189,2 +202,3 @@ | ||
* [AWS Config Constructor](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property) | ||
* [Configuring the AWS Node.js SDK](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html) | ||
* [S3 putObject](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property) | ||
@@ -191,0 +205,0 @@ * [Access Control List (ACL) Overview](http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19429
178
212
6
3
1
+ Addedhttps-proxy-agent@^0.3.5
+ Addedagent-base@1.0.2(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhttps-proxy-agent@0.3.6(transitive)
+ Addedms@2.0.0(transitive)