Refactor routers to use explicit FastAPI app dependencies
This commit is contained in:
@@ -15,7 +15,7 @@ import aiohttp
|
||||
import aiosqlite
|
||||
import structlog
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler # type: ignore[import-untyped]
|
||||
from fastapi import Depends, HTTPException, Request, status
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request, status
|
||||
|
||||
from app.config import Settings
|
||||
from app.models.auth import Session
|
||||
@@ -181,6 +181,11 @@ async def get_app_state(request: Request) -> AppState:
|
||||
return cast("AppState", request.app.state)
|
||||
|
||||
|
||||
async def get_app(request: Request) -> FastAPI:
|
||||
"""Provide the FastAPI application instance for the current request."""
|
||||
return request.app
|
||||
|
||||
|
||||
async def get_server_status(request: Request) -> ServerStatus:
|
||||
"""Return the cached fail2ban server status snapshot from app state."""
|
||||
state = cast("AppState", request.app.state)
|
||||
@@ -264,4 +269,5 @@ Fail2BanStartCommandDep = Annotated[str, Depends(get_fail2ban_start_command)]
|
||||
ServerStatusDep = Annotated[ServerStatus, Depends(get_server_status)]
|
||||
PendingRecoveryDep = Annotated[PendingRecovery | None, Depends(get_pending_recovery)]
|
||||
AppStateDep = Annotated[AppState, Depends(get_app_state)]
|
||||
AppDep = Annotated[FastAPI, Depends(get_app)]
|
||||
AuthDep = Annotated[Session, Depends(require_auth)]
|
||||
|
||||
Reference in New Issue
Block a user