Fix blocklist service injection and centralize session cookie name
This commit is contained in:
@@ -23,6 +23,7 @@ from app.models.config import PendingRecovery
|
||||
from app.models.server import ServerStatus
|
||||
from app.repositories.protocols import SessionRepository
|
||||
from app.services.protocols import AuthService, JailService
|
||||
from app.utils.constants import SESSION_COOKIE_NAME
|
||||
from app.utils.runtime_state import RuntimeState
|
||||
from app.utils.session_cache import SessionCache
|
||||
|
||||
@@ -58,8 +59,6 @@ class ApplicationContext:
|
||||
session_cache: SessionCache | None
|
||||
|
||||
|
||||
_COOKIE_NAME = "bangui_session"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Session validation cache
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -137,7 +136,9 @@ async def get_db(
|
||||
await db.close()
|
||||
|
||||
|
||||
async def get_http_session(app_context: Annotated[ApplicationContext, Depends(get_app_context)]) -> aiohttp.ClientSession:
|
||||
async def get_http_session(
|
||||
app_context: Annotated[ApplicationContext, Depends(get_app_context)],
|
||||
) -> aiohttp.ClientSession:
|
||||
"""Provide the shared HTTP client session from application context.
|
||||
|
||||
Args:
|
||||
@@ -209,14 +210,14 @@ async def get_auth_service() -> AuthService:
|
||||
"""Provide the concrete authentication service implementation."""
|
||||
from app.services import auth_service # noqa: PLC0415
|
||||
|
||||
return cast(AuthService, auth_service)
|
||||
return cast("AuthService", auth_service)
|
||||
|
||||
|
||||
async def get_jail_service() -> JailService:
|
||||
"""Provide the concrete jail service implementation."""
|
||||
from app.services import jail_service # noqa: PLC0415
|
||||
|
||||
return cast(JailService, jail_service)
|
||||
return cast("JailService", jail_service)
|
||||
|
||||
|
||||
async def get_session_repo() -> SessionRepository:
|
||||
@@ -241,7 +242,9 @@ async def get_server_status(app_context: Annotated[ApplicationContext, Depends(g
|
||||
return app_context.server_status
|
||||
|
||||
|
||||
async def get_pending_recovery(app_context: Annotated[ApplicationContext, Depends(get_app_context)]) -> PendingRecovery | None:
|
||||
async def get_pending_recovery(
|
||||
app_context: Annotated[ApplicationContext, Depends(get_app_context)],
|
||||
) -> PendingRecovery | None:
|
||||
"""Return the current pending recovery record from application context."""
|
||||
return app_context.pending_recovery
|
||||
|
||||
@@ -277,7 +280,7 @@ async def require_auth(
|
||||
HTTPException: 401 if no valid session token is found.
|
||||
"""
|
||||
|
||||
token: str | None = request.cookies.get(_COOKIE_NAME)
|
||||
token: str | None = request.cookies.get(SESSION_COOKIE_NAME)
|
||||
if not token:
|
||||
auth_header: str = request.headers.get("Authorization", "")
|
||||
if auth_header.startswith("Bearer "):
|
||||
|
||||
Reference in New Issue
Block a user