Skip to content

Commit

Permalink
Refactor: use cal-itp/littlepay to check API access (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Feb 14, 2024
2 parents 0a744c3 + df25d78 commit 493a7ec
Showing 1 changed file with 16 additions and 58 deletions.
74 changes: 16 additions & 58 deletions .github/workflows/check-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,39 @@ name: Check access to API

on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Select the API environment
options: [all, prod, qa]
schedule:
- cron: "0 12 * * *"

jobs:
check-api:
runs-on: ubuntu-latest
env:
SHOULD_RUN: |
${{ github.event_name == 'schedule'
|| github.event.inputs.environment == 'all'
|| github.event.inputs.environment == matrix.name
}}
strategy:
fail-fast: false
matrix:
include:
- name: prod
cert: API_CHECK_PROD_CERT
key: API_CHECK_PROD_KEY
ca-cert: API_CHECK_PROD_CA_CERT
url: API_CHECK_PROD_URL
data: API_CHECK_PROD_DATA

- name: qa
cert: API_CHECK_QA_CERT
key: API_CHECK_QA_KEY
ca-cert: API_CHECK_QA_CA_CERT
url: API_CHECK_QA_URL
data: API_CHECK_QA_DATA

name: Check API endpoint (${{ matrix.name }})
participant: [mst, sacrt, sbmtd]
env: [qa, prod]
steps:
- name: Echo workflow run information
run: |
echo "Triggering event name: ${{ github.event_name }}, \
APIs to check: ${{ github.event.inputs.environment }}"
- uses: actions/checkout@v4
with:
repository: "cal-itp/littlepay"

- name: Decode cert files
if: contains(env.SHOULD_RUN, 'true')
- name: Install the littlepay library
run: |
mkdir $RUNNER_TEMP/${{ matrix.name }}
temp_dir=$RUNNER_TEMP/${{ matrix.name }}
cat > $temp_dir/cert.pem <<- EOM
${{ secrets[matrix.cert] }}
EOM
cat > $temp_dir/key.pem <<- EOM
${{ secrets[matrix.key] }}
EOM
python3 -m pip install --upgrade pip
pip install -e .
cat > $temp_dir/cacert.ca <<- EOM
${{ secrets[matrix.ca-cert] }}
- name: Create config file and set config
run: |
cat > config.yaml <<- EOM
${{ secrets.API_CHECK_CONFIG }}
EOM
littlepay config config.yaml
- name: Call API endpoint
if: contains(env.SHOULD_RUN, 'true')
- name: Run littlepay to get access token
run: |
temp_dir=$RUNNER_TEMP/${{ matrix.name }}
curl -i --url ${{ secrets[matrix.url] }} \
--header 'Accept: application/json' \
--header 'Content-type: application/json' \
--data '${{ secrets[matrix.data] }}' \
--cert $temp_dir/cert.pem \
--key $temp_dir/key.pem \
--cacert $temp_dir/cacert.ca > $temp_dir/payload.txt
test $(head -n 1 $temp_dir/payload.txt | grep -o 201)
littlepay switch env ${{ matrix.env }}
littlepay switch participant ${{ matrix.participant }}
# https://www.ravsam.in/blog/send-slack-notification-when-github-actions-fails/#using-notify-slack-action
- name: Report failure to Slack
if: always()
uses: ravsamhq/notify-slack-action@v2
Expand Down

0 comments on commit 493a7ec

Please sign in to comment.