Skip to content

Commit

Permalink
Test/check token (#9)
Browse files Browse the repository at this point in the history
* test: add check token job

* fix: modify the actual secret jwt name

* fix: format the check token

* fix: checkout sh file

* test: change to workflow_call

* fix: format to use workflow_call

* fix: use different variable name for broker

* fix: convert input to env in workflow_call

* fix: only pass secrets in workflow_call

* fix: secrets inherit

* fix: add secrets in workflow_call

* fix: use secrets in workflow_call

* fix: no type for secrets

* fix: use inputs and secrets directly in workflow_call

* feat: use composer to generate pipelines

* fix: remove sh script
  • Loading branch information
GraceRuan authored Jan 14, 2025
1 parent a0f2f5b commit c802f3d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ env:
SERVICE_NAME: java-maven-pipeline-example

jobs:
check_token_expiration:
uses: ./.github/workflows/check-token.yaml
secrets:
token: ${{ secrets.broker_jwt_0e727e83_f027_426a_a31c_d7c1cceaddf6 }}
build-release:
name: Build and release
runs-on: ubuntu-latest
needs: check_token_expiration
permissions:
contents: read
packages: write
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/check-token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check token expiration

on:
workflow_call:
inputs:
url:
description: "The Broker URL"
default: https://broker.io.nrs.gov.bc.ca
type: string
secrets:
token:
description: "The Broker token"
required: true

jobs:
check-jwt:
runs-on: ubuntu-latest

steps:
- name: Check token expiration
shell: bash
run: |
RESPONSE_CODE=$(curl -o /dev/null -s -w "%{http_code}" -X 'GET' \
${{ inputs.url }}/v1/health/token-check \
-H 'accept: */*' \
-H 'Authorization: Bearer '"${{ secrets.token }}"'' \
)
if [ "$RESPONSE_CODE" -eq 401 ]; then
echo "Unauthorized (401)"
exit 1
elif [ "$RESPONSE_CODE" -eq 403 ]; then
echo "Invalid JWT: Block list has match"
exit 1
else
echo "Response code: $RESPONSE_CODE"
fi
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ env:
PACKAGE_REPO: https://maven.pkg.github.com/bcgov/java-maven-pipeline-example

jobs:
check_token_expiration:
uses: ./.github/workflows/check-token.yaml
secrets:
token: ${{ secrets.broker_jwt_0e727e83_f027_426a_a31c_d7c1cceaddf6 }}
deploy-build:
name: Deploy development version
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
needs: check_token_expiration
outputs:
project_version: ${{ steps.set-build-output.outputs.project_version }}
build_guid: ${{ steps.set-build-output.outputs.build_guid }}
Expand Down Expand Up @@ -94,6 +99,7 @@ jobs:
name: Deploy release version
if: ${{ startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
needs: check_token_expiration
outputs:
project_version: ${{ steps.set-tag-output.outputs.project_version }}
build_guid: ${{ steps.set-tag-output.outputs.build_guid }}
Expand Down

0 comments on commit c802f3d

Please sign in to comment.