Skip to content

Commit 67822c8

Browse files
committed
Ignore undefined params
1 parent 6bccd84 commit 67822c8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/cfn.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ const fs = require('fs');
55

66
function hash2ArrayHash(hash, keyProperty = 'Key', valueProperty = 'Value') {
77
return Object.keys(hash)
8-
.map(key => ({
9-
[keyProperty]: key,
10-
[valueProperty]: hash[key]
11-
}));
8+
.map(key => {
9+
return hash[key] !== undefined ? {
10+
[keyProperty]: key,
11+
[valueProperty]: hash[key]
12+
} : undefined;
13+
})
14+
.filter(Boolean);
1215
}
1316

1417
function ucFirst(str) {
@@ -116,6 +119,10 @@ class CfnClient {
116119
let value = options[origKey];
117120
let key = ucFirst(origKey);
118121

122+
if (value === undefined) {
123+
return;
124+
}
125+
119126
switch (origKey) {
120127
case 'parameters':
121128
value = hash2ArrayHash(value, 'ParameterKey', 'ParameterValue');

tests/unit/cfn-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const options = {
2323
templateBody: `file://${templatePath}`,
2424
parameters: {
2525
key1: 'val1',
26-
key2: 'val2'
26+
key2: 'val2',
27+
key3: undefined
2728
},
2829
capabilities: ['CAPABILITY_IAM'],
2930
resourceTypes: ['AWS::*'],
@@ -38,7 +39,8 @@ const options = {
3839
disableRollback: true,
3940
rollbackConfiguration: {
4041
MonitoringTimeInMinutes: 10
41-
}
42+
},
43+
dummy: undefined
4244
};
4345

4446
const templateBody = fs.readFileSync(templatePath, { encoding: 'utf8' });

0 commit comments

Comments
 (0)