Skip to content

Commit

Permalink
fix(Variables): In ssm source auto parse only object JSON notation
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 15, 2021
1 parent 1864969 commit 8c741d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ module.exports = (serverlessInstance) => {
);
}
}
if (shouldReturnRawValue) return { value: result.Parameter.Value };
if (shouldReturnRawValue || !result.Parameter.Value.startsWith('{')) {
return { value: result.Parameter.Value };
}
try {
return { value: JSON.parse(result.Parameter.Value) };
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
existingListRaw: '${ssm(raw):existingList}',
secretManager: '${ssm:/aws/reference/secretsmanager/existing}',
existingEncrypted: '${ssm:/secret/existing}',
existingEncryptedDirect: '${ssm:/secret/direct}',
existingEncryptedRaw: '${ssm(raw):/aws/reference/secretsmanager/existing}',
notExisting: '${ssm:notExisting, null}',
missingAddress: '${ssm:}',
Expand All @@ -49,6 +50,9 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
if (Name === '/secret/existing' || Name === '/aws/reference/secretsmanager/existing') {
return { Parameter: { Type: 'SecureString', Value: '{"someSecret":"someValue"}' } };
}
if (Name === '/secret/direct') {
return { Parameter: { Type: 'SecureString', Value: '12345678901234567890' } };
}
if (Name === 'notExisting') {
throw Object.assign(
new Error(
Expand Down Expand Up @@ -104,7 +108,11 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
if (variablesMeta.get('custom\0existingEncrypted')) {
throw variablesMeta.get('custom\0existingEncrypted').error;
}
if (variablesMeta.get('custom\0existingDirect')) {
throw variablesMeta.get('custom\0existingDirect').error;
}
expect(configuration.custom.existingEncrypted).to.deep.equal({ someSecret: 'someValue' });
expect(configuration.custom.existingEncryptedDirect).to.equal('12345678901234567890');
});

it('should support "raw" output for decrypted data', () => {
Expand Down

0 comments on commit 8c741d1

Please sign in to comment.