From 0178e025a426114e67408a01fc134a2b48bcf236 Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Fri, 26 Jan 2024 15:36:35 +0000 Subject: [PATCH 1/3] fix: logical error with assigning gov pay secret --- infrastructure/application/utils/generateTeamSecrets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/application/utils/generateTeamSecrets.ts b/infrastructure/application/utils/generateTeamSecrets.ts index 7bb906cc51..0918a88850 100644 --- a/infrastructure/application/utils/generateTeamSecrets.ts +++ b/infrastructure/application/utils/generateTeamSecrets.ts @@ -25,7 +25,7 @@ export const generateTeamSecrets = ( ): awsx.ecs.KeyValuePair[] => { const secrets: awsx.ecs.KeyValuePair[] = []; teams.forEach((team) => { - if (team?.govPayStagingOnly && env !== "production") { + if ((team?.govPayStagingOnly && env !== "production") || !team?.govPayStagingOnly) { secrets.push({ name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, value: From 2e1d61dfc09ef227903ff8f5450d0af322491cde Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Fri, 26 Jan 2024 15:47:15 +0000 Subject: [PATCH 2/3] refactor: use Daf's switch statement for readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adds a switch statement with a case for each environment - Improves comprehensibility Co-authored-by: Dafydd Llŷr Pearson --- .../application/utils/generateTeamSecrets.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/infrastructure/application/utils/generateTeamSecrets.ts b/infrastructure/application/utils/generateTeamSecrets.ts index 0918a88850..2720482139 100644 --- a/infrastructure/application/utils/generateTeamSecrets.ts +++ b/infrastructure/application/utils/generateTeamSecrets.ts @@ -25,15 +25,27 @@ export const generateTeamSecrets = ( ): awsx.ecs.KeyValuePair[] => { const secrets: awsx.ecs.KeyValuePair[] = []; teams.forEach((team) => { - if ((team?.govPayStagingOnly && env !== "production") || !team?.govPayStagingOnly) { - secrets.push({ - name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, - value: - env === "sandbox" - ? "sandbox" - : config.require(`gov-uk-pay-token-${value(team.name)}`), - }); - } + switch(env) { + case "sandbox": + secrets.push({ + name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, + value: "sandbox" + }); + break; + case "staging": + secrets.push({ + name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, + value: config.require(`gov-uk-pay-token-${value(team.name)}`), + }); + break; + case "production": + if (!team.govPayStagingOnly) { + secrets.push({ + name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, + value: config.require(`gov-uk-pay-token-${value(team.name)}`), + }); + } + }; team.uniformInstances?.forEach((instance) => { secrets.push({ name: `UNIFORM_CLIENT_${name(instance)}`, From 12149f5e8b2b304479cb8bfd04eb891dc3799dde Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Fri, 26 Jan 2024 16:24:28 +0000 Subject: [PATCH 3/3] fix: add safe key access --- infrastructure/application/utils/generateTeamSecrets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/application/utils/generateTeamSecrets.ts b/infrastructure/application/utils/generateTeamSecrets.ts index 2720482139..702f184e14 100644 --- a/infrastructure/application/utils/generateTeamSecrets.ts +++ b/infrastructure/application/utils/generateTeamSecrets.ts @@ -39,7 +39,7 @@ export const generateTeamSecrets = ( }); break; case "production": - if (!team.govPayStagingOnly) { + if (!team?.govPayStagingOnly) { secrets.push({ name: `GOV_UK_PAY_TOKEN_${name(team.name)}`, value: config.require(`gov-uk-pay-token-${value(team.name)}`),