-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathuploadAliasArtifacts.js
61 lines (47 loc) · 1.54 KB
/
uploadAliasArtifacts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const BbPromise = require('bluebird');
const _ = require('lodash');
module.exports = {
uploadAliasCloudFormationFile() {
this.serverless.cli.log('Uploading CloudFormation alias file to S3...');
const body = JSON.stringify(this.serverless.service.provider.compiledCloudFormationAliasTemplate);
const fileName = 'compiled-cloudformation-template-alias.json';
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);
},
uploadAliasArtifacts() {
if (this.options.noDeploy) {
return BbPromise.resolve();
}
return BbPromise.bind(this)
.then(this.resolveDeferredOutputs)
.then(this.uploadAliasCloudFormationFile);
},
};
function setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
const encryptionFields = {
'serverSideEncryption': 'ServerSideEncryption',
'sseCustomerAlgorithm': 'SSECustomerAlgorithm',
'sseCustomerKey': 'SSECustomerKey',
'sseCustomerKeyMD5': 'SSECustomerKeyMD5',
'sseKMSKeyId': 'SSEKMSKeyId',
};
const params = putParams;
_.forOwn(encryptionFields, (value, field) => {
if (deploymentBucketOptions[field]) {
params[value] = deploymentBucketOptions[field];
}
});
return params;
}