-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jlantz/update-auth-structure' into jlantz/refactor-pyda…
…ntic-models
- Loading branch information
Showing
23 changed files
with
733 additions
and
87 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Delete Org Session | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment_name: | ||
description: "The name of the GitHub Environment to delete the org session from" | ||
required: true | ||
type: string | ||
github_auth_environment: | ||
description: "The name of the GitHub Environment to get the GitHub Access token from" | ||
required: true | ||
type: string | ||
secrets: | ||
github-token: | ||
required: true | ||
|
||
jobs: | ||
delete-org-session: | ||
name: "Delete Org Session" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get GitHub Access Token | ||
run: | | ||
echo "Retrieving GitHub Access Token from environment: ${{ inputs.github_auth_environment }}" | ||
GITHUB_ACCESS_TOKEN=$(gh api \ | ||
-H "Authorization: token ${{ secrets.github-token }}" \ | ||
"/repos/${{ github.repository }}/environments/${{ inputs.github_auth_environment }}/variables/GITHUB_ACCESS_TOKEN" \ | ||
| jq -r '.value') | ||
echo "GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN}" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Delete Org Session | ||
run: | | ||
echo "Deleting org session from environment: ${{ inputs.environment_name }}" | ||
gh api \ | ||
-X DELETE \ | ||
-H "Authorization: token ${{ env.GITHUB_ACCESS_TOKEN }}" \ | ||
"/repos/${{ github.repository }}/environments/${{ inputs.environment_name }}/variables/ACCESS_TOKEN" | ||
shell: bash | ||
|
||
- name: Add Job Summary | ||
run: | | ||
echo "## Org Session Deletion Summary" >> $GITHUB_STEP_SUMMARY | ||
echo "Environment: ${{ inputs.environment_name }}" >> $GITHUB_STEP_SUMMARY | ||
echo "Status: Org session deleted successfully" >> $GITHUB_STEP_SUMMARY | ||
shell: bash |
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,35 @@ | ||
name: Test GitHub Auth | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**" | ||
|
||
jobs: | ||
test-github-auth: | ||
runs-on: ubuntu-latest | ||
environment: test | ||
container: | ||
image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots | ||
options: --user root | ||
credentials: | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.github-token }} | ||
env: | ||
DEV_HUB_AUTH_URL: "${{ secrets.dev-hub-auth-url }}" | ||
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }' | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Auth to DevHub | ||
run: /usr/local/bin/devhub.sh | ||
- name: Test GitHub Auth | ||
run: | | ||
d2x auth url | ||
d2x auth login | ||
shell: bash | ||
- name: Record API Requests | ||
run: | | ||
pip install vcrpy | ||
vcrpy --record-mode=once --filter-headers Authorization --filter-headers X-Auth-Token --filter-headers X-API-Key | ||
shell: bash |
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 @@ | ||
# d2x.api module |
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,91 @@ | ||
import os | ||
import requests | ||
|
||
GITHUB_REPO = os.environ.get("GITHUB_REPOSITORY") | ||
|
||
|
||
def get_github_token() -> str: | ||
"""Get the GitHub token from the environment""" | ||
token = os.environ.get("GITHUB_TOKEN") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable not set") | ||
return token | ||
|
||
|
||
def get_repo_full_name() -> str: | ||
"""Get the full name of the GitHub repository""" | ||
repo = os.environ.get("GITHUB_REPOSITORY") | ||
if not repo: | ||
raise ValueError("GITHUB_REPOSITORY environment variable not set") | ||
return repo | ||
|
||
|
||
def set_environment_variable(env_name: str, var_name: str, var_value: str) -> None: | ||
"""Set a variable in a GitHub Environment""" | ||
token = os.environ.get("GITHUB_TOKEN") | ||
repo = os.environ.get("GITHUB_REPOSITORY") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable not set") | ||
|
||
url = f"https://api.github.com/repos/{GITHUB_REPO}/environments/{env_name}/variables/{var_name}" | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
data = {"name": var_name, "value": var_value} | ||
|
||
response = requests.put(url, headers=headers, json=data) | ||
response.raise_for_status() | ||
|
||
|
||
def get_environment_variable(env_name: str, var_name: str) -> str: | ||
"""Get a variable from a GitHub Environment""" | ||
token = os.environ.get("GITHUB_TOKEN") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable not set") | ||
|
||
url = f"https://api.github.com/repos/{GITHUB_REPO}/environments/{env_name}/variables/{var_name}" | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
|
||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
|
||
return response.json()["value"] | ||
|
||
|
||
def set_environment_secret(env_name: str, secret_name: str, secret_value: str) -> None: | ||
"""Set a secret in a GitHub Environment""" | ||
token = os.environ.get("GITHUB_TOKEN") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable not set") | ||
|
||
url = f"https://api.github.com/repos/{GITHUB_REPO}/environments/{env_name}/secrets/{secret_name}" | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
data = {"encrypted_value": secret_value} | ||
|
||
response = requests.put(url, headers=headers, json=data) | ||
response.raise_for_status() | ||
|
||
|
||
def get_environment_secret(env_name: str, secret_name: str) -> str: | ||
"""Get a secret from a GitHub Environment""" | ||
token = os.environ.get("GITHUB_TOKEN") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable not set") | ||
|
||
url = f"https://api.github.com/repos/{GITHUB_REPO}/environments/{env_name}/secrets/{secret_name}" | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
|
||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
|
||
return response.json()["encrypted_value"] |
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 |
---|---|---|
@@ -1 +1 @@ | ||
# ...existing code or leave empty... | ||
# This is the __init__.py file for the d2x.auth.sf module. |
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
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 @@ | ||
# d2x.base |
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
Oops, something went wrong.