Skip to content

Commit

Permalink
Merge pull request #72 from sethpollack/sse
Browse files Browse the repository at this point in the history
Add Server Side Encryption
  • Loading branch information
lukemelia committed Nov 2, 2016
2 parents c9adf1e + 8490fd1 commit fb02da6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ The network proxy url used when sending requests to S3.

*Default:* `undefined`

### serverSideEncryption

The Server-side encryption algorithm used when storing this object in S3 (e.g., AES256, aws:kms). Possible values include:
- "AES256"
- "aws:kms"

## Prerequisites

The following properties are expected to be present on the deployment `context` object:
Expand Down
29 changes: 17 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ module.exports = {
requiredConfig: ['bucket', 'region'],

upload: function(context) {
var self = this;
var self = this;

var filePattern = this.readConfig('filePattern');
var distDir = this.readConfig('distDir');
var distFiles = this.readConfig('distFiles');
var gzippedFiles = this.readConfig('gzippedFiles');
var bucket = this.readConfig('bucket');
var acl = this.readConfig('acl');
var prefix = this.readConfig('prefix');
var manifestPath = this.readConfig('manifestPath');
var cacheControl = this.readConfig('cacheControl');
var expires = this.readConfig('expires');
var dotFolders = this.readConfig('dotFolders');
var filePattern = this.readConfig('filePattern');
var distDir = this.readConfig('distDir');
var distFiles = this.readConfig('distFiles');
var gzippedFiles = this.readConfig('gzippedFiles');
var bucket = this.readConfig('bucket');
var acl = this.readConfig('acl');
var prefix = this.readConfig('prefix');
var manifestPath = this.readConfig('manifestPath');
var cacheControl = this.readConfig('cacheControl');
var expires = this.readConfig('expires');
var dotFolders = this.readConfig('dotFolders');
var serverSideEncryption = this.readConfig('serverSideEncryption');

var filesToUpload = distFiles.filter(minimatch.filter(filePattern, { matchBase: true, dot: dotFolders }));

Expand All @@ -77,6 +78,10 @@ module.exports = {
expires: expires
};

if (serverSideEncryption) {
options.serverSideEncryption = serverSideEncryption;
}

this.log('preparing to upload to S3 bucket `' + bucket + '`', { verbose: true });

return s3.upload(options)
Expand Down
22 changes: 14 additions & 8 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ module.exports = CoreObject.extend({
},

_putObjects: function(filePaths, options) {
var plugin = this._plugin;
var cwd = options.cwd;
var bucket = options.bucket;
var prefix = options.prefix;
var acl = options.acl;
var gzippedFilePaths = options.gzippedFilePaths || [];
var cacheControl = options.cacheControl;
var expires = options.expires;
var plugin = this._plugin;
var cwd = options.cwd;
var bucket = options.bucket;
var prefix = options.prefix;
var acl = options.acl;
var gzippedFilePaths = options.gzippedFilePaths || [];
var cacheControl = options.cacheControl;
var expires = options.expires;
var serverSideEncryption = options.serverSideEncryption;

mime.default_type = options.defaultMimeType || mime.lookup('bin');

Expand Down Expand Up @@ -140,6 +141,11 @@ module.exports = CoreObject.extend({
CacheControl: cacheControl,
Expires: expires
};

if (serverSideEncryption) {
params.ServerSideEncryption = serverSideEncryption;
}

if (isGzipped) {
params.ContentEncoding = 'gzip';
}
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/lib/s3-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,36 @@ describe('s3', function() {
assert.equal(s3Params.CacheControl, 'max-age=1234, public');
assert.equal(s3Params.Expires, '2010');
assert.isUndefined(s3Params.ContentEncoding);
assert.isUndefined(s3Params.ServerSideEncryption);
});
});

it('sets ServerSideEncryption using serverSideEncryption', function() {
var s3Params;
s3Client.putObject = function(params, cb) {
s3Params = params;
cb();
};

var options = {
filePaths: ['app.css'],
cwd: process.cwd() + '/tests/fixtures/dist',
prefix: 'js-app',
acl: 'public-read',
bucket: 'some-bucket',
cacheControl: 'max-age=1234, public',
expires: '2010',
serverSideEncryption: 'AES256'
};

var promise = subject.upload(options);

return assert.isFulfilled(promise)
.then(function() {
assert.equal(s3Params.ServerSideEncryption, 'AES256', 'ServerSideEncryption passed correctly');
});
});

it('sends the correct content type params for gzipped files with .gz extension', function() {
var s3Params;
s3Client.putObject = function(params, cb) {
Expand Down

0 comments on commit fb02da6

Please sign in to comment.