PyKubeGrader 0.2.27__py3-none-any.whl → 0.2.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/METADATA +1 -1
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/RECORD +7 -7
- pykubegrader/tokens/validate_token.py +51 -14
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/LICENSE.txt +0 -0
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/WHEEL +0 -0
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/entry_points.txt +0 -0
- {PyKubeGrader-0.2.27.dist-info → PyKubeGrader-0.2.29.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,7 @@ pykubegrader/log_parser/parse.ipynb,sha256=5e-9dzUbJk2M8kPP55lVeksm86lSY5ocKfWOP
|
|
14
14
|
pykubegrader/log_parser/parse.py,sha256=dXzTEOTI6VTRNoHFDAjg6hZUhvB3kHtMb10_KW3NPrw,7641
|
15
15
|
pykubegrader/submit/submit_assignment.py,sha256=UgJXKWw5b8-bRSFnba4iHAyXnujULHcWIask7hKx9ik,3421
|
16
16
|
pykubegrader/tokens/tokens.py,sha256=TOj0jRun1lWTztKA7KX9SjzIfNQqkwdnbczrFSPWB7Y,1089
|
17
|
-
pykubegrader/tokens/validate_token.py,sha256=
|
17
|
+
pykubegrader/tokens/validate_token.py,sha256=CwoVo_KFEYspbH6pbb3jb7QKHaiOQQVOEFFWXV18Gvg,5287
|
18
18
|
pykubegrader/widgets/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
19
19
|
pykubegrader/widgets/multiple_choice.py,sha256=NjD3-uXSnibpUQ0mO3hRp_O-rynFyl0Dz6IXE4tnCRI,2078
|
20
20
|
pykubegrader/widgets/reading_question.py,sha256=y30_swHwzH8LrT8deWTnxctAAmR8BSxTlXAqMgUrAT4,3031
|
@@ -27,9 +27,9 @@ pykubegrader/widgets_base/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-
|
|
27
27
|
pykubegrader/widgets_base/multi_select.py,sha256=Cl0IN21wXLZuFu-zC65aS9tD4jMfzCRJ2DPjHao5_Ak,4044
|
28
28
|
pykubegrader/widgets_base/reading.py,sha256=xmvN1UIXwk32v9S-JhsXwDc7axPlgpvoxSeM3II8sxY,5393
|
29
29
|
pykubegrader/widgets_base/select.py,sha256=Fw3uFNOIWo1a3CvlzSx23bvi6bSmA3TqutuRbhD4Dp8,2525
|
30
|
-
PyKubeGrader-0.2.
|
31
|
-
PyKubeGrader-0.2.
|
32
|
-
PyKubeGrader-0.2.
|
33
|
-
PyKubeGrader-0.2.
|
34
|
-
PyKubeGrader-0.2.
|
35
|
-
PyKubeGrader-0.2.
|
30
|
+
PyKubeGrader-0.2.29.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
|
31
|
+
PyKubeGrader-0.2.29.dist-info/METADATA,sha256=7Te1ql0k3BNp9JaX-fQjxGKEMBLMfXrlGUj9gBdSHaw,2779
|
32
|
+
PyKubeGrader-0.2.29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
33
|
+
PyKubeGrader-0.2.29.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
|
34
|
+
PyKubeGrader-0.2.29.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
|
35
|
+
PyKubeGrader-0.2.29.dist-info/RECORD,,
|
@@ -1,9 +1,12 @@
|
|
1
1
|
import asyncio
|
2
2
|
import os
|
3
|
+
import sys
|
3
4
|
from typing import Optional
|
4
5
|
|
5
6
|
import httpx
|
6
7
|
import nest_asyncio # type: ignore
|
8
|
+
import requests
|
9
|
+
from requests.auth import HTTPBasicAuth
|
7
10
|
|
8
11
|
# Apply nest_asyncio for environments like Jupyter
|
9
12
|
nest_asyncio.apply()
|
@@ -87,26 +90,18 @@ async def async_validate_token(token: Optional[str] = None) -> None:
|
|
87
90
|
async with httpx.AsyncClient() as client:
|
88
91
|
try:
|
89
92
|
response = await client.get(url=endpoint, auth=basic_auth, timeout=10)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# If the response is 404, the token is invalid
|
96
|
-
detail = response.json().get("detail", "Token not found")
|
97
|
-
raise TokenValidationError(detail)
|
98
|
-
else:
|
99
|
-
# Handle unexpected status codes
|
100
|
-
raise TokenValidationError(
|
101
|
-
f"Unexpected response code: {response.status_code}"
|
102
|
-
)
|
93
|
+
response.raise_for_status()
|
94
|
+
return
|
95
|
+
except httpx.HTTPStatusError as e:
|
96
|
+
detail = e.response.json().get("detail", e.response.text)
|
97
|
+
raise TokenValidationError(detail)
|
103
98
|
except httpx.RequestError as e:
|
104
99
|
raise TokenValidationError(f"Request failed: {e}")
|
105
100
|
except Exception as e:
|
106
101
|
raise TokenValidationError(f"An unexpected error occurred: {e}")
|
107
102
|
|
108
103
|
|
109
|
-
def
|
104
|
+
def validate_token_wrapper(token: Optional[str] = None) -> None:
|
110
105
|
"""
|
111
106
|
Synchronous wrapper for the `async_validate_token` function.
|
112
107
|
|
@@ -131,6 +126,48 @@ def validate_token(token: Optional[str] = None) -> None:
|
|
131
126
|
loop.run_until_complete(async_validate_token(token))
|
132
127
|
|
133
128
|
|
129
|
+
def validate_token(token: Optional[str] = None) -> None:
|
130
|
+
if token:
|
131
|
+
os.environ["TOKEN"] = token # If token passed, set env var
|
132
|
+
else:
|
133
|
+
token = os.getenv("TOKEN") # Otherwise try to get from env
|
134
|
+
if not token:
|
135
|
+
print("Error: No token provided", file=sys.stderr)
|
136
|
+
return
|
137
|
+
|
138
|
+
# Get endpoint URL
|
139
|
+
base_url = os.getenv("DB_URL")
|
140
|
+
if not base_url:
|
141
|
+
print("Error: Environment variable 'DB_URL' not set", file=sys.stderr)
|
142
|
+
return
|
143
|
+
endpoint = f"{base_url.rstrip('/')}/validate-token/{token}"
|
144
|
+
|
145
|
+
# Get credentials
|
146
|
+
try:
|
147
|
+
credentials = get_credentials()
|
148
|
+
except ValueError as e:
|
149
|
+
print(f"Error: {e}", file=sys.stderr)
|
150
|
+
return
|
151
|
+
|
152
|
+
username = credentials["username"]
|
153
|
+
password = credentials["password"]
|
154
|
+
basic_auth = HTTPBasicAuth(username, password)
|
155
|
+
|
156
|
+
try:
|
157
|
+
response = requests.get(url=endpoint, auth=basic_auth, timeout=10)
|
158
|
+
response.raise_for_status()
|
159
|
+
|
160
|
+
detail = response.json().get("detail", response.text)
|
161
|
+
print(detail)
|
162
|
+
except requests.exceptions.HTTPError as e:
|
163
|
+
detail = e.response.json().get("detail", e.response.text)
|
164
|
+
print(f"Error: {detail}", file=sys.stderr)
|
165
|
+
except requests.exceptions.RequestException as e:
|
166
|
+
print(f"Error: Request failed: {e}", file=sys.stderr)
|
167
|
+
except Exception as e:
|
168
|
+
print(f"Unexpected error: {e}", file=sys.stderr)
|
169
|
+
|
170
|
+
|
134
171
|
# Example usage
|
135
172
|
if __name__ == "__main__":
|
136
173
|
token = "test"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|