Skip to content

Commit

Permalink
Add Server Side Encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Pollack committed Oct 5, 2016
1 parent 14178e9 commit b7f019b
Show file tree
Hide file tree
Showing 3 changed files with 37 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 @@ -97,14 +97,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 @@ -138,6 +139,11 @@ module.exports = CoreObject.extend({
CacheControl: cacheControl,
Expires: expires
};

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

if (isGzipped) {
params.ContentEncoding = 'gzip';
}
Expand Down

0 comments on commit b7f019b

Please sign in to comment.