From a8ba0af96079f5379e274b8fe7c582b8d2d9fa46 Mon Sep 17 00:00:00 2001 From: James Mortensen Date: Tue, 12 Apr 2022 22:18:08 +0530 Subject: [PATCH] Added some error handling to the access token script, in case environment variables aren't set properly, so error messages are more helpful. [deploy] --- .circleci/config.yml | 2 +- get-access-token.py | 8 ++++++++ get-access-token.sh | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index edd16d77d..856973a8d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -187,7 +187,7 @@ jobs: - run: name: "Check if branch is deployable (contains [deploy] in commit msg on $DEPLOY_BRANCH" command: | - export CI_DEPLOY=`git log --format=oneline -n 1 | grep '\[deploy\]'` && echo $CI_DEPLOY + export CI_DEPLOY=`git log --format=oneline -n 1 | grep '\[deploy\]'` && echo "$CI_DEPLOY" if [ -z "$CI_DEPLOY" ] || [ "$CIRCLE_BRANCH" != "$DEPLOY_BRANCH" ]; then echo "Cancelling run. Pass [deploy] in commit message on $DEPLOY_BRANCH to deploy" circleci-agent step halt diff --git a/get-access-token.py b/get-access-token.py index 1eb541045..630783bf6 100644 --- a/get-access-token.py +++ b/get-access-token.py @@ -10,6 +10,14 @@ private_key = os.environ.get('GITHUB_APP_PEM') private_key = private_key.replace("\\n", "\n") +standard_error_msg = 'Seleniarm GitHub App installation environment variables are not set. ' +if github_app_id == '': + raise Exception(standard_error_msg + 'Valid GITHUB_APP_ID is required to obtain an access token.') +if github_installation_id == '': + raise Exception(standard_error_msg + 'Valid GITHUB_INSTALLATION_ID is required to obtain an access token.') +if private_key == '': + raise Exception(standard_error_msg + 'Valid GITHUB_APP_PEM token is required to obtain an access token.') + time_since_epoch_in_seconds = int(time.time()) diff --git a/get-access-token.sh b/get-access-token.sh index 6115747e7..3fc7c6daa 100644 --- a/get-access-token.sh +++ b/get-access-token.sh @@ -11,8 +11,8 @@ pip3 install cryptography pip3 install requests pip3 install PyJWT -export GITHUB_APP_ID=$SELENIARM_GITHUB_APP_ID -export GITHUB_INSTALLATION_ID=$SELENIARM_GITHUB_INSTALLATION_ID +export GITHUB_APP_ID="$SELENIARM_GITHUB_APP_ID" +export GITHUB_INSTALLATION_ID="$SELENIARM_GITHUB_INSTALLATION_ID" export GITHUB_APP_PEM="$SELENIARM_GITHUB_APP_PEM" python3 get-access-token.py