docstrings / formatting
This commit is contained in:
30
util.py
30
util.py
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user