Refactor routers to use explicit FastAPI app dependencies
This commit is contained in:
@@ -44,6 +44,7 @@ import structlog
|
||||
from fastapi import APIRouter, HTTPException, Path, Query, Request, status
|
||||
|
||||
from app.dependencies import (
|
||||
AppDep,
|
||||
AppStateDep,
|
||||
AuthDep,
|
||||
DbDep,
|
||||
@@ -677,9 +678,8 @@ async def update_map_color_thresholds(
|
||||
summary="Activate an inactive jail",
|
||||
)
|
||||
async def activate_jail(
|
||||
request: Request,
|
||||
app: AppDep,
|
||||
_auth: AuthDep,
|
||||
app_state: AppStateDep,
|
||||
config_dir: Fail2BanConfigDirDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
name: _NamePath,
|
||||
@@ -692,7 +692,7 @@ async def activate_jail(
|
||||
the jail starts immediately.
|
||||
|
||||
Args:
|
||||
request: FastAPI request object.
|
||||
app: FastAPI application instance.
|
||||
_auth: Validated session.
|
||||
name: Name of the jail to activate.
|
||||
body: Optional override values (bantime, findtime, maxretry, port,
|
||||
@@ -730,7 +730,7 @@ async def activate_jail(
|
||||
|
||||
# Record this activation so the health-check task can attribute a
|
||||
# subsequent fail2ban crash to it.
|
||||
app_state.last_activation = {
|
||||
app.state.last_activation = {
|
||||
"jail_name": name,
|
||||
"at": datetime.datetime.now(tz=datetime.UTC),
|
||||
}
|
||||
@@ -738,15 +738,15 @@ async def activate_jail(
|
||||
# If fail2ban stopped responding after the reload, create a pending-recovery
|
||||
# record immediately (before the background health task notices).
|
||||
if not result.fail2ban_running:
|
||||
app_state.pending_recovery = PendingRecovery(
|
||||
app.state.pending_recovery = PendingRecovery(
|
||||
jail_name=name,
|
||||
activated_at=app_state.last_activation["at"],
|
||||
activated_at=app.state.last_activation["at"],
|
||||
detected_at=datetime.datetime.now(tz=datetime.UTC),
|
||||
)
|
||||
|
||||
# Force an immediate health probe so the cached status reflects the current
|
||||
# fail2ban state without waiting for the next scheduled check.
|
||||
await _run_probe(request.app)
|
||||
await _run_probe(app)
|
||||
|
||||
return result
|
||||
|
||||
@@ -757,7 +757,7 @@ async def activate_jail(
|
||||
summary="Deactivate an active jail",
|
||||
)
|
||||
async def deactivate_jail(
|
||||
request: Request,
|
||||
app: AppDep,
|
||||
_auth: AuthDep,
|
||||
config_dir: Fail2BanConfigDirDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
@@ -769,7 +769,7 @@ async def deactivate_jail(
|
||||
full fail2ban reload so the jail stops immediately.
|
||||
|
||||
Args:
|
||||
request: FastAPI request object.
|
||||
app: FastAPI application instance.
|
||||
_auth: Validated session.
|
||||
name: Name of the jail to deactivate.
|
||||
|
||||
@@ -805,7 +805,7 @@ async def deactivate_jail(
|
||||
# Force an immediate health probe so the cached status reflects the current
|
||||
# fail2ban state (reload changes the active-jail count) without waiting for
|
||||
# the next scheduled background check (up to 30 seconds).
|
||||
await _run_probe(request.app)
|
||||
await _run_probe(app)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user