Refactor router dependency wiring to explicit app state providers
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user