Skip to content

Commit

Permalink
merge prs and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Feb 20, 2019
1 parent 37186e1 commit afb58c7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 147 deletions.
114 changes: 0 additions & 114 deletions cloudfront.js

This file was deleted.

16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-aws",
"description": "A Grunt interface into the Amazon Node.JS SDK",
"version": "0.6.2",
"version": "0.7.0",
"homepage": "https://github.com/jpillora/grunt-aws",
"author": {
"name": "Jaime Pillora",
Expand Down Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"async": "~0.2.9",
"aws-sdk": "^2.1.50",
"lodash": "~1.3.1",
"mime": "~1.2.11"
"lodash": "^4.17.11",
"mime": "^2.4.0"
}
}
48 changes: 26 additions & 22 deletions tasks/services/cloudfront.js
@@ -1,9 +1,8 @@
var AWS = require("aws-sdk"),
_ = require("lodash"),
async = require("async");
_ = require("lodash"),
async = require("async");

module.exports = function(grunt) {

//cloudfront description
var DESC = "grunt-aws's cloudfront";

Expand All @@ -12,36 +11,37 @@ module.exports = function(grunt) {

//cloudfront task
grunt.registerMultiTask("cloudfront", DESC, function() {

//get options
var opts = this.options(DEFAULTS);

if(_.isEmpty(opts.distributionId))
if (_.isEmpty(opts.distributionId))
return grunt.log.ok("No DistributionId specified");

//mark as async
var done = this.async();

//whitelist allowed keys
AWS.config.update(_.pick(opts,
'accessKeyId',
'secretAccessKey'
), true);
AWS.config.update(_.pick(opts, "accessKeyId", "secretAccessKey"), true);

//whitelist allowed keys
AWS.config.update(
_.pick(opts, "accessKeyId", "secretAccessKey", "sessionToken"),
true
);

//cloudfront client
var cloudfront = new AWS.CloudFront();

var subtasks = [];
subtasks.push(createUpdates);
subtasks.push(createInvalidations);
subtasks.push(createUpdates);
async.series(subtasks, done);

//------------------------------------------------

//create records defined in opts.invalidations
function createInvalidations(callback) {
if(!opts.invalidations || !opts.invalidations.length)
return callback();
if (!opts.invalidations || !opts.invalidations.length) return callback();

var params = {
DistributionId: opts.distributionId,
Expand All @@ -61,10 +61,17 @@ module.exports = function(grunt) {
}

function createUpdates(callback) {
if(!opts.customErrorResponses && !opts.originPath && !opts.defaultRootObject)
if (
!opts.customErrorResponses &&
!opts.originPath &&
!opts.defaultRootObject
)
return callback();

cloudfront.getDistribution({ Id: opts.distributionId }, function(err, res) {
cloudfront.getDistribution({ Id: opts.distributionId }, function(
err,
res
) {
if (err) {
console.log(err, err.stack);
return callback(err);
Expand All @@ -76,18 +83,19 @@ module.exports = function(grunt) {
IfMatch: res.ETag
};

if(opts.customErrorResponses){
if (opts.customErrorResponses) {
params.DistributionConfig.CustomErrorResponses = {
Quantity: opts.customErrorResponses.length,
Items: opts.customErrorResponses
};
}

if(opts.originPath){
params.DistributionConfig.Origins.Items[ 0 ].OriginPath = opts.originPath;
if (opts.originPath) {
params.DistributionConfig.Origins.Items[0].OriginPath =
opts.originPath;
}

if(opts.defaultRootObject){
if (opts.defaultRootObject) {
params.DistributionConfig.DefaultRootObject = opts.defaultRootObject;
}

Expand All @@ -97,10 +105,6 @@ module.exports = function(grunt) {
callback(err);
});
});

}

});


};

0 comments on commit afb58c7

Please sign in to comment.