Skip to content

Commit

Permalink
Support S3 server side encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Jul 5, 2017
1 parent 78e0e6a commit 99a7b98
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/uploadAliasArtifacts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const BbPromise = require('bluebird');
const _ = require('lodash');

module.exports = {
uploadAliasCloudFormationFile() {
Expand All @@ -10,13 +11,18 @@ module.exports = {

const fileName = 'compiled-cloudformation-template-alias.json';

const params = {
let params = {
Bucket: this.bucketName,
Key: `${this.serverless.service.package.artifactDirectoryName}/${fileName}`,
Body: body,
ContentType: 'application/json',
};

const deploymentBucketObject = this.serverless.service.provider.deploymentBucketObject;
if (deploymentBucketObject) {
params = setServersideEncryptionOptions(params, deploymentBucketObject);
}

return this.provider.request('S3',
'putObject',
params,
Expand All @@ -34,3 +40,23 @@ module.exports = {
},

};

function setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
const encryptionFields = {
'serverSideEncryption': 'ServerSideEncryption',
'sseCustomerAlgorithim': 'SSECustomerAlgorithm',
'sseCustomerKey': 'SSECustomerKey',
'sseCustomerKeyMD5': 'SSECustomerKeyMD5',
'sseKMSKeyId': 'SSEKMSKeyId',
};

const params = putParams;

_.forOwn(encryptionFields, (value, field) => {
if (deploymentBucketOptions[field]) {
params[value] = deploymentBucketOptions[field];
}
});

return params;
}

0 comments on commit 99a7b98

Please sign in to comment.