feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.

This commit is contained in:
pacnpal
2025-12-28 17:32:53 -05:00
parent aa56c46c27
commit c95f99ca10
452 changed files with 7948 additions and 6073 deletions

View File

@@ -18,10 +18,10 @@ Why python-decouple?
import logging
import re
import warnings
from typing import Any, Callable, Optional
from typing import Any
from urllib.parse import urlparse
from decouple import config, UndefinedValueError
from decouple import UndefinedValueError, config
logger = logging.getLogger("thrillwiki")
@@ -170,24 +170,20 @@ def validate_type(value: Any, expected_type: type) -> bool:
def validate_range(
value: Any,
min_value: Optional[Any] = None,
max_value: Optional[Any] = None
min_value: Any | None = None,
max_value: Any | None = None
) -> bool:
"""Validate that a value is within a specified range."""
if min_value is not None and value < min_value:
return False
if max_value is not None and value > max_value:
return False
return True
return not (max_value is not None and value > max_value)
def validate_length(value: str, min_length: int = 0, max_length: int = None) -> bool:
"""Validate that a string value meets length requirements."""
if len(value) < min_length:
return False
if max_length is not None and len(value) > max_length:
return False
return True
return not (max_length is not None and len(value) > max_length)
VALIDATORS = {
@@ -217,7 +213,7 @@ def validate_variable(name: str, rules: dict) -> list[str]:
try:
# Get the value with appropriate type casting
var_type = rules.get("type", str)
default = rules.get("default", None)
default = rules.get("default")
if var_type == bool:
value = config(name, default=default, cast=bool)
@@ -263,9 +259,8 @@ def validate_variable(name: str, rules: dict) -> list[str]:
# Custom validator
validator_name = rules.get("validator")
if validator_name and validator_name in VALIDATORS:
if not VALIDATORS[validator_name](value):
errors.append(f"{name}: Failed {validator_name} validation")
if validator_name and validator_name in VALIDATORS and not VALIDATORS[validator_name](value):
errors.append(f"{name}: Failed {validator_name} validation")
return errors
@@ -375,7 +370,7 @@ def run_startup_validation() -> None:
else:
if debug_mode:
for error in result["errors"]:
warnings.warn(f"Configuration error: {error}")
warnings.warn(f"Configuration error: {error}", stacklevel=2)
else:
raise ValueError(
"Configuration validation failed. Check logs for details."