From 9a9845765b05cdaacf7860874f558764a17283ec Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Wed, 14 Nov 2018 16:25:34 -0500 Subject: [PATCH 1/3] Force Environment Variables to be Strings This forces any environment variables to be sent to GCF as strings, even if the value was supplied as a non-string (e.g., number). --- package/lib/compileFunctions.js | 11 +++++++---- package/lib/compileFunctions.test.js | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package/lib/compileFunctions.js b/package/lib/compileFunctions.js index d24afbf..22e1d08 100644 --- a/package/lib/compileFunctions.js +++ b/package/lib/compileFunctions.js @@ -46,10 +46,13 @@ module.exports = { 'nodejs8'; funcTemplate.properties.timeout = _.get(funcObject, 'timeout') || _.get(this, 'serverless.service.provider.timeout') || '60s'; - funcTemplate.properties.environmentVariables = _.merge( - {}, - _.get(this, 'serverless.service.provider.environment'), - funcObject.environment // eslint-disable-line comma-dangle + funcTemplate.properties.environmentVariables = _.mapValues( + _.merge( + {}, + _.get(this, 'serverless.service.provider.environment'), + funcObject.environment // eslint-disable-line comma-dangle + ), + (value) => value.toString() // eslint-disable-line comma-dangle ); if (!funcTemplate.properties.serviceAccountEmail) { diff --git a/package/lib/compileFunctions.test.js b/package/lib/compileFunctions.test.js index cfdc6f4..6cfbad5 100644 --- a/package/lib/compileFunctions.test.js +++ b/package/lib/compileFunctions.test.js @@ -376,6 +376,8 @@ describe('CompileFunctions', () => { handler: 'func1', environment: { TEST_VAR: 'test', + TEST_VAR_NUMBER: 123, + TEST_VAR_BOOL: false, }, events: [{ http: 'foo' }], }, @@ -393,6 +395,8 @@ describe('CompileFunctions', () => { availableMemoryMb: 256, environmentVariables: { TEST_VAR: 'test', + TEST_VAR_NUMBER: '123', + TEST_VAR_BOOL: 'false', }, timeout: '60s', sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip', From 0a0a8923203fffbef7f0c55d674488922ef96d71 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Wed, 14 Nov 2018 16:32:08 -0500 Subject: [PATCH 2/3] fix linting issues --- package/lib/compileFunctions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lib/compileFunctions.js b/package/lib/compileFunctions.js index 22e1d08..364d111 100644 --- a/package/lib/compileFunctions.js +++ b/package/lib/compileFunctions.js @@ -52,7 +52,7 @@ module.exports = { _.get(this, 'serverless.service.provider.environment'), funcObject.environment // eslint-disable-line comma-dangle ), - (value) => value.toString() // eslint-disable-line comma-dangle + value => value.toString() // eslint-disable-line comma-dangle ); if (!funcTemplate.properties.serviceAccountEmail) { From 4e875ad2bed0fa83bf2291c8b4dca67b4cfbe908 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Wed, 14 Oct 2020 12:46:03 -0400 Subject: [PATCH 3/3] run prettify --- package/lib/compileFunctions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lib/compileFunctions.js b/package/lib/compileFunctions.js index 364d111..22e1d08 100644 --- a/package/lib/compileFunctions.js +++ b/package/lib/compileFunctions.js @@ -52,7 +52,7 @@ module.exports = { _.get(this, 'serverless.service.provider.environment'), funcObject.environment // eslint-disable-line comma-dangle ), - value => value.toString() // eslint-disable-line comma-dangle + (value) => value.toString() // eslint-disable-line comma-dangle ); if (!funcTemplate.properties.serviceAccountEmail) {