Skip to content

Commit 137bf10

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 b68b247 commit 137bf10

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

package/lib/compileFunctions.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ module.exports = {
4343
funcTemplate.properties.timeout = _.get(funcObject, 'timeout')
4444
|| _.get(this, 'serverless.service.provider.timeout')
4545
|| '60s';
46-
funcTemplate.properties.environmentVariables = _.merge(
47-
_.get(this, 'serverless.service.provider.environment'),
48-
funcObject.environment,
46+
funcTemplate.properties.environmentVariables = _.mapValues(
47+
_.merge(
48+
_.get(this, 'serverless.service.provider.environment'),
49+
funcObject.environment,
50+
),
51+
(value) => value.toString()
4952
);
5053

5154
if (!_.size(funcTemplate.properties.environmentVariables)) {

package/lib/compileFunctions.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ describe('CompileFunctions', () => {
366366
handler: 'func1',
367367
environment: {
368368
TEST_VAR: 'test',
369+
TEST_VAR_NUMBER: 123,
370+
TEST_VAR_BOOL: false,
369371
},
370372
events: [
371373
{ http: 'foo' },
@@ -383,6 +385,8 @@ describe('CompileFunctions', () => {
383385
availableMemoryMb: 256,
384386
environmentVariables: {
385387
TEST_VAR: 'test',
388+
TEST_VAR_NUMBER: '123',
389+
TEST_VAR_BOOL: 'false',
386390
},
387391
timeout: '60s',
388392
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',

0 commit comments

Comments
 (0)