From d35205081fbf6f33cd536ea4962ca09ef96eb123 Mon Sep 17 00:00:00 2001 From: Oryan Moshe Date: Wed, 4 Mar 2020 21:10:22 +0200 Subject: [PATCH] Checking default AWS env var --- action.yml | 33 +++++++++++++++------------------ dist/index.js | 16 +++++++++++++--- src/index.js | 16 +++++++++++++--- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/action.yml b/action.yml index e61e542..c23b53c 100644 --- a/action.yml +++ b/action.yml @@ -1,35 +1,32 @@ -name: "ECS Wait" -author: "Oryan Moshe" -description: "Waits for ECS service stability" +name: 'ECS Wait' +author: 'Oryan Moshe' +description: 'Waits for ECS service stability' inputs: retries: - description: "How many times to retry the 10 minute wait (integer)" + description: 'How many times to retry the 10 minute wait (integer)' required: true default: 2 aws-access-key-id: - description: "The AWS_ACCESS_KEY_ID (string)" - required: true + description: 'The AWS_ACCESS_KEY_ID (string)' aws-secret-access-key: - description: "The AWS_SECRET_ACCESS_KEY (string)" - required: true + description: 'The AWS_SECRET_ACCESS_KEY (string)' aws-region: - description: "The AWS_REGION (string)" - required: true + description: 'The AWS_REGION (string)' ecs-cluster: - description: "The ECS cluster name (string)" + description: 'The ECS cluster name (string)' required: true ecs-services: - description: "List of ECS services to wait for (string[])" + description: 'List of ECS services to wait for (string[])' required: true verbose: - description: "Whether to print the retry log (bool)" + description: 'Whether to print the retry log (bool)' default: false outputs: retries: - description: "How many retries happened until success (integer)" + description: 'How many retries happened until success (integer)' runs: - using: "node12" - main: "dist/index.js" + using: 'node12' + main: 'dist/index.js' branding: - icon: "clock" - color: "purple" + icon: 'clock' + color: 'purple' diff --git a/dist/index.js b/dist/index.js index 17a14f2..24cb92e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5702,15 +5702,25 @@ const createEcsConnection = ({ accessKeyId, secretAccessKey, region }) => const main = async () => { try { const params = { - accessKeyId: core.getInput('aws-access-key-id'), - secretAccessKey: core.getInput('aws-secret-access-key'), - region: core.getInput('aws-region'), + accessKeyId: + core.getInput('aws-access-key-id') || process.env.AWS_ACCESS_KEY_ID, + secretAccessKey: + core.getInput('aws-secret-access-key') || + process.env.AWS_SECRET_ACCESS_KEY, + region: core.getInput('aws-region') || process.env.AWS_REGION, retries: parseInt(core.getInput('retries'), 10), cluster: core.getInput('ecs-cluster'), services: JSON.parse(core.getInput('ecs-services')), verbose: core.getInput('verbose') === 'true', }; + if (!params.accessKeyId || !params.secretAccessKey || !params.region) { + core.setFailed( + 'AWS credentials were not found in inputs or environment variables.' + ); + return; + } + const ecsConnection = createEcsConnection(params); params['ecsConnection'] = ecsConnection; diff --git a/src/index.js b/src/index.js index 4403e40..ff783e1 100644 --- a/src/index.js +++ b/src/index.js @@ -64,15 +64,25 @@ const createEcsConnection = ({ accessKeyId, secretAccessKey, region }) => const main = async () => { try { const params = { - accessKeyId: core.getInput('aws-access-key-id'), - secretAccessKey: core.getInput('aws-secret-access-key'), - region: core.getInput('aws-region'), + accessKeyId: + core.getInput('aws-access-key-id') || process.env.AWS_ACCESS_KEY_ID, + secretAccessKey: + core.getInput('aws-secret-access-key') || + process.env.AWS_SECRET_ACCESS_KEY, + region: core.getInput('aws-region') || process.env.AWS_REGION, retries: parseInt(core.getInput('retries'), 10), cluster: core.getInput('ecs-cluster'), services: JSON.parse(core.getInput('ecs-services')), verbose: core.getInput('verbose') === 'true', }; + if (!params.accessKeyId || !params.secretAccessKey || !params.region) { + core.setFailed( + 'AWS credentials were not found in inputs or environment variables.' + ); + return; + } + const ecsConnection = createEcsConnection(params); params['ecsConnection'] = ecsConnection;