gulp-awspublish
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -60,3 +60,5 @@ var AWS = require('aws-sdk'), | ||
params.ACL = headers[header]; | ||
} else if(header ==='Content-MD5') { | ||
params['ContentMD5'] = headers[header]; | ||
} else { | ||
@@ -175,6 +177,16 @@ | ||
function Publisher(config) { | ||
function Publisher(config, options) { | ||
this.config = config; | ||
this.client = new AWS.S3(config); | ||
var bucket = this.config.params.Bucket; | ||
if (!bucket) { | ||
throw new Error('Missing `params.Bucket` config value.'); | ||
} | ||
// init Cache file | ||
this._cacheFile = options && options.cacheFile | ||
? options.cacheFile | ||
: '.awspublish-' + bucket; | ||
// load cache | ||
@@ -195,9 +207,3 @@ try { | ||
Publisher.prototype.getCacheFilename = function() { | ||
var bucket = this.config.params['Bucket']; | ||
if (!bucket) { | ||
throw new Error('Missing `params.Bucket` config value.'); | ||
} | ||
return '.awspublish-' + bucket; | ||
return this._cacheFile; | ||
}; | ||
@@ -415,4 +421,4 @@ | ||
exports.create = function(options){ | ||
return new Publisher(options); | ||
exports.create = function(config, options){ | ||
return new Publisher(config, options); | ||
}; |
{ | ||
"name": "gulp-awspublish", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "gulp plugin to publish files to amazon s3", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=0.8.0", | ||
"node": ">=0.12.0", | ||
"npm": ">=1.2.10" | ||
@@ -53,0 +53,0 @@ }, |
103
README.md
@@ -24,5 +24,8 @@ # gulp-awspublish | ||
var publisher = awspublish.create({ | ||
region: 'your-region-id', | ||
params: { | ||
Bucket: '...' | ||
} | ||
}, { | ||
cacheFile: 'your-cache-location' | ||
}); | ||
@@ -62,14 +65,40 @@ | ||
* Note: In order for publish to work on S3, your policiy has to allow the following S3 actions: | ||
- "s3:PutObject", | ||
- "s3:GetObject", | ||
- "s3:DeleteObject", | ||
- "s3:ListMultipartUploadParts", | ||
- "s3:AbortMultipartUpload", | ||
- "s3:ListBucket" | ||
* Note: In order for publish to work on S3, your policy has to allow the following S3 actions: | ||
``` | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:ListBucket" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::BUCKETNAME" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:PutObject", | ||
"s3:PutObjectAcl", | ||
"s3:GetObject", | ||
"s3:GetObjectAcl", | ||
"s3:DeleteObject", | ||
"s3:ListMultipartUploadParts", | ||
"s3:AbortMultipartUpload" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::BUCKETNAME/*" | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
## Testing | ||
add an aws-credentials.json json file to the project directory | ||
with your bucket credentials, then run mocha. | ||
with your **testing bucket** credentials, then run mocha. | ||
@@ -79,3 +108,3 @@ ```json | ||
"params": { | ||
"Bucket": "..." | ||
"Bucket": "<test-bucket>" | ||
}, | ||
@@ -93,2 +122,4 @@ "accessKeyId": "...", | ||
* Note: Node version 0.12.x or later is required in order to use `awspublish.gzip`. If you need an older node engine to work with gzipping, you can use [v2.0.2](https://github.com/pgherveou/gulp-awspublish/tree/v2.0.2). | ||
Available options: | ||
@@ -98,12 +129,44 @@ - ext: file extension to add to gzipped file (eg: { ext: '.gz' }) | ||
### awspublish.create(options) | ||
### awspublish.create(config, options) | ||
Create a Publisher. | ||
Options are used to create an `aws-sdk` S3 client. At a minimum you must pass | ||
a `bucket` option, to define the site bucket. If you are using the [aws-sdk suggestions](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html) for credentials you do not need | ||
to provide anything else. | ||
The config object is used to create an `aws-sdk` S3 client. At a minimum you must pass a `Bucket` key, to define the site bucket. You can find all available options in the [AWS SDK documentation](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property). | ||
Also supports credentials specified in the old [knox](https://github.com/LearnBoost/knox#client-creation-options) | ||
format, a `profile` property for choosing a specific set of shared AWS creds, or and `accessKeyId` and `secretAccessKey` provided explicitly. | ||
The options object allows you to define the location of the cached hash digests. By default, they will be saved in your projects root folder in a hidden file called '.awspublish-' + 'name-of-your-bucket'. | ||
#### Credentials | ||
By default, gulp-awspublish uses the credential chain specified in the AWS [docs](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html). | ||
Here are some example credential configurations: | ||
Hardcoded credentials (**Note**: We recommend you **not** hard-code credentials inside an application. Use this method only for small personal scripts or for testing purposes.): | ||
``` | ||
var publisher = awspublish.create({ | ||
region: 'your-region-id', | ||
params: { | ||
Bucket: '...' | ||
}, | ||
accessKeyId: 'akid', | ||
secretAccessKey: 'secret' | ||
}); | ||
``` | ||
Using a profile by name from `~/.aws/credentials`: | ||
``` | ||
var AWS = require('aws-sdk'); | ||
var publisher = awspublish.create({ | ||
region: 'your-region-id', | ||
params: { | ||
Bucket: '...' | ||
}, | ||
credentials: new AWS.SharedIniFileCredentials({profile: 'myprofile'}) | ||
}); | ||
``` | ||
Instead of putting anything in the configuration object, you can also provide the following environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_PROFILE`. You can also define a `[default]` profile in `~/.aws/credentials` which the SDK will use transparently without needing to set anything. | ||
#### Publisher.publish([headers], [options]) | ||
@@ -183,3 +246,3 @@ | ||
### rename file & directory | ||
### [Rename file & directory](examples/rename.js) | ||
@@ -204,3 +267,3 @@ You can use `gulp-rename` to rename your files on s3 | ||
### upload file in parallel | ||
### [Upload file in parallel](examples/concurrent.js) | ||
@@ -218,3 +281,3 @@ You can use `concurrent-transform` to upload files in parallel to your amazon bucket | ||
### upload both gzipped and plain files in one stream | ||
### Upload both gzipped and plain files in one stream | ||
@@ -242,2 +305,6 @@ You can use the [`merge-stream`](https://github.com/grncdr/merge-stream) plugin | ||
### gulp-cloudfront-invalidate-aws-publish | ||
Invalidate cloudfront cache based on output from awspublish | ||
https://www.npmjs.com/package/gulp-cloudfront-invalidate-aws-publish | ||
## License | ||
@@ -244,0 +311,0 @@ |
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
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
38740
742
310