Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Added some error handling to the access token script, in case environ…
Browse files Browse the repository at this point in the history
…ment variables aren't set properly, so error messages are more helpful. [deploy]
  • Loading branch information
jamesmortensen committed Apr 12, 2022
1 parent 2f65fc3 commit a8ba0af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions get-access-token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 2 additions & 2 deletions get-access-token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a8ba0af

Please sign in to comment.