Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use cal-itp/littlepay to check API access #1889

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading