This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to dispatch dbt tests after sqoop import (#5)
* Add crawler trigger to run.sh * Add initial scripts for dispatching GH workflows * Update example .env file * Fix small bash quoting issues * Fix Glue crawler name * Add logging messages in dispatch script
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ IPTS_HOSTNAME= | |
IPTS_PORT= | ||
IPTS_SERVICE_NAME= | ||
IPTS_USERNAME= | ||
GH_APP_ID= | ||
GH_PEM_PATH= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
GH_API_REPO="https://api.github.com/repos/ccao-data/data-architecture" | ||
GH_DBT_WORKFLOW="test_dbt_models.yaml" | ||
|
||
# First auth as a GitHub app using JSON Web Token (JWT). | ||
# Uses a local PEM file and python lib to construct the JWT | ||
echo "Generating JWT to send to GitHub auth" | ||
GH_JWT=$(python3 scripts/get-jwt.py) | ||
|
||
# Grab the token URL from our current installation | ||
echo "Fetching GitHub tokens URL" | ||
GH_TOKENS_URL=$(curl -s --request GET \ | ||
--url "https://api.github.com/app/installations" \ | ||
--header "Accept: application/vnd.github+json" \ | ||
--header "Authorization: Bearer ${GH_JWT}" \ | ||
--header "X-GitHub-Api-Version: 2022-11-28" \ | ||
| jq -r '.[].access_tokens_url') | ||
|
||
# Auth against the tokens URL to get a short-lived (60 second) token | ||
echo "Fetching temporary GitHub auth token" | ||
GH_TOKEN=$(curl -s -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${GH_JWT}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"$GH_TOKENS_URL" \ | ||
| jq -r '.token') | ||
|
||
# Use the token to call the API and dispatch the workflow | ||
echo "Dispatching workflow" | ||
curl -v -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${GH_TOKEN}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"$GH_API_REPO"/actions/workflows/"$GH_DBT_WORKFLOW"/dispatches \ | ||
-d '{"ref": "master"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
import jwt | ||
import os | ||
import time | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
GH_APP_ID = os.getenv("GH_APP_ID") | ||
GH_PEM_PATH = os.getenv("GH_PEM_PATH") | ||
|
||
with open(GH_PEM_PATH, "rb") as pem_file: | ||
signing_key = jwt.jwk_from_pem(pem_file.read()) | ||
|
||
payload = { | ||
"iat": int(time.time()), | ||
"exp": int(time.time()) + 60, | ||
"iss": GH_APP_ID | ||
} | ||
|
||
jwt_instance = jwt.JWT() | ||
encoded_jwt = jwt_instance.encode(payload, signing_key, alg="RS256") | ||
print(encoded_jwt) |