|
| 1 | +name: Repository AUTH client |
| 2 | + |
| 3 | +inputs: |
| 4 | + domain: |
| 5 | + required: false |
| 6 | + default: 'repo-auth-service.freeswitch.org' |
| 7 | + description: Domain of AUTH service |
| 8 | + mode: |
| 9 | + required: true |
| 10 | + description: Mode of operation |
| 11 | + type: choice |
| 12 | + options: |
| 13 | + - nonce |
| 14 | + - issue |
| 15 | + - revoke |
| 16 | +outputs: |
| 17 | + nonce: |
| 18 | + description: Nonce value from AUTH service (only available in nonce mode) |
| 19 | + value: ${{ steps.get-nonce.outputs.nonce || '' }} |
| 20 | + token: |
| 21 | + description: Token value from AUTH service (only available in issue mode) |
| 22 | + value: ${{ steps.issue-token.outputs.token || '' }} |
| 23 | + |
| 24 | +runs: |
| 25 | + using: "composite" |
| 26 | + steps: |
| 27 | + - name: Get Nonce |
| 28 | + if: inputs.mode == 'nonce' |
| 29 | + id: get-nonce |
| 30 | + shell: python |
| 31 | + run: | |
| 32 | + import os |
| 33 | + import requests |
| 34 | + import sys |
| 35 | + from requests.adapters import HTTPAdapter, Retry |
| 36 | + from urllib.parse import urlencode |
| 37 | +
|
| 38 | + def create_https_session_with_retries( |
| 39 | + retries=5, backoff_factor=1.0, status_forcelist=(500, 502, 504, 400, 403, 404) |
| 40 | + ): |
| 41 | + session = requests.Session() |
| 42 | + retry = Retry( |
| 43 | + total=retries, |
| 44 | + read=retries, |
| 45 | + connect=retries, |
| 46 | + backoff_factor=backoff_factor, |
| 47 | + status_forcelist=status_forcelist, |
| 48 | + ) |
| 49 | + adapter = HTTPAdapter(max_retries=retry) |
| 50 | + session.mount("https://", adapter) |
| 51 | + return session |
| 52 | +
|
| 53 | + def GET(url, session): |
| 54 | + response = session.get(url) |
| 55 | + response.raise_for_status() |
| 56 | + return response.text.strip() |
| 57 | +
|
| 58 | + session = create_https_session_with_retries() |
| 59 | +
|
| 60 | + try: |
| 61 | + nonce = GET( |
| 62 | + f"https://${{ inputs.domain }}/auth.php", session |
| 63 | + ) |
| 64 | +
|
| 65 | + with open(os.getenv('GITHUB_OUTPUT'), 'a') as f: |
| 66 | + f.write(f'nonce={nonce}\n') |
| 67 | + except Exception as e: |
| 68 | + print(f"An error occurred: {e}") |
| 69 | + sys.exit(1) |
| 70 | +
|
| 71 | + - name: Issue Token |
| 72 | + if: inputs.mode == 'issue' |
| 73 | + id: issue-token |
| 74 | + shell: python |
| 75 | + run: | |
| 76 | + import os |
| 77 | + import requests |
| 78 | + import sys |
| 79 | + from requests.adapters import HTTPAdapter, Retry |
| 80 | + from urllib.parse import urlencode |
| 81 | +
|
| 82 | + def create_https_session_with_retries( |
| 83 | + retries=5, backoff_factor=1.0, status_forcelist=(500, 502, 504, 400, 403, 404) |
| 84 | + ): |
| 85 | + session = requests.Session() |
| 86 | + retry = Retry( |
| 87 | + total=retries, |
| 88 | + read=retries, |
| 89 | + connect=retries, |
| 90 | + backoff_factor=backoff_factor, |
| 91 | + status_forcelist=status_forcelist, |
| 92 | + ) |
| 93 | + adapter = HTTPAdapter(max_retries=retry) |
| 94 | + session.mount("https://", adapter) |
| 95 | + return session |
| 96 | +
|
| 97 | + def GET(url, session): |
| 98 | + response = session.get(url) |
| 99 | + response.raise_for_status() |
| 100 | + return response.text.strip() |
| 101 | +
|
| 102 | + session = create_https_session_with_retries() |
| 103 | +
|
| 104 | + try: |
| 105 | + token = GET( |
| 106 | + f'https://${{ inputs.domain }}/?{urlencode({"verify": "${{ env.NONCE }}"})}', session |
| 107 | + ) |
| 108 | +
|
| 109 | + with open(os.getenv('GITHUB_OUTPUT'), 'a') as f: |
| 110 | + f.write(f'token={token}\n') |
| 111 | + except Exception as e: |
| 112 | + print(f"An error occurred: {e}") |
| 113 | + sys.exit(1) |
| 114 | +
|
| 115 | + - name: Revoke Token |
| 116 | + if: inputs.mode == 'revoke' |
| 117 | + id: revoke-token |
| 118 | + shell: python |
| 119 | + run: | |
| 120 | + import os |
| 121 | + import requests |
| 122 | + import sys |
| 123 | + from requests.adapters import HTTPAdapter, Retry |
| 124 | + from urllib.parse import urlencode |
| 125 | +
|
| 126 | + def create_https_session_with_retries( |
| 127 | + retries=5, backoff_factor=1.0, status_forcelist=(500, 502, 504, 400, 403, 404) |
| 128 | + ): |
| 129 | + session = requests.Session() |
| 130 | + retry = Retry( |
| 131 | + total=retries, |
| 132 | + read=retries, |
| 133 | + connect=retries, |
| 134 | + backoff_factor=backoff_factor, |
| 135 | + status_forcelist=status_forcelist, |
| 136 | + ) |
| 137 | + adapter = HTTPAdapter(max_retries=retry) |
| 138 | + session.mount("https://", adapter) |
| 139 | + return session |
| 140 | +
|
| 141 | + def GET(url, session): |
| 142 | + response = session.get(url) |
| 143 | + response.raise_for_status() |
| 144 | + return response.text.strip() |
| 145 | +
|
| 146 | + session = create_https_session_with_retries() |
| 147 | +
|
| 148 | + try: |
| 149 | + token = GET( |
| 150 | + f'https://${{ inputs.domain }}/?{urlencode({"revoke": "${{ env.TOKEN }}"})}', session |
| 151 | + ) |
| 152 | + except requests.exceptions.RequestException as e: |
| 153 | + print(f"An error occurred: {e}") |
| 154 | + sys.exit(1) |
0 commit comments