diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb76a4..72d712e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.1.0](https://github.com/serverless/serverless-google-cloudfunctions/compare/v3.0.0...v3.1.0) (2020-05-11) + +### Features + +- Support serviceAccount option for deployment ([#215](https://github.com/serverless/serverless-google-cloudfunctions/issues/215)) ([1164495](https://github.com/serverless/serverless-google-cloudfunctions/commit/11644956771bc64dc0259b6316502f104fadf1ea)) + +### Bug Fixes + +- Fix function name resolution on invoke ([#216](https://github.com/serverless/serverless-google-cloudfunctions/issues/216)) ([86d40aa](https://github.com/serverless/serverless-google-cloudfunctions/commit/86d40aa3ab07e512eb7e6a92424db399335a8201)) + ## [3.0.0](https://github.com/serverless/serverless-google-cloudfunctions/compare/v2.4.3...v3.0.0) (2020-04-01) ### ⚠ BREAKING CHANGES diff --git a/deploy/googleDeploy.js b/deploy/googleDeploy.js index 46732a2..98360fa 100644 --- a/deploy/googleDeploy.js +++ b/deploy/googleDeploy.js @@ -30,10 +30,7 @@ class GoogleDeploy { ); this.hooks = { - 'before:deploy:deploy': () => - BbPromise.bind(this) - .then(this.validate) - .then(this.setDefaults), + 'before:deploy:deploy': () => BbPromise.bind(this).then(this.validate).then(this.setDefaults), 'deploy:deploy': () => BbPromise.bind(this) diff --git a/deploy/lib/cleanupDeploymentBucket.js b/deploy/lib/cleanupDeploymentBucket.js index 1115c6c..d41f965 100644 --- a/deploy/lib/cleanupDeploymentBucket.js +++ b/deploy/lib/cleanupDeploymentBucket.js @@ -5,9 +5,7 @@ const _ = require('lodash'); module.exports = { cleanupDeploymentBucket() { - return BbPromise.bind(this) - .then(this.getObjectsToRemove) - .then(this.removeObjects); + return BbPromise.bind(this).then(this.getObjectsToRemove).then(this.removeObjects); }, getObjectsToRemove() { @@ -15,7 +13,7 @@ module.exports = { bucket: this.serverless.service.provider.deploymentBucketName, }; - return this.provider.request('storage', 'objects', 'list', params).then(response => { + return this.provider.request('storage', 'objects', 'list', params).then((response) => { if (!response.items.length) return BbPromise.resolve([]); const files = response.items; @@ -25,7 +23,7 @@ module.exports = { const orderedObjects = _.orderBy( files, - file => { + (file) => { const timestamp = file.name.match(/(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/)[4]; return timestamp; }, @@ -48,7 +46,7 @@ module.exports = { this.serverless.cli.log('Removing old artifacts...'); - const removePromises = objectsToRemove.map(object => { + const removePromises = objectsToRemove.map((object) => { const params = { bucket: object.bucket, object: object.name, diff --git a/deploy/lib/cleanupDeploymentBucket.test.js b/deploy/lib/cleanupDeploymentBucket.test.js index 52a3369..a7a43dd 100644 --- a/deploy/lib/cleanupDeploymentBucket.test.js +++ b/deploy/lib/cleanupDeploymentBucket.test.js @@ -94,7 +94,7 @@ describe('CleanupDeploymentBucket', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.getObjectsToRemove().then(objects => { + return googleDeploy.getObjectsToRemove().then((objects) => { expect(objects.length).toEqual(2); expect(objects).not.toContainEqual({ bucket: 'sls-my-service-dev-12345678', @@ -143,7 +143,7 @@ describe('CleanupDeploymentBucket', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.getObjectsToRemove().then(objects => { + return googleDeploy.getObjectsToRemove().then((objects) => { expect(objects.length).toEqual(0); expect(objects).toEqual([]); expect( @@ -160,7 +160,7 @@ describe('CleanupDeploymentBucket', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.getObjectsToRemove().then(objects => { + return googleDeploy.getObjectsToRemove().then((objects) => { expect(objects.length).toEqual(0); expect(objects).toEqual([]); expect( @@ -217,7 +217,7 @@ describe('CleanupDeploymentBucket', () => { requestStub.returns(BbPromise.resolve('removePromise')); - return googleDeploy.removeObjects(objectsToRemove).then(removePromises => { + return googleDeploy.removeObjects(objectsToRemove).then((removePromises) => { expect(requestStub.called).toEqual(true); expect(consoleLogStub.calledOnce).toEqual(true); expect(removePromises).toEqual([ diff --git a/deploy/lib/createDeployment.js b/deploy/lib/createDeployment.js index 8b78e7d..2f2ca9e 100644 --- a/deploy/lib/createDeployment.js +++ b/deploy/lib/createDeployment.js @@ -7,9 +7,7 @@ const BbPromise = require('bluebird'); module.exports = { createDeployment() { - return BbPromise.bind(this) - .then(this.checkForExistingDeployment) - .then(this.createIfNotExists); + return BbPromise.bind(this).then(this.checkForExistingDeployment).then(this.createIfNotExists); }, checkForExistingDeployment() { @@ -19,11 +17,11 @@ module.exports = { return this.provider .request('deploymentmanager', 'deployments', 'list', params) - .then(response => { + .then((response) => { let foundDeployment; if (response && response.deployments) { - foundDeployment = response.deployments.find(deployment => { + foundDeployment = response.deployments.find((deployment) => { const name = `sls-${this.serverless.service.service}-${this.options.stage}`; return deployment.name === name; }); diff --git a/deploy/lib/createDeployment.test.js b/deploy/lib/createDeployment.test.js index d400456..506d954 100644 --- a/deploy/lib/createDeployment.test.js +++ b/deploy/lib/createDeployment.test.js @@ -72,7 +72,7 @@ describe('CreateDeployment', () => { it('should return "undefined" if no deployments are found', () => { requestStub.returns(BbPromise.resolve([])); - return googleDeploy.checkForExistingDeployment().then(foundDeployment => { + return googleDeploy.checkForExistingDeployment().then((foundDeployment) => { expect(foundDeployment).toEqual(undefined); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -88,7 +88,7 @@ describe('CreateDeployment', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.checkForExistingDeployment().then(foundDeployment => { + return googleDeploy.checkForExistingDeployment().then((foundDeployment) => { expect(foundDeployment).toEqual(undefined); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -104,7 +104,7 @@ describe('CreateDeployment', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.checkForExistingDeployment().then(foundDeployment => { + return googleDeploy.checkForExistingDeployment().then((foundDeployment) => { expect(foundDeployment).toEqual(response.deployments[0]); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { diff --git a/deploy/lib/updateDeployment.js b/deploy/lib/updateDeployment.js index 61ec308..07c7523 100644 --- a/deploy/lib/updateDeployment.js +++ b/deploy/lib/updateDeployment.js @@ -7,9 +7,7 @@ const BbPromise = require('bluebird'); module.exports = { updateDeployment() { - return BbPromise.bind(this) - .then(this.getDeployment) - .then(this.update); + return BbPromise.bind(this).then(this.getDeployment).then(this.update); }, getDeployment() { @@ -19,8 +17,8 @@ module.exports = { return this.provider .request('deploymentmanager', 'deployments', 'list', params) - .then(response => { - const deployment = response.deployments.find(dep => { + .then((response) => { + const deployment = response.deployments.find((dep) => { const name = `sls-${this.serverless.service.service}-${this.options.stage}`; return dep.name === name; }); diff --git a/deploy/lib/updateDeployment.test.js b/deploy/lib/updateDeployment.test.js index 2cab4f2..e83d4b8 100644 --- a/deploy/lib/updateDeployment.test.js +++ b/deploy/lib/updateDeployment.test.js @@ -71,7 +71,7 @@ describe('UpdateDeployment', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.getDeployment().then(foundDeployment => { + return googleDeploy.getDeployment().then((foundDeployment) => { expect(foundDeployment).toEqual(undefined); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -87,7 +87,7 @@ describe('UpdateDeployment', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleDeploy.getDeployment().then(foundDeployment => { + return googleDeploy.getDeployment().then((foundDeployment) => { expect(foundDeployment).toEqual(response.deployments[0]); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { diff --git a/info/googleInfo.js b/info/googleInfo.js index bee73ab..37af6b7 100644 --- a/info/googleInfo.js +++ b/info/googleInfo.js @@ -15,10 +15,7 @@ class GoogleInfo { Object.assign(this, validate, setDefaults, displayServiceInfo); this.hooks = { - 'before:info:info': () => - BbPromise.bind(this) - .then(this.validate) - .then(this.setDefaults), + 'before:info:info': () => BbPromise.bind(this).then(this.validate).then(this.setDefaults), 'deploy:deploy': () => BbPromise.bind(this).then(this.displayServiceInfo), diff --git a/info/lib/displayServiceInfo.js b/info/lib/displayServiceInfo.js index 654ce5f..a89c016 100644 --- a/info/lib/displayServiceInfo.js +++ b/info/lib/displayServiceInfo.js @@ -8,10 +8,7 @@ const _ = require('lodash'); module.exports = { displayServiceInfo() { - return BbPromise.bind(this) - .then(this.getResources) - .then(this.gatherData) - .then(this.printInfo); + return BbPromise.bind(this).then(this.getResources).then(this.gatherData).then(this.printInfo); }, getResources() { @@ -36,7 +33,7 @@ module.exports = { functions: [], }; - _.forEach(resources.resources, resource => { + _.forEach(resources.resources, (resource) => { if (resource.type === 'gcp-types/cloudfunctions-v1:projects.locations.functions') { const serviceFuncName = getFunctionNameInService( resource.name, @@ -83,7 +80,7 @@ module.exports = { // get all the functions message += `${chalk.yellow.underline('Deployed functions')}\n`; if (data.resources.functions.length) { - data.resources.functions.forEach(func => { + data.resources.functions.forEach((func) => { message += `${chalk.yellow(func.name)}\n`; message += ` ${func.resource}\n`; }); diff --git a/info/lib/displayServiceInfo.test.js b/info/lib/displayServiceInfo.test.js index 8983e1b..5f08b9b 100644 --- a/info/lib/displayServiceInfo.test.js +++ b/info/lib/displayServiceInfo.test.js @@ -126,7 +126,7 @@ describe('DisplayServiceInfo', () => { }, }; - return googleInfo.gatherData(resources).then(data => { + return googleInfo.gatherData(resources).then((data) => { expect(data).toEqual(expectedData); }); }); @@ -146,7 +146,7 @@ describe('DisplayServiceInfo', () => { }, }; - return googleInfo.gatherData(resources).then(data => { + return googleInfo.gatherData(resources).then((data) => { expect(data).toEqual(expectedData); }); }); diff --git a/invoke/googleInvoke.js b/invoke/googleInvoke.js index 3b4e79a..935f8b9 100644 --- a/invoke/googleInvoke.js +++ b/invoke/googleInvoke.js @@ -15,10 +15,7 @@ class GoogleInvoke { Object.assign(this, validate, setDefaults, invokeFunction); this.hooks = { - 'before:invoke:invoke': () => - BbPromise.bind(this) - .then(this.validate) - .then(this.setDefaults), + 'before:invoke:invoke': () => BbPromise.bind(this).then(this.validate).then(this.setDefaults), 'invoke:invoke': () => BbPromise.bind(this).then(this.invokeFunction), }; diff --git a/invoke/lib/invokeFunction.js b/invoke/lib/invokeFunction.js index fb88c9c..5dccea8 100644 --- a/invoke/lib/invokeFunction.js +++ b/invoke/lib/invokeFunction.js @@ -7,9 +7,7 @@ const chalk = require('chalk'); module.exports = { invokeFunction() { - return BbPromise.bind(this) - .then(this.invoke) - .then(this.printResult); + return BbPromise.bind(this).then(this.invoke).then(this.printResult); }, invoke() { @@ -65,5 +63,5 @@ const getGoogleCloudFunctionName = (serviceFunctions, func) => { throw new Error(errorMessage); } - return serviceFunctions[func].handler; + return serviceFunctions[func].name; }; diff --git a/invoke/lib/invokeFunction.test.js b/invoke/lib/invokeFunction.test.js index f2a7844..6711dc2 100644 --- a/invoke/lib/invokeFunction.test.js +++ b/invoke/lib/invokeFunction.test.js @@ -23,6 +23,7 @@ describe('InvokeFunction', () => { serverless.service.functions = { func1: { handler: 'foo', + name: 'full-function-name', }, }; serverless.setProvider('google', new GoogleProvider(serverless)); @@ -77,7 +78,7 @@ describe('InvokeFunction', () => { 'functions', 'call', { - name: 'projects/my-project/locations/us-central1/functions/foo', + name: 'projects/my-project/locations/us-central1/functions/full-function-name', resource: { data: '', }, @@ -100,7 +101,7 @@ describe('InvokeFunction', () => { 'functions', 'call', { - name: 'projects/my-project/locations/us-central1/functions/foo', + name: 'projects/my-project/locations/us-central1/functions/full-function-name', resource: { data: googleInvoke.options.data, }, diff --git a/logs/googleLogs.js b/logs/googleLogs.js index adc1e23..a3657c5 100644 --- a/logs/googleLogs.js +++ b/logs/googleLogs.js @@ -27,10 +27,7 @@ class GoogleLogs { Object.assign(this, validate, setDefaults, retrieveLogs); this.hooks = { - 'before:logs:logs': () => - BbPromise.bind(this) - .then(this.validate) - .then(this.setDefaults), + 'before:logs:logs': () => BbPromise.bind(this).then(this.validate).then(this.setDefaults), 'logs:logs': () => BbPromise.bind(this).then(this.retrieveLogs), }; diff --git a/logs/lib/retrieveLogs.js b/logs/lib/retrieveLogs.js index e0447d6..aaff1bb 100644 --- a/logs/lib/retrieveLogs.js +++ b/logs/lib/retrieveLogs.js @@ -7,9 +7,7 @@ const chalk = require('chalk'); module.exports = { retrieveLogs() { - return BbPromise.bind(this) - .then(this.getLogs) - .then(this.printLogs); + return BbPromise.bind(this).then(this.getLogs).then(this.printLogs); }, getLogs() { diff --git a/package.json b/package.json index 1ac95f0..62ff5c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-google-cloudfunctions", - "version": "3.0.0", + "version": "3.1.0", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Google Cloud Functions.", "author": "serverless.com", "repository": "serverless/serverless-google-cloudfunctions", @@ -41,25 +41,25 @@ "dependencies": { "async": "^2.6.3", "bluebird": "^3.7.2", - "chalk": "^2.4.2", + "chalk": "^3.0.0", "fs-extra": "^8.1.0", - "googleapis": "^48.0.0", + "googleapis": "^50.0.0", "lodash": "^4.17.15" }, "devDependencies": { "@commitlint/cli": "^8.3.5", - "@serverless/eslint-config": "^1.2.1", - "coveralls": "^3.0.11", + "@serverless/eslint-config": "^2.0.0", + "coveralls": "^3.1.0", "eslint": "^6.8.0", - "eslint-plugin-import": "^2.20.1", + "eslint-plugin-import": "^2.20.2", "git-list-updated": "^1.2.1", "github-release-from-cc-changelog": "^2.2.0", - "husky": "^4.2.3", - "jest": "^24.9.0", - "lint-staged": "^10.0.9", - "prettier": "^1.19.1", - "sinon": "^7.5.0", - "standard-version": "^7.1.0" + "husky": "^4.2.5", + "jest": "^25.5.4", + "lint-staged": "^10.2.2", + "prettier": "^2.0.5", + "sinon": "^8.1.1", + "standard-version": "^8.0.0" }, "scripts": { "commitlint": "commitlint -f HEAD@{15}", diff --git a/package/googlePackage.js b/package/googlePackage.js index e08a4f8..754d6db 100644 --- a/package/googlePackage.js +++ b/package/googlePackage.js @@ -37,9 +37,7 @@ class GooglePackage { 'package:cleanup': () => BbPromise.bind(this).then(this.cleanupServerlessDir), 'before:package:initialize': () => - BbPromise.bind(this) - .then(this.validate) - .then(this.setDefaults), + BbPromise.bind(this).then(this.validate).then(this.setDefaults), 'package:initialize': () => BbPromise.bind(this) @@ -53,9 +51,7 @@ class GooglePackage { 'package:compileFunctions': () => BbPromise.bind(this).then(this.compileFunctions), 'package:finalize': () => - BbPromise.bind(this) - .then(this.mergeServiceResources) - .then(this.saveUpdateTemplateFile), + BbPromise.bind(this).then(this.mergeServiceResources).then(this.saveUpdateTemplateFile), }; } } diff --git a/package/lib/compileFunctions.js b/package/lib/compileFunctions.js index 5306fd2..d24afbf 100644 --- a/package/lib/compileFunctions.js +++ b/package/lib/compileFunctions.js @@ -16,7 +16,7 @@ module.exports = { this.serverless.service.provider.region || 'us-central1'; this.serverless.service.package.artifactFilePath = `${this.serverless.service.package.artifactDirectoryName}/${fileName}`; - this.serverless.service.getAllFunctions().forEach(functionName => { + this.serverless.service.getAllFunctions().forEach((functionName) => { const funcObject = this.serverless.service.getFunction(functionName); this.serverless.cli.log(`Compiling function "${functionName}"...`); @@ -32,6 +32,10 @@ module.exports = { `gs://${this.serverless.service.provider.deploymentBucketName}/${this.serverless.service.package.artifactFilePath}` ); + funcTemplate.properties.serviceAccountEmail = + _.get(funcObject, 'serviceAccountEmail') || + _.get(this, 'serverless.service.provider.serviceAccountEmail') || + null; funcTemplate.properties.availableMemoryMb = _.get(funcObject, 'memorySize') || _.get(this, 'serverless.service.provider.memorySize') || @@ -48,6 +52,10 @@ module.exports = { funcObject.environment // eslint-disable-line comma-dangle ); + if (!funcTemplate.properties.serviceAccountEmail) { + delete funcTemplate.properties.serviceAccountEmail; + } + if (funcObject.vpc) { _.assign(funcTemplate.properties, { vpcConnector: _.get(funcObject, 'vpc') || _.get(this, 'serverless.service.provider.vpc'), diff --git a/package/lib/prepareDeployment.js b/package/lib/prepareDeployment.js index da28508..d116671 100644 --- a/package/lib/prepareDeployment.js +++ b/package/lib/prepareDeployment.js @@ -36,7 +36,7 @@ const updateBucketName = (bucket, name) => { return newBucket; }; -const findDeploymentBucket = resource => { +const findDeploymentBucket = (resource) => { const type = 'storage.v1.bucket'; const name = 'will-be-replaced-by-serverless'; diff --git a/provider/googleProvider.js b/provider/googleProvider.js index ebb4d04..8638177 100644 --- a/provider/googleProvider.js +++ b/provider/googleProvider.js @@ -41,13 +41,34 @@ class GoogleProvider { logging: google.logging('v2'), cloudfunctions: google.cloudfunctions('v1'), }; + + this.variableResolvers = { + gs: this.getGsValue, + }; + } + + getGsValue(variableString) { + const groups = variableString.split(':')[1].split('/'); + const bucket = groups.shift(); + const object = groups.join('/'); + + return this.serverless + .getProvider('google') + .request('storage', 'objects', 'get', { + bucket, + object, + alt: 'media', + }) + .catch((err) => { + throw new Error(`Error getting value for ${variableString}. ${err.message}`); + }); } request() { // grab necessary stuff from arguments array const lastArg = arguments[Object.keys(arguments).pop()]; //eslint-disable-line const hasParams = typeof lastArg === 'object'; - const filArgs = _.filter(arguments, v => typeof v === 'string'); //eslint-disable-line + const filArgs = _.filter(arguments, (v) => typeof v === 'string'); //eslint-disable-line const params = hasParams ? lastArg : {}; const service = filArgs[0]; @@ -65,8 +86,8 @@ class GoogleProvider { return filArgs .reduce((p, c) => p[c], this.sdk) .bind(serviceInstance)(requestParams) - .then(result => result.data) - .catch(error => { + .then((result) => result.data) + .catch((error) => { if ( error && error.errors && diff --git a/provider/googleProvider.test.js b/provider/googleProvider.test.js index 08b501f..655c355 100644 --- a/provider/googleProvider.test.js +++ b/provider/googleProvider.test.js @@ -109,7 +109,7 @@ describe('GoogleProvider', () => { googleProvider.sdk.service.resource.method.bind = () => sinon.stub().resolves({ data: 'result' }); - return googleProvider.request('service', 'resource', 'method', {}).then(result => { + return googleProvider.request('service', 'resource', 'method', {}).then((result) => { expect(result).toEqual('result'); }); }); diff --git a/remove/googleRemove.js b/remove/googleRemove.js index 89c6aaa..fb44a39 100644 --- a/remove/googleRemove.js +++ b/remove/googleRemove.js @@ -33,9 +33,7 @@ class GoogleRemove { .then(this.setDeploymentBucketName), 'remove:remove': () => - BbPromise.bind(this) - .then(this.emptyDeploymentBucket) - .then(this.removeDeployment), + BbPromise.bind(this).then(this.emptyDeploymentBucket).then(this.removeDeployment), }; } } diff --git a/remove/lib/emptyDeploymentBucket.js b/remove/lib/emptyDeploymentBucket.js index 90b4e72..3f187a9 100644 --- a/remove/lib/emptyDeploymentBucket.js +++ b/remove/lib/emptyDeploymentBucket.js @@ -4,9 +4,7 @@ const BbPromise = require('bluebird'); module.exports = { emptyDeploymentBucket() { - return BbPromise.bind(this) - .then(this.getObjectsToRemove) - .then(this.removeObjects); + return BbPromise.bind(this).then(this.getObjectsToRemove).then(this.removeObjects); }, getObjectsToRemove() { @@ -14,7 +12,7 @@ module.exports = { bucket: this.serverless.service.provider.deploymentBucketName, }; - return this.provider.request('storage', 'objects', 'list', params).then(response => { + return this.provider.request('storage', 'objects', 'list', params).then((response) => { if (!response.items || !response.items.length) return BbPromise.resolve([]); return BbPromise.resolve(response.items); @@ -26,7 +24,7 @@ module.exports = { this.serverless.cli.log('Removing artifacts in deployment bucket...'); - const removePromises = objectsToRemove.map(object => { + const removePromises = objectsToRemove.map((object) => { const params = { bucket: object.bucket, object: object.name, diff --git a/remove/lib/emptyDeploymentBucket.test.js b/remove/lib/emptyDeploymentBucket.test.js index 04050b9..e2a4f09 100644 --- a/remove/lib/emptyDeploymentBucket.test.js +++ b/remove/lib/emptyDeploymentBucket.test.js @@ -69,7 +69,7 @@ describe('EmptyDeploymentBucket', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleRemove.getObjectsToRemove().then(objects => { + return googleRemove.getObjectsToRemove().then((objects) => { expect(objects.length).toEqual(0); expect(objects).toEqual([]); expect( @@ -95,7 +95,7 @@ describe('EmptyDeploymentBucket', () => { }; requestStub.returns(BbPromise.resolve(response)); - return googleRemove.getObjectsToRemove().then(objects => { + return googleRemove.getObjectsToRemove().then((objects) => { expect(objects.length).toEqual(2); expect(objects).toContainEqual({ bucket: 'sls-my-service-dev-12345678', @@ -151,7 +151,7 @@ describe('EmptyDeploymentBucket', () => { requestStub.returns(BbPromise.resolve('removePromise')); - return googleRemove.removeObjects(objectsToRemove).then(removePromises => { + return googleRemove.removeObjects(objectsToRemove).then((removePromises) => { expect(requestStub.called).toEqual(true); expect(consoleLogStub.calledOnce).toEqual(true); expect(removePromises).toEqual(['removePromise', 'removePromise']); diff --git a/shared/monitorDeployment.js b/shared/monitorDeployment.js index 3d53243..89af79b 100644 --- a/shared/monitorDeployment.js +++ b/shared/monitorDeployment.js @@ -17,21 +17,21 @@ module.exports = { async.whilst( () => validStatuses.indexOf(deploymentStatus) === -1, - callback => { + (callback) => { setTimeout(() => { const params = { project: this.serverless.service.provider.project, }; return this.provider .request('deploymentmanager', 'deployments', 'list', params) - .then(response => { + .then((response) => { // if actions is "remove" and no deployments are left set to "DONE" if (!response.deployments && action === 'remove') { deploymentStatus = 'DONE'; callback(); } - const deployment = response.deployments.find(dep => dep.name === deploymentName); + const deployment = response.deployments.find((dep) => dep.name === deploymentName); // if actions is "remove" and deployment disappeared then set to "DONE" if (!deployment && action === 'remove') { @@ -46,7 +46,7 @@ module.exports = { this.serverless.cli.printDot(); return callback(); }) - .catch(error => { + .catch((error) => { reject(error); }); }, frequency); @@ -63,7 +63,7 @@ module.exports = { }, }; -const throwErrorIfDeploymentFails = deployment => { +const throwErrorIfDeploymentFails = (deployment) => { if (deployment.operation.error && deployment.operation.error.errors.length) { const errorCode = deployment.operation.error.errors[0].code; const parsedDetails = deployment.operation.error.errors[0].message; diff --git a/shared/monitorDeployment.test.js b/shared/monitorDeployment.test.js index cfd3065..a90893e 100644 --- a/shared/monitorDeployment.test.js +++ b/shared/monitorDeployment.test.js @@ -67,7 +67,7 @@ describe('MonitorDeployment', () => { return googleCommand .monitorDeployment(deploymentName, 'create', 10) - .then(deploymentStatus => { + .then((deploymentStatus) => { expect(consoleLogStub.called).toEqual(true); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -100,7 +100,7 @@ describe('MonitorDeployment', () => { requestStub.returns(BbPromise.resolve(response)); - return googleCommand.monitorDeployment(deploymentName, 'update', 10).catch(error => { + return googleCommand.monitorDeployment(deploymentName, 'update', 10).catch((error) => { expect(consoleLogStub.called).toEqual(true); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -121,7 +121,7 @@ describe('MonitorDeployment', () => { return googleCommand .monitorDeployment(deploymentName, 'remove', 10) - .then(deploymentStatus => { + .then((deploymentStatus) => { expect(consoleLogStub.called).toEqual(true); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { @@ -142,7 +142,7 @@ describe('MonitorDeployment', () => { return googleCommand .monitorDeployment(deploymentName, 'remove', 10) - .then(deploymentStatus => { + .then((deploymentStatus) => { expect(consoleLogStub.called).toEqual(true); expect( requestStub.calledWithExactly('deploymentmanager', 'deployments', 'list', { diff --git a/shared/setDeploymentBucketName.js b/shared/setDeploymentBucketName.js index 6273105..5a6a9ce 100644 --- a/shared/setDeploymentBucketName.js +++ b/shared/setDeploymentBucketName.js @@ -21,12 +21,12 @@ module.exports = { return this.provider .request('deploymentmanager', 'resources', 'list', params) - .then(response => { + .then((response) => { if (!_.isEmpty(response) && response.resources) { const regex = new RegExp(`sls-${service}-${stage}-.+`); const deploymentBucket = response.resources.find( - resource => resource.type === 'storage.v1.bucket' && resource.name.match(regex) + (resource) => resource.type === 'storage.v1.bucket' && resource.name.match(regex) ); this.serverless.service.provider.deploymentBucketName = deploymentBucket.name; diff --git a/test/serverless.js b/test/serverless.js index 1c31d4e..321d72a 100644 --- a/test/serverless.js +++ b/test/serverless.js @@ -6,11 +6,11 @@ class Serverless { this.providers = {}; this.service = {}; - this.service.getAllFunctions = function() { + this.service.getAllFunctions = function () { //eslint-disable-line return Object.keys(this.functions); }; - this.service.getFunction = function(functionName) { + this.service.getFunction = function (functionName) { //eslint-disable-line // NOTE the stage is always 'dev'! this.functions[functionName].name = `${this.service}-dev-${functionName}`; @@ -29,7 +29,7 @@ class Serverless { this.plugins = []; this.pluginManager = { - addPlugin: plugin => this.plugins.push(plugin), + addPlugin: (plugin) => this.plugins.push(plugin), }; }