From 8e2467c047ba5a4f57f37b6c3e1e58897d884453 Mon Sep 17 00:00:00 2001 From: Junya Date: Sun, 9 Feb 2025 04:32:37 +0900 Subject: [PATCH] fix: separate envFiles and secrets condition checks to avoid unintended nesting --- dist/index.js | 74 +++++++++++++++++++++++++-------------------------- index.js | 72 ++++++++++++++++++++++++------------------------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5ece815a..da0b8a7b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -142,45 +142,45 @@ async function run() { containerDef.environment.push(variable); } }) + } - if (secrets) { - // If secrets array is missing, create it - if (!Array.isArray(containerDef.secrets)) { - containerDef.secrets = []; - } - - // Get pairs by splitting on newlines - secrets.split('\n').forEach(function (line) { - // Trim whitespace - const trimmedLine = line.trim(); - // Skip if empty - if (trimmedLine.length === 0) { return; } - // Split on = - const separatorIdx = trimmedLine.indexOf("="); - // If there's nowhere to split - if (separatorIdx === -1) { - throw new Error( - `Cannot parse the secret '${trimmedLine}'. Secret pairs must be of the form NAME=valueFrom, - where valueFrom is an arn from parameter store or secrets manager. See AWS documentation for more information: - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html.`); - } - // Build object - const secret = { - name: trimmedLine.substring(0, separatorIdx), - valueFrom: trimmedLine.substring(separatorIdx + 1), - }; - - // Search container definition environment for one matching name - const secretDef = containerDef.secrets.find((s) => s.name == secret.name); - if (secretDef) { - // If found, update - secretDef.valueFrom = secret.valueFrom; - } else { - // Else, create - containerDef.secrets.push(secret); - } - }) + if (secrets) { + // If secrets array is missing, create it + if (!Array.isArray(containerDef.secrets)) { + containerDef.secrets = []; } + + // Get pairs by splitting on newlines + secrets.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Split on = + const separatorIdx = trimmedLine.indexOf("="); + // If there's nowhere to split + if (separatorIdx === -1) { + throw new Error( + `Cannot parse the secret '${trimmedLine}'. Secret pairs must be of the form NAME=valueFrom, + where valueFrom is an arn from parameter store or secrets manager. See AWS documentation for more information: + https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html.`); + } + // Build object + const secret = { + name: trimmedLine.substring(0, separatorIdx), + valueFrom: trimmedLine.substring(separatorIdx + 1), + }; + + // Search container definition environment for one matching name + const secretDef = containerDef.secrets.find((s) => s.name == secret.name); + if (secretDef) { + // If found, update + secretDef.valueFrom = secret.valueFrom; + } else { + // Else, create + containerDef.secrets.push(secret); + } + }) } if (logConfigurationLogDriver) { diff --git a/index.js b/index.js index 95467f9b..a349abbf 100644 --- a/index.js +++ b/index.js @@ -136,45 +136,45 @@ async function run() { containerDef.environment.push(variable); } }) + } + + if (secrets) { + // If secrets array is missing, create it + if (!Array.isArray(containerDef.secrets)) { + containerDef.secrets = []; + } - if (secrets) { - // If secrets array is missing, create it - if (!Array.isArray(containerDef.secrets)) { - containerDef.secrets = []; + // Get pairs by splitting on newlines + secrets.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Split on = + const separatorIdx = trimmedLine.indexOf("="); + // If there's nowhere to split + if (separatorIdx === -1) { + throw new Error( + `Cannot parse the secret '${trimmedLine}'. Secret pairs must be of the form NAME=valueFrom, + where valueFrom is an arn from parameter store or secrets manager. See AWS documentation for more information: + https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html.`); } + // Build object + const secret = { + name: trimmedLine.substring(0, separatorIdx), + valueFrom: trimmedLine.substring(separatorIdx + 1), + }; - // Get pairs by splitting on newlines - secrets.split('\n').forEach(function (line) { - // Trim whitespace - const trimmedLine = line.trim(); - // Skip if empty - if (trimmedLine.length === 0) { return; } - // Split on = - const separatorIdx = trimmedLine.indexOf("="); - // If there's nowhere to split - if (separatorIdx === -1) { - throw new Error( - `Cannot parse the secret '${trimmedLine}'. Secret pairs must be of the form NAME=valueFrom, - where valueFrom is an arn from parameter store or secrets manager. See AWS documentation for more information: - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html.`); - } - // Build object - const secret = { - name: trimmedLine.substring(0, separatorIdx), - valueFrom: trimmedLine.substring(separatorIdx + 1), - }; - - // Search container definition environment for one matching name - const secretDef = containerDef.secrets.find((s) => s.name == secret.name); - if (secretDef) { - // If found, update - secretDef.valueFrom = secret.valueFrom; - } else { - // Else, create - containerDef.secrets.push(secret); - } - }) - } + // Search container definition environment for one matching name + const secretDef = containerDef.secrets.find((s) => s.name == secret.name); + if (secretDef) { + // If found, update + secretDef.valueFrom = secret.valueFrom; + } else { + // Else, create + containerDef.secrets.push(secret); + } + }) } if (logConfigurationLogDriver) {