mirror of
https://github.com/serverless/serverless.git
synced 2026-02-01 16:07:28 +00:00
Minor code cleanup
This commit is contained in:
parent
d045201315
commit
b912ad91bd
@ -110,14 +110,6 @@ class Service {
|
||||
that.serviceObject = { name: serverlessFile.service };
|
||||
that.service = serverlessFile.service;
|
||||
}
|
||||
that.custom = serverlessFile.custom;
|
||||
that.plugins = serverlessFile.plugins;
|
||||
that.resources = serverlessFile.resources;
|
||||
that.functions = serverlessFile.functions || {};
|
||||
|
||||
// merge so that the default settings are still in place and
|
||||
// won't be overwritten
|
||||
that.provider = _.merge(that.provider, serverlessFile.provider);
|
||||
|
||||
if (_.isObject(that.provider.deploymentBucket)) {
|
||||
that.provider.deploymentBucketObject = that.provider.deploymentBucket;
|
||||
@ -130,6 +122,15 @@ class Service {
|
||||
that.provider.deploymentBucketObject = { name: that.provider.deploymentBucket };
|
||||
}
|
||||
|
||||
that.custom = serverlessFile.custom;
|
||||
that.plugins = serverlessFile.plugins;
|
||||
that.resources = serverlessFile.resources;
|
||||
that.functions = serverlessFile.functions || {};
|
||||
|
||||
// merge so that the default settings are still in place and
|
||||
// won't be overwritten
|
||||
that.provider = _.merge(that.provider, serverlessFile.provider);
|
||||
|
||||
if (serverlessFile.package) {
|
||||
that.package.individually = serverlessFile.package.individually;
|
||||
that.package.path = serverlessFile.package.path;
|
||||
|
||||
@ -925,14 +925,16 @@ describe('Service', () => {
|
||||
});
|
||||
|
||||
describe('#setDeploymentBucketName()', () => {
|
||||
it('should set the name field of deploymentBucketObject', () => {
|
||||
it('should set the name field of the deploymentBucket object', () => {
|
||||
const serverless = new Serverless();
|
||||
const serviceInstance = new Service(serverless);
|
||||
const newName = 'new-name';
|
||||
serviceInstance.provider.deploymentBucketObject = {
|
||||
name: 'old-name',
|
||||
};
|
||||
|
||||
serviceInstance.setDeploymentBucketName(newName);
|
||||
|
||||
expect(serviceInstance.provider.deploymentBucketObject.name).to.be.equal(newName);
|
||||
expect(serviceInstance.provider.deploymentBucket).to.be.equal(newName);
|
||||
});
|
||||
|
||||
@ -1,28 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable no-use-before-define */
|
||||
|
||||
const fs = require('fs');
|
||||
const BbPromise = require('bluebird');
|
||||
const filesize = require('filesize');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
|
||||
const encryptionFields = [
|
||||
['serverSideEncryption', 'ServerSideEncryption'],
|
||||
['sseCustomerAlgorithim', 'SSECustomerAlgorithm'],
|
||||
['sseCustomerKey', 'SSECustomerKey'],
|
||||
['sseCustomerKeyMD5', 'SSECustomerKeyMD5'],
|
||||
['sseKMSKeyId', 'SSEKMSKeyId'],
|
||||
];
|
||||
const params = putParams;
|
||||
encryptionFields.forEach((element) => {
|
||||
if (deploymentBucketOptions[element[0]]) {
|
||||
params[element[1]] = deploymentBucketOptions[element[0]];
|
||||
}
|
||||
}, this);
|
||||
return params;
|
||||
},
|
||||
|
||||
uploadCloudFormationFile() {
|
||||
this.serverless.cli.log('Uploading CloudFormation file to S3...');
|
||||
|
||||
@ -36,9 +21,8 @@ module.exports = {
|
||||
ContentType: 'application/json',
|
||||
};
|
||||
const bucketObject = this.serverless.service.provider.deploymentBucketObject;
|
||||
if (bucketObject) {
|
||||
params = this.setServersideEncryptionOptions(params, bucketObject);
|
||||
}
|
||||
|
||||
if (bucketObject) params = setServersideEncryptionOptions(params, bucketObject);
|
||||
|
||||
return this.provider.request('S3',
|
||||
'putObject',
|
||||
@ -57,9 +41,9 @@ module.exports = {
|
||||
ContentType: 'application/zip',
|
||||
};
|
||||
const bucketObject = this.serverless.service.provider.deploymentBucketObject;
|
||||
if (bucketObject) {
|
||||
params = this.setServersideEncryptionOptions(params, bucketObject);
|
||||
}
|
||||
|
||||
if (bucketObject) params = setServersideEncryptionOptions(params, bucketObject);
|
||||
|
||||
return this.provider.request('S3',
|
||||
'putObject',
|
||||
params,
|
||||
@ -108,3 +92,23 @@ module.exports = {
|
||||
.then(this.uploadFunctions);
|
||||
},
|
||||
};
|
||||
|
||||
function setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
|
||||
const encryptionFields = [
|
||||
['serverSideEncryption', 'ServerSideEncryption'],
|
||||
['sseCustomerAlgorithim', 'SSECustomerAlgorithm'],
|
||||
['sseCustomerKey', 'SSECustomerKey'],
|
||||
['sseCustomerKeyMD5', 'SSECustomerKeyMD5'],
|
||||
['sseKMSKeyId', 'SSEKMSKeyId'],
|
||||
];
|
||||
|
||||
const params = putParams;
|
||||
|
||||
encryptionFields.forEach((element) => {
|
||||
if (deploymentBucketOptions[element[0]]) {
|
||||
params[element[1]] = deploymentBucketOptions[element[0]];
|
||||
}
|
||||
}, this);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -86,6 +86,7 @@ describe('uploadArtifacts', () => {
|
||||
awsDeploy.options.stage,
|
||||
awsDeploy.options.region
|
||||
)).to.be.equal(true);
|
||||
|
||||
awsDeploy.provider.request.restore();
|
||||
});
|
||||
});
|
||||
@ -122,6 +123,7 @@ describe('uploadArtifacts', () => {
|
||||
awsDeploy.provider.request.restore();
|
||||
});
|
||||
});
|
||||
|
||||
it('should upload to a bucket with server side encryption bucket policy', () => {
|
||||
const tmpDirPath = testUtils.getTmpDirPath();
|
||||
const artifactFilePath = path.join(tmpDirPath, 'artifact.zip');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user