docstrings / formatting

This commit is contained in:
2025-09-23 13:17:34 -04:00
parent c2044711fb
commit 19afb287cd
16 changed files with 1165 additions and 428 deletions

30
util.py
View File

@@ -18,23 +18,45 @@ class Utilities:
def get_blocked_response(self, path: Optional[str] = None):
"""
Get Blocked HTTP Response
Return a redirect response for blocked requests.
Args:
path (Optional[str]): The requested path (currently unused).
Returns:
RedirectResponse: A redirect to the blocked URI.
"""
logging.error("Rejected request: Blocked")
return RedirectResponse(url=self.blocked_redirect_uri)
def get_no_endpoint_found(self, path: Optional[str] = None):
"""
Get 404 Response
Raise an HTTP 404 exception for unknown endpoints.
Args:
path (Optional[str]): The requested path (currently unused).
Raises:
HTTPException: With status code 404 and detail "Unknown endpoint".
"""
logging.error("Rejected request: No such endpoint")
raise HTTPException(detail="Unknown endpoint", status_code=404)
def check_key(self, path: str, key: str, req_type: int = 0) -> bool:
"""
Accepts path as an argument to allow fine tuning access for each API key, not currently in use.
"""
Check if the provided API key is valid and meets the requirements.
Args:
path (str): The request path (reserved for future fine-tuning).
key (str): The authorization header value, expected to start with "Bearer ".
req_type (int): The type of access required.
0: Basic access.
2: Private access (key must start with "PRV-").
4: Radio access (key must start with "RAD-").
Returns:
bool: True if the key is valid and meets the requirements, False otherwise.
"""
if not key or not key.startswith("Bearer "):
return False