PyKubeGrader 0.2.19__tar.gz → 0.2.20__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. {pykubegrader-0.2.19/src/PyKubeGrader.egg-info → pykubegrader-0.2.20}/PKG-INFO +1 -1
  2. {pykubegrader-0.2.19 → pykubegrader-0.2.20/src/PyKubeGrader.egg-info}/PKG-INFO +1 -1
  3. pykubegrader-0.2.20/src/pykubegrader/tokens/validate_token.py +127 -0
  4. pykubegrader-0.2.19/src/pykubegrader/tokens/validate_token.py +0 -71
  5. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/.coveragerc +0 -0
  6. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/.github/workflows/main.yml +0 -0
  7. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/.gitignore +0 -0
  8. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/.readthedocs.yml +0 -0
  9. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/AUTHORS.rst +0 -0
  10. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/CHANGELOG.rst +0 -0
  11. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/CONTRIBUTING.rst +0 -0
  12. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/LICENSE.txt +0 -0
  13. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/README.rst +0 -0
  14. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/Makefile +0 -0
  15. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/_static/Drexel_blue_Logo_square_Dark.png +0 -0
  16. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/_static/Drexel_blue_Logo_square_Light.png +0 -0
  17. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/_static/custom.css +0 -0
  18. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/authors.rst +0 -0
  19. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/changelog.rst +0 -0
  20. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/conf.py +0 -0
  21. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/contributing.rst +0 -0
  22. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/index.rst +0 -0
  23. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/license.rst +0 -0
  24. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/readme.rst +0 -0
  25. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/docs/requirements.txt +0 -0
  26. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/examples/.responses.json +0 -0
  27. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/examples/true_false.ipynb +0 -0
  28. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/pyproject.toml +0 -0
  29. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/setup.cfg +0 -0
  30. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/setup.py +0 -0
  31. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/SOURCES.txt +0 -0
  32. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/dependency_links.txt +0 -0
  33. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/entry_points.txt +0 -0
  34. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/not-zip-safe +0 -0
  35. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/requires.txt +0 -0
  36. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/PyKubeGrader.egg-info/top_level.txt +0 -0
  37. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/__init__.py +0 -0
  38. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/build/__init__.py +0 -0
  39. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/build/api_notebook_builder.py +0 -0
  40. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/build/build_folder.py +0 -0
  41. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/build/clean_folder.py +0 -0
  42. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/graders/__init__.py +0 -0
  43. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/graders/late_assignments.py +0 -0
  44. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/initialize.py +0 -0
  45. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/log_parser/__init__.py +0 -0
  46. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/log_parser/parse.ipynb +0 -0
  47. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/log_parser/parse.py +0 -0
  48. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/submit/submit_assignment.py +0 -0
  49. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/telemetry.py +0 -0
  50. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/tokens/tokens.py +0 -0
  51. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/utils.py +0 -0
  52. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/validate.py +0 -0
  53. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/__init__.py +0 -0
  54. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/multiple_choice.py +0 -0
  55. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/reading_question.py +0 -0
  56. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/select_many.py +0 -0
  57. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/student_info.py +0 -0
  58. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/style.py +0 -0
  59. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/true_false.py +0 -0
  60. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets/types_question.py +0 -0
  61. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets_base/__init__.py +0 -0
  62. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets_base/multi_select.py +0 -0
  63. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets_base/reading.py +0 -0
  64. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/src/pykubegrader/widgets_base/select.py +0 -0
  65. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/tests/conftest.py +0 -0
  66. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/tests/import_test.py +0 -0
  67. {pykubegrader-0.2.19 → pykubegrader-0.2.20}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyKubeGrader
3
- Version: 0.2.19
3
+ Version: 0.2.20
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: jagar2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyKubeGrader
3
- Version: 0.2.19
3
+ Version: 0.2.20
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: jagar2
@@ -0,0 +1,127 @@
1
+ import os
2
+ import base64
3
+ import httpx
4
+ import asyncio
5
+ import nest_asyncio
6
+
7
+ # Apply nest_asyncio for environments like Jupyter
8
+ nest_asyncio.apply()
9
+
10
+
11
+ class TokenValidationError(Exception):
12
+ """
13
+ Custom exception raised when the token validation fails.
14
+ """
15
+
16
+ def __init__(self, message=None):
17
+ """
18
+ Initialize the exception with an optional message.
19
+
20
+ Args:
21
+ message (str, optional): The error message to display. Defaults to None.
22
+ """
23
+ super().__init__(message)
24
+
25
+
26
+ def get_credentials():
27
+ """
28
+ Fetch the username and password from environment variables.
29
+
30
+ Returns:
31
+ dict: A dictionary containing 'username' and 'password'.
32
+ """
33
+ username = os.getenv("user_name_student")
34
+ password = os.getenv("keys_student")
35
+ if not username or not password:
36
+ raise ValueError(
37
+ "Environment variables 'user_name_student' or 'keys_student' are not set."
38
+ )
39
+ return {"username": username, "password": password}
40
+
41
+
42
+ async def async_validate_token(token: str) -> None:
43
+ """
44
+ Asynchronously validate a token by making a GET request to the validation endpoint.
45
+
46
+ Args:
47
+ token (str): The token to validate.
48
+
49
+ Raises:
50
+ TokenValidationError: If the token is invalid or if there is an error in the validation process.
51
+
52
+ Returns:
53
+ None: If the token is valid, the function will pass silently.
54
+ """
55
+ # Fetch the endpoint URL
56
+ base_url = os.getenv("DB_URL")
57
+ if not base_url:
58
+ raise ValueError("Environment variable 'DB_URL' is not set.")
59
+ endpoint = f"{base_url}validate-token/{token}"
60
+
61
+ # Get credentials
62
+ credentials = get_credentials()
63
+ username = credentials["username"]
64
+ password = credentials["password"]
65
+
66
+ # Encode credentials for Basic Authentication
67
+ auth_header = (
68
+ f"Basic {base64.b64encode(f'{username}:{password}'.encode()).decode()}"
69
+ )
70
+
71
+ # Make the GET request
72
+ async with httpx.AsyncClient() as client:
73
+ try:
74
+ response = await client.get(
75
+ endpoint, headers={"Authorization": auth_header}, timeout=10
76
+ )
77
+
78
+ if response.status_code == 200:
79
+ # If the response is 200, the token is valid
80
+ return # Pass silently
81
+ elif response.status_code == 404:
82
+ # If the response is 404, the token is invalid
83
+ detail = response.json().get("detail", "Token not found")
84
+ raise TokenValidationError(detail)
85
+ else:
86
+ # Handle unexpected status codes
87
+ raise TokenValidationError(
88
+ f"Unexpected response code: {response.status_code}"
89
+ )
90
+ except httpx.RequestError as e:
91
+ raise TokenValidationError(f"Request failed: {e}")
92
+ except Exception as e:
93
+ raise TokenValidationError(f"An unexpected error occurred: {e}")
94
+
95
+
96
+ def validate_token(token: str) -> None:
97
+ """
98
+ Synchronous wrapper for the `async_validate_token` function.
99
+
100
+ Args:
101
+ token (str): The token to validate.
102
+
103
+ Raises:
104
+ TokenValidationError: If the token is invalid or if there is an error in the validation process.
105
+
106
+ Returns:
107
+ None: If the token is valid, the function will pass silently.
108
+ """
109
+ # Get the current event loop or create one
110
+ try:
111
+ loop = asyncio.get_event_loop()
112
+ except RuntimeError:
113
+ loop = asyncio.new_event_loop()
114
+ asyncio.set_event_loop(loop)
115
+
116
+ # Run the async function in the event loop
117
+ loop.run_until_complete(async_validate_token(token))
118
+
119
+
120
+ # Example usage
121
+ if __name__ == "__main__":
122
+ token = "test"
123
+ try:
124
+ validate_token(token)
125
+ print("Token is valid.")
126
+ except TokenValidationError as e:
127
+ print(f"Token validation failed: {e}")
@@ -1,71 +0,0 @@
1
- import requests
2
- import os
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 = None):
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
- # sets the token in the environment variable
33
- if token is not None:
34
- os.environ["TOKEN"] = token
35
-
36
- if token is None:
37
- token = os.getenv("TOKEN", None)
38
-
39
- if token is None:
40
- raise TokenValidationError("No token provided")
41
-
42
- # Define the validation endpoint
43
- endpoint = f"https://engr-131-api.eastus.cloudapp.azure.com/validate-token/{token}"
44
-
45
- try:
46
- response = requests.get(endpoint, timeout=10)
47
-
48
- if response.status_code == 200:
49
- # If the response is 200, the token is valid
50
- return # Pass silently
51
- elif response.status_code == 404:
52
- # If the response is 404, the token is invalid
53
- raise TokenValidationError(response.json().get("detail", "Token not found"))
54
- else:
55
- # Handle unexpected status codes
56
- raise TokenValidationError(
57
- f"Unexpected response code: {response.status_code}"
58
- )
59
- except requests.RequestException as e:
60
- # Raise an exception for connection errors or timeout
61
- raise TokenValidationError(f"Request failed: {e}")
62
-
63
-
64
- # Example usage
65
- if __name__ == "__main__":
66
- token = "test"
67
- try:
68
- validate_token(token)
69
- print("Token is valid.")
70
- except TokenValidationError as e:
71
- print(f"Token validation failed: {e}")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes