From f61859fd25908b13b6d9638c550e88ef4a08392e Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 14 Jun 2021 12:14:10 +0200 Subject: [PATCH] fix(Variables): Strip unrecognized legacy instructions --- .../sources/instance-dependent/get-ssm.js | 32 ++++++++----------- .../instance-dependent/get-ssm.test.js | 8 +++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/configuration/variables/sources/instance-dependent/get-ssm.js b/lib/configuration/variables/sources/instance-dependent/get-ssm.js index 4eefc448446..b7c58148ff7 100644 --- a/lib/configuration/variables/sources/instance-dependent/get-ssm.js +++ b/lib/configuration/variables/sources/instance-dependent/get-ssm.js @@ -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 }) => { @@ -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 () => { diff --git a/test/unit/lib/configuration/variables/sources/instance-dependent/get-ssm.test.js b/test/unit/lib/configuration/variables/sources/instance-dependent/get-ssm.test.js index 39f93cfeb10..9d13197af39 100644 --- a/test/unit/lib/configuration/variables/sources/instance-dependent/get-ssm.test.js +++ b/test/unit/lib/configuration/variables/sources/instance-dependent/get-ssm.test.js @@ -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}', @@ -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;