Skip to content

Commit

Permalink
Add reusable workflows for repo-auth-client.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rj1k committed Jul 11, 2024
1 parent 2c97bcb commit 5fef342
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/actions/repo-auth-client-nonce/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Repository AUTH client Nonce

inputs:
domain:
required: false
default: 'repo-auth-service.freeswitch.org'
description: Domain of AUTH service
outputs:
nonce:
description: Nonce value from AUTH service
value: ${{ steps.get-nonce.outputs.nonce }}

runs:
using: "composite"
steps:
- name: Get Nonce
id: get-nonce
shell: python
run: |
import requests
from requests.adapters import HTTPAdapter, Retry
from urllib.parse import urlencode
import sys
import os
def create_https_session_with_retries(
retries=5, backoff_factor=1.0, status_forcelist=(500, 502, 504, 400, 403, 404)
):
session = requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("https://", adapter)
return session
def GET(url, session):
response = session.get(url)
response.raise_for_status()
return response.text.strip()
session = create_https_session_with_retries()
try:
nonce = GET(
f"https://${{ inputs.domain }}/?auth=1", session
)
with open(os.getenv('GITHUB_OUTPUT'), 'a') as f:
f.write(f'nonce={nonce}\n')
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
sys.exit(1)
57 changes: 57 additions & 0 deletions .github/actions/repo-auth-client-token/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Repository AUTH client Token

inputs:
domain:
required: false
default: 'repo-auth-service.freeswitch.org'
description: Domain of AUTH service
outputs:
token:
description: Token value from AUTH service
value: ${{ steps.get-token.outputs.token }}

runs:
using: "composite"
steps:
- name: Get Token
id: get-token
shell: python
run: |
import requests
from requests.adapters import HTTPAdapter, Retry
from urllib.parse import urlencode
import sys
import os
def create_https_session_with_retries(
retries=5, backoff_factor=1.0, status_forcelist=(500, 502, 504, 400, 403, 404)
):
session = requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("https://", adapter)
return session
def GET(url, session):
response = session.get(url)
response.raise_for_status()
return response.text.strip()
session = create_https_session_with_retries()
try:
token = GET(
f'https://${{ inputs.domain }}/?{urlencode({"verify": "${{ env.NONCE }}"})}', session
)
with open(os.getenv('GITHUB_OUTPUT'), 'a') as f:
f.write(f'token={token}\n')
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
sys.exit(1)

0 comments on commit 5fef342

Please sign in to comment.