From 91299ec3e70864935d3e8481e6ba1ac6a120ec92 Mon Sep 17 00:00:00 2001 From: Nathaniel Ram <1310137+nathanielram@users.noreply.github.com> Date: Tue, 16 Nov 2021 15:41:58 -0500 Subject: [PATCH] Updated ignored task definition attributes and some validation --- dist/index.js | 37 +++++++++++++++++++++++++++++++++++-- index.js | 37 +++++++++++++++++++++++++++++++++++-- package-lock.json | 16 ++++++++++++---- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2e70b39dc..cd98f0dd8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -143,7 +143,10 @@ const IGNORED_TASK_DEFINITION_ATTRIBUTES = [ 'taskDefinitionArn', 'requiresAttributes', 'revision', - 'status' + 'status', + 'registeredAt', + 'deregisteredAt', + 'registeredBy' ]; const WAIT_DEFAULT_DELAY_SEC = 5; @@ -209,6 +212,36 @@ function removeIgnoredAttributes(taskDef) { return taskDef; } +function maintainValidObjects(taskDef) { + if (validateProxyConfigurations(taskDef)) { + taskDef.proxyConfiguration.properties.forEach((property, index, arr) => { + if (!('value' in property)) { + arr[index].value = ''; + } + if (!('name' in property)) { + arr[index].name = ''; + } + }); + } + + if(taskDef && taskDef.containerDefinitions){ + taskDef.containerDefinitions.forEach((container) => { + if(container.environment){ + container.environment.forEach((property, index, arr) => { + if (!('value' in property)) { + arr[index].value = ''; + } + }); + } + }); + } + return taskDef; +} + +function validateProxyConfigurations(taskDef){ + return 'proxyConfiguration' in taskDef && taskDef.proxyConfiguration.type && taskDef.proxyConfiguration.type == 'APPMESH' && taskDef.proxyConfiguration.properties && taskDef.proxyConfiguration.properties.length > 0; +} + async function run() { try { const agent = 'amazon-ecs-run-task-for-github-actions' @@ -234,7 +267,7 @@ async function run() { taskDefinitionFile : path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile); const fileContents = fs.readFileSync(taskDefPath, 'utf8'); - const taskDefContents = removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))); + const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents)))); let registerResponse; try { diff --git a/index.js b/index.js index b07b6f216..f3d27d603 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,10 @@ const IGNORED_TASK_DEFINITION_ATTRIBUTES = [ 'taskDefinitionArn', 'requiresAttributes', 'revision', - 'status' + 'status', + 'registeredAt', + 'deregisteredAt', + 'registeredBy' ]; const WAIT_DEFAULT_DELAY_SEC = 5; @@ -76,6 +79,36 @@ function removeIgnoredAttributes(taskDef) { return taskDef; } +function maintainValidObjects(taskDef) { + if (validateProxyConfigurations(taskDef)) { + taskDef.proxyConfiguration.properties.forEach((property, index, arr) => { + if (!('value' in property)) { + arr[index].value = ''; + } + if (!('name' in property)) { + arr[index].name = ''; + } + }); + } + + if(taskDef && taskDef.containerDefinitions){ + taskDef.containerDefinitions.forEach((container) => { + if(container.environment){ + container.environment.forEach((property, index, arr) => { + if (!('value' in property)) { + arr[index].value = ''; + } + }); + } + }); + } + return taskDef; +} + +function validateProxyConfigurations(taskDef){ + return 'proxyConfiguration' in taskDef && taskDef.proxyConfiguration.type && taskDef.proxyConfiguration.type == 'APPMESH' && taskDef.proxyConfiguration.properties && taskDef.proxyConfiguration.properties.length > 0; +} + async function run() { try { const agent = 'amazon-ecs-run-task-for-github-actions' @@ -101,7 +134,7 @@ async function run() { taskDefinitionFile : path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile); const fileContents = fs.readFileSync(taskDefPath, 'utf8'); - const taskDefContents = removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))); + const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents)))); let registerResponse; try { diff --git a/package-lock.json b/package-lock.json index 87aa11f02..bf9d7633b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2611,7 +2611,8 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", - "dev": true + "dev": true, + "optional": true }, "har-schema": { "version": "2.0.0", @@ -2977,6 +2978,7 @@ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", "dev": true, + "optional": true, "requires": { "is-docker": "^2.0.0" } @@ -4519,6 +4521,7 @@ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, + "optional": true, "requires": { "yallist": "^4.0.0" } @@ -4700,6 +4703,7 @@ "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", "integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==", "dev": true, + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -4714,6 +4718,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", "dev": true, + "optional": true, "requires": { "lru-cache": "^6.0.0" } @@ -5513,7 +5518,8 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", - "dev": true + "dev": true, + "optional": true }, "signal-exit": { "version": "3.0.3", @@ -6215,7 +6221,8 @@ "version": "8.3.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz", "integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==", - "dev": true + "dev": true, + "optional": true }, "v8-compile-cache": { "version": "2.1.1", @@ -6450,7 +6457,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "dev": true, + "optional": true }, "yaml": { "version": "1.10.0",