Skip to content

Commit 330e022

Browse files
committed
add functionality to pass token in the request parameters
1 parent 5a15f54 commit 330e022

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ You can use the App to configure [CCTray Clients](https://cctray.org/clients/):
1919
* Github Personal Access Token
2020
* [FGPAT (recommended) or PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
2121
* Read-Only access to Actions (Workflows, workflow runs and artifacts) required for Private repos.
22+
* Please take into account the (Github API rate limit)[https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting] for authentication tokens.
2223
* Development
2324
* Python 3.9
2425
* pip
@@ -47,23 +48,27 @@ Once up, the App binds to port `8000` by default and should be available at: htt
4748

4849
## Making an HTTP request
4950

50-
The App accepts GET and POST requests with **two manadatory parameters**:
51+
The App accepts GET requests with following parameters:
52+
53+
**manadatory parameters**
5154

5255
* `owner` - Organisation or User who owns the repository
5356
* `repo` - Name of the Repository
5457

55-
For Example:
58+
**optional parameter**
5659

57-
* GET
60+
* `token` - If you want to use FGPAT per user to access the API, to overcome Github API rate limiting (this takes precedence over the token set in the env var).
5861

62+
For Example:
63+
64+
* Mandatory Parameters
5965
```bash
6066
curl -X GET http://localhost:8000?owner=<repo_owner>&repo=<repository_name>
6167
```
6268

63-
* POST
64-
69+
* Optional Parameter
6570
```bash
66-
curl -d "owner=<repo_owner>&repo=<repository_name>" -X POST http://localhost:8000
71+
curl -X GET http://localhost:8000?owner=<repo_owner>&repo=<repository_name&token=<your_token>
6772
```
6873

6974
## Response

app.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@
1717
app.config['BASIC_AUTH_USERNAME'] = os.environ.get("BASIC_AUTH_USERNAME")
1818
app.config['BASIC_AUTH_PASSWORD'] = os.environ.get("BASIC_AUTH_PASSWORD")
1919

20-
token = os.environ.get("GITHUB_TOKEN")
21-
2220
basic_auth = BasicAuth(app)
2321

2422
API_BASE_URL = "https://api.github.com"
2523
MAX_WORKERS = 10
2624
TIMEOUT = 10
2725

26+
def get_token():
27+
"""Sets the Github API token
28+
29+
Returns:
30+
token: Either from the query parameter or the environment variable
31+
"""
32+
query_token = request.args.get("token")
33+
34+
if query_token:
35+
return query_token
36+
return os.environ.get("GITHUB_TOKEN")
37+
2838

2939
def get_workflows(owner, repo, headers):
3040
"""Get the workflows for a given owner and repo from the GitHub API.
@@ -104,9 +114,9 @@ def index():
104114
Returns:
105115
flask.Response: The XML response containing the project information.
106116
"""
107-
108117
owner = request.args.get("owner") or request.form.get('owner')
109118
repo = request.args.get("repo") or request.form.get('repo')
119+
token = get_token()
110120

111121
if not owner or not repo or not token:
112122
logger.warning("Missing parameter(s) or Environment Variable")
@@ -159,7 +169,6 @@ def health():
159169
Returns:
160170
flask.Response: JSON response containing the status and version.
161171
"""
162-
163172
with open('CHANGELOG.md', 'r', encoding='utf-8') as changelog_file:
164173
changelog_content = changelog_file.read()
165174

@@ -175,12 +184,14 @@ def health():
175184
return jsonify(response)
176185

177186
@app.route('/limit')
187+
@basic_auth.required
178188
def limit():
179189
"""Endpoint for checking the rate limit status.
180190
181191
Returns:
182192
flask.Response: JSON response containing rate limiting information.
183193
"""
194+
token = get_token()
184195

185196
headers = {
186197
'Accept': 'application/vnd.github+json',

0 commit comments

Comments
 (0)