Skip to content

Commit 9a98457

Browse files
committed
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).
1 parent be817a2 commit 9a98457

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

package/lib/compileFunctions.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ module.exports = {
4646
'nodejs8';
4747
funcTemplate.properties.timeout =
4848
_.get(funcObject, 'timeout') || _.get(this, 'serverless.service.provider.timeout') || '60s';
49-
funcTemplate.properties.environmentVariables = _.merge(
50-
{},
51-
_.get(this, 'serverless.service.provider.environment'),
52-
funcObject.environment // eslint-disable-line comma-dangle
49+
funcTemplate.properties.environmentVariables = _.mapValues(
50+
_.merge(
51+
{},
52+
_.get(this, 'serverless.service.provider.environment'),
53+
funcObject.environment // eslint-disable-line comma-dangle
54+
),
55+
(value) => value.toString() // eslint-disable-line comma-dangle
5356
);
5457

5558
if (!funcTemplate.properties.serviceAccountEmail) {

package/lib/compileFunctions.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ describe('CompileFunctions', () => {
376376
handler: 'func1',
377377
environment: {
378378
TEST_VAR: 'test',
379+
TEST_VAR_NUMBER: 123,
380+
TEST_VAR_BOOL: false,
379381
},
380382
events: [{ http: 'foo' }],
381383
},
@@ -393,6 +395,8 @@ describe('CompileFunctions', () => {
393395
availableMemoryMb: 256,
394396
environmentVariables: {
395397
TEST_VAR: 'test',
398+
TEST_VAR_NUMBER: '123',
399+
TEST_VAR_BOOL: 'false',
396400
},
397401
timeout: '60s',
398402
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',

0 commit comments

Comments
 (0)