PyKubeGrader 0.2.16__py3-none-any.whl → 0.2.17__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/METADATA +1 -1
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/RECORD +8 -7
- pykubegrader/tokens/tokens.py +0 -6
- pykubegrader/tokens/validate_token.py +59 -0
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/LICENSE.txt +0 -0
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/WHEEL +0 -0
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/entry_points.txt +0 -0
- {PyKubeGrader-0.2.16.dist-info → PyKubeGrader-0.2.17.dist-info}/top_level.txt +0 -0
@@ -13,7 +13,8 @@ pykubegrader/log_parser/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YB
|
|
13
13
|
pykubegrader/log_parser/parse.ipynb,sha256=H1CUuqiUSE-tiZV1IS7VG6HAEvoopGd6i_5QM5CwoE0,12230
|
14
14
|
pykubegrader/log_parser/parse.py,sha256=YCs_OCnoxQKsL55MjTZWXBBBsehJL8PIB9ANnC-aE44,7379
|
15
15
|
pykubegrader/submit/submit_assignment.py,sha256=p-v31479342q0AO3lJrd8Fwk7iJQUz183OeGeiNcXOY,3405
|
16
|
-
pykubegrader/tokens/tokens.py,sha256=
|
16
|
+
pykubegrader/tokens/tokens.py,sha256=DorNwdrA5N5apB3LQjVGa2ABN5C1upkgglecaLHobr0,1260
|
17
|
+
pykubegrader/tokens/validate_token.py,sha256=ejnIAOe6YODSH6Q5MOtC5yEGB3gSDkTSQViPzut6c8E,1806
|
17
18
|
pykubegrader/widgets/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
18
19
|
pykubegrader/widgets/multiple_choice.py,sha256=NjD3-uXSnibpUQ0mO3hRp_O-rynFyl0Dz6IXE4tnCRI,2078
|
19
20
|
pykubegrader/widgets/reading_question.py,sha256=y30_swHwzH8LrT8deWTnxctAAmR8BSxTlXAqMgUrAT4,3031
|
@@ -26,9 +27,9 @@ pykubegrader/widgets_base/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-
|
|
26
27
|
pykubegrader/widgets_base/multi_select.py,sha256=Cl0IN21wXLZuFu-zC65aS9tD4jMfzCRJ2DPjHao5_Ak,4044
|
27
28
|
pykubegrader/widgets_base/reading.py,sha256=_vjUPynqmJe_R4vf-7hVhGnQR726S9GL6qT8bflBXBM,5383
|
28
29
|
pykubegrader/widgets_base/select.py,sha256=Fw3uFNOIWo1a3CvlzSx23bvi6bSmA3TqutuRbhD4Dp8,2525
|
29
|
-
PyKubeGrader-0.2.
|
30
|
-
PyKubeGrader-0.2.
|
31
|
-
PyKubeGrader-0.2.
|
32
|
-
PyKubeGrader-0.2.
|
33
|
-
PyKubeGrader-0.2.
|
34
|
-
PyKubeGrader-0.2.
|
30
|
+
PyKubeGrader-0.2.17.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
|
31
|
+
PyKubeGrader-0.2.17.dist-info/METADATA,sha256=GmcLxVd6cwJ_8HepAk0ucQinhdsF9IX125y37DJXxIs,2779
|
32
|
+
PyKubeGrader-0.2.17.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
33
|
+
PyKubeGrader-0.2.17.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
|
34
|
+
PyKubeGrader-0.2.17.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
|
35
|
+
PyKubeGrader-0.2.17.dist-info/RECORD,,
|
pykubegrader/tokens/tokens.py
CHANGED
@@ -3,12 +3,6 @@ import os
|
|
3
3
|
import json
|
4
4
|
|
5
5
|
|
6
|
-
# try:
|
7
|
-
# from pykubegrader.build.passwords import password, user
|
8
|
-
# except: # noqa: E722
|
9
|
-
# print("Passwords not found, cannot access database")
|
10
|
-
|
11
|
-
|
12
6
|
def build_token_payload(token: str, duration: int) -> dict:
|
13
7
|
|
14
8
|
if os.getenv("JUPYTERHUB_USER", None) is None:
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import requests
|
2
|
+
|
3
|
+
|
4
|
+
class TokenValidationError(Exception):
|
5
|
+
"""
|
6
|
+
Custom exception raised when the token validation fails.
|
7
|
+
"""
|
8
|
+
|
9
|
+
def __init__(self, message=None):
|
10
|
+
"""
|
11
|
+
Initialize the exception with an optional message.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
message (str, optional): The error message to display. Defaults to None.
|
15
|
+
"""
|
16
|
+
super().__init__(message)
|
17
|
+
|
18
|
+
|
19
|
+
def validate_token(token):
|
20
|
+
"""
|
21
|
+
Validate a token by making a GET request to the validation endpoint.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
token (str): The token to validate.
|
25
|
+
|
26
|
+
Raises:
|
27
|
+
TokenValidationError: If the token is invalid or if there is an error in the validation process.
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
None: If the token is valid, the function will pass silently.
|
31
|
+
"""
|
32
|
+
endpoint = f"https://engr-131-api.eastus.cloudapp.azure.com/validate-token/{token}"
|
33
|
+
try:
|
34
|
+
response = requests.get(endpoint, timeout=10)
|
35
|
+
|
36
|
+
if response.status_code == 200:
|
37
|
+
# If the response is 200, the token is valid
|
38
|
+
return # Pass silently
|
39
|
+
elif response.status_code == 404:
|
40
|
+
# If the response is 404, the token is invalid
|
41
|
+
raise TokenValidationError(response.json().get("detail", "Token not found"))
|
42
|
+
else:
|
43
|
+
# Handle unexpected status codes
|
44
|
+
raise TokenValidationError(
|
45
|
+
f"Unexpected response code: {response.status_code}"
|
46
|
+
)
|
47
|
+
except requests.RequestException as e:
|
48
|
+
# Raise an exception for connection errors or timeout
|
49
|
+
raise TokenValidationError(f"Request failed: {e}")
|
50
|
+
|
51
|
+
|
52
|
+
# Example usage
|
53
|
+
if __name__ == "__main__":
|
54
|
+
token = "test"
|
55
|
+
try:
|
56
|
+
validate_token(token)
|
57
|
+
print("Token is valid.")
|
58
|
+
except TokenValidationError as e:
|
59
|
+
print(f"Token validation failed: {e}")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|