Skip to content

Commit fb02da6

Browse files
authored
Merge pull request #72 from sethpollack/sse
Add Server Side Encryption
2 parents c9adf1e + 8490fd1 commit fb02da6

File tree

4 files changed

+64
-20
lines changed

4 files changed

+64
-20
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ The network proxy url used when sending requests to S3.
195195

196196
*Default:* `undefined`
197197

198+
### serverSideEncryption
199+
200+
The Server-side encryption algorithm used when storing this object in S3 (e.g., AES256, aws:kms). Possible values include:
201+
- "AES256"
202+
- "aws:kms"
203+
198204
## Prerequisites
199205

200206
The following properties are expected to be present on the deployment `context` object:

index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ module.exports = {
4545
requiredConfig: ['bucket', 'region'],
4646

4747
upload: function(context) {
48-
var self = this;
48+
var self = this;
4949

50-
var filePattern = this.readConfig('filePattern');
51-
var distDir = this.readConfig('distDir');
52-
var distFiles = this.readConfig('distFiles');
53-
var gzippedFiles = this.readConfig('gzippedFiles');
54-
var bucket = this.readConfig('bucket');
55-
var acl = this.readConfig('acl');
56-
var prefix = this.readConfig('prefix');
57-
var manifestPath = this.readConfig('manifestPath');
58-
var cacheControl = this.readConfig('cacheControl');
59-
var expires = this.readConfig('expires');
60-
var dotFolders = this.readConfig('dotFolders');
50+
var filePattern = this.readConfig('filePattern');
51+
var distDir = this.readConfig('distDir');
52+
var distFiles = this.readConfig('distFiles');
53+
var gzippedFiles = this.readConfig('gzippedFiles');
54+
var bucket = this.readConfig('bucket');
55+
var acl = this.readConfig('acl');
56+
var prefix = this.readConfig('prefix');
57+
var manifestPath = this.readConfig('manifestPath');
58+
var cacheControl = this.readConfig('cacheControl');
59+
var expires = this.readConfig('expires');
60+
var dotFolders = this.readConfig('dotFolders');
61+
var serverSideEncryption = this.readConfig('serverSideEncryption');
6162

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

@@ -77,6 +78,10 @@ module.exports = {
7778
expires: expires
7879
};
7980

81+
if (serverSideEncryption) {
82+
options.serverSideEncryption = serverSideEncryption;
83+
}
84+
8085
this.log('preparing to upload to S3 bucket `' + bucket + '`', { verbose: true });
8186

8287
return s3.upload(options)

lib/s3.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ module.exports = CoreObject.extend({
9999
},
100100

101101
_putObjects: function(filePaths, options) {
102-
var plugin = this._plugin;
103-
var cwd = options.cwd;
104-
var bucket = options.bucket;
105-
var prefix = options.prefix;
106-
var acl = options.acl;
107-
var gzippedFilePaths = options.gzippedFilePaths || [];
108-
var cacheControl = options.cacheControl;
109-
var expires = options.expires;
102+
var plugin = this._plugin;
103+
var cwd = options.cwd;
104+
var bucket = options.bucket;
105+
var prefix = options.prefix;
106+
var acl = options.acl;
107+
var gzippedFilePaths = options.gzippedFilePaths || [];
108+
var cacheControl = options.cacheControl;
109+
var expires = options.expires;
110+
var serverSideEncryption = options.serverSideEncryption;
110111

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

@@ -140,6 +141,11 @@ module.exports = CoreObject.extend({
140141
CacheControl: cacheControl,
141142
Expires: expires
142143
};
144+
145+
if (serverSideEncryption) {
146+
params.ServerSideEncryption = serverSideEncryption;
147+
}
148+
143149
if (isGzipped) {
144150
params.ContentEncoding = 'gzip';
145151
}

tests/unit/lib/s3-nodetest.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,36 @@ describe('s3', function() {
114114
assert.equal(s3Params.CacheControl, 'max-age=1234, public');
115115
assert.equal(s3Params.Expires, '2010');
116116
assert.isUndefined(s3Params.ContentEncoding);
117+
assert.isUndefined(s3Params.ServerSideEncryption);
117118
});
118119
});
119120

121+
it('sets ServerSideEncryption using serverSideEncryption', function() {
122+
var s3Params;
123+
s3Client.putObject = function(params, cb) {
124+
s3Params = params;
125+
cb();
126+
};
127+
128+
var options = {
129+
filePaths: ['app.css'],
130+
cwd: process.cwd() + '/tests/fixtures/dist',
131+
prefix: 'js-app',
132+
acl: 'public-read',
133+
bucket: 'some-bucket',
134+
cacheControl: 'max-age=1234, public',
135+
expires: '2010',
136+
serverSideEncryption: 'AES256'
137+
};
138+
139+
var promise = subject.upload(options);
140+
141+
return assert.isFulfilled(promise)
142+
.then(function() {
143+
assert.equal(s3Params.ServerSideEncryption, 'AES256', 'ServerSideEncryption passed correctly');
144+
});
145+
});
146+
120147
it('sends the correct content type params for gzipped files with .gz extension', function() {
121148
var s3Params;
122149
s3Client.putObject = function(params, cb) {

0 commit comments

Comments
 (0)