Skip to content

Commit

Permalink
Ignore undefined params
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed May 23, 2018
1 parent 6bccd84 commit 67822c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/cfn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ const fs = require('fs');

function hash2ArrayHash(hash, keyProperty = 'Key', valueProperty = 'Value') {
return Object.keys(hash)
.map(key => ({
[keyProperty]: key,
[valueProperty]: hash[key]
}));
.map(key => {
return hash[key] !== undefined ? {
[keyProperty]: key,
[valueProperty]: hash[key]
} : undefined;
})
.filter(Boolean);
}

function ucFirst(str) {
Expand Down Expand Up @@ -116,6 +119,10 @@ class CfnClient {
let value = options[origKey];
let key = ucFirst(origKey);

if (value === undefined) {
return;
}

switch (origKey) {
case 'parameters':
value = hash2ArrayHash(value, 'ParameterKey', 'ParameterValue');
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/cfn-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const options = {
templateBody: `file://${templatePath}`,
parameters: {
key1: 'val1',
key2: 'val2'
key2: 'val2',
key3: undefined
},
capabilities: ['CAPABILITY_IAM'],
resourceTypes: ['AWS::*'],
Expand All @@ -38,7 +39,8 @@ const options = {
disableRollback: true,
rollbackConfiguration: {
MonitoringTimeInMinutes: 10
}
},
dummy: undefined
};

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

0 comments on commit 67822c8

Please sign in to comment.