Refactor router dependency wiring to explicit app state providers

This commit is contained in:
2026-04-06 20:12:04 +02:00
parent f0ee466603
commit 594f55d157
5 changed files with 45 additions and 59 deletions

View File

@@ -14,7 +14,7 @@ from __future__ import annotations
from typing import Literal
from fastapi import APIRouter, Query, Request
from fastapi import APIRouter, Query
from app import __version__
from app.dependencies import (
@@ -22,6 +22,7 @@ from app.dependencies import (
DbDep,
Fail2BanSocketDep,
HttpSessionDep,
ServerStatusDep,
)
from app.models.ban import (
BanOrigin,
@@ -50,7 +51,7 @@ _DEFAULT_RANGE: TimeRange = "24h"
summary="Return the cached fail2ban server status",
)
async def get_server_status(
request: Request,
server_status: ServerStatusDep,
_auth: AuthDep,
) -> ServerStatusResponse:
"""Return the most recent fail2ban health snapshot.
@@ -60,18 +61,14 @@ async def get_server_status(
returned so the response is always well-formed.
Args:
request: The incoming request (used to access ``app.state``).
server_status: Cached fail2ban server health snapshot (injected).
_auth: Validated session — enforces authentication on this endpoint.
Returns:
:class:`~app.models.server.ServerStatusResponse` containing the
current health snapshot.
"""
cached: ServerStatus = getattr(
request.app.state,
"server_status",
ServerStatus(online=False),
)
cached: ServerStatus = server_status
cached.version = __version__
return ServerStatusResponse(status=cached)