Skip to content

Commit

Permalink
fix(Variables): Strip unrecognized legacy instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 14, 2021
1 parent 93233d1 commit f61859f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/configuration/variables/sources/instance-dependent/get-ssm.js
Expand Up @@ -4,8 +4,6 @@ const ensureString = require('type/string/ensure');
const ServerlessError = require('../../../../serverless-error');
const logDeprecation = require('../../../../utils/logDeprecation');

const legacyInstructions = new Set(['true', 'split']);

module.exports = (serverlessInstance) => {
return {
resolve: async ({ address, params, resolveConfigurationProperty }) => {
Expand Down Expand Up @@ -33,22 +31,20 @@ module.exports = (serverlessInstance) => {
const legacyInstructionSeparator = address.lastIndexOf('~');
if (legacyInstructionSeparator !== -1) {
const instruction = address.slice(legacyInstructionSeparator + 1);
if (legacyInstructions.has(instruction)) {
address = address.slice(0, legacyInstructionSeparator);
if (instruction === 'true') legacyShouldEnforceDecrypt = true;
else legacyShouldEnforceSplit = true;
logDeprecation(
'NEW_VARIABLES_RESOLVER',
'Syntax for referencing SSM parameters was upgraded with ' +
'automatic type detection ' +
'and there\'s no need to add "~true" or "~split" postfixes to variable references.\n' +
'Drop those postfixes and set "variablesResolutionMode: 20210326" in your ' +
'service config to adapt to a new behavior.\n' +
'Starting with next major release, ' +
'this will be communicated with a thrown error.\n',
{ serviceConfig: serverlessInstance.configurationInput }
);
}
address = address.slice(0, legacyInstructionSeparator);
if (instruction === 'true') legacyShouldEnforceDecrypt = true;
else if (instruction === 'split') legacyShouldEnforceSplit = true;
logDeprecation(
'NEW_VARIABLES_RESOLVER',
'Syntax for referencing SSM parameters was upgraded with ' +
'automatic type detection ' +
'and there\'s no need to add "~true" or "~split" postfixes to variable references.\n' +
'Drop those postfixes and set "variablesResolutionMode: 20210326" in your ' +
'service config to adapt to a new behavior.\n' +
'Starting with next major release, ' +
'this will be communicated with a thrown error.\n',
{ serviceConfig: serverlessInstance.configurationInput }
);
}
}
const result = await (async () => {
Expand Down
Expand Up @@ -147,6 +147,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
custom: {
existing: '${ssm:existing}',
existingWithSplit: '${ssm:existing~split}',
existingWithUnrecognized: '${ssm:existing~other}',
existingList: '${ssm:existingList}',
existingListWithSplit: '${ssm:existingList~split}',
secretManager: '${ssm:/aws/reference/secretsmanager/existing}',
Expand Down Expand Up @@ -213,6 +214,13 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
);
});

it('should ignore unrecognized legacy instructions', () => {
if (variablesMeta.get('custom\0existingWithUnrecognized')) {
throw variablesMeta.get('custom\0existing').error;
}
expect(configuration.custom.existingWithUnrecognized).to.equal('value');
});

it('should resolve existing string list param', () => {
if (variablesMeta.get('custom\0existingListWithSplit')) {
throw variablesMeta.get('custom\0existingListWithSplit').error;
Expand Down

0 comments on commit f61859f

Please sign in to comment.