Remove FastAPI dependency from jail config service signatures

This commit is contained in:
2026-04-14 15:01:05 +02:00
parent 41f8c1f6cb
commit 86fa271c40
4 changed files with 28 additions and 40 deletions

View File

@@ -14,7 +14,7 @@ import os
import re
import tempfile
from pathlib import Path
from typing import TYPE_CHECKING, cast
from typing import cast
import structlog
@@ -37,15 +37,6 @@ from app.models.config import (
from app.services import health_service
from app.utils.async_utils import run_blocking
from app.utils.fail2ban_client import Fail2BanClient
from app.utils.runtime_state import (
clear_activation_record,
clear_pending_recovery,
create_pending_recovery,
record_activation,
)
if TYPE_CHECKING: # pragma: no cover
from fastapi import FastAPI
log: structlog.stdlib.BoundLogger = structlog.get_logger()
@@ -274,29 +265,18 @@ async def list_inactive_jails(
async def activate_jail(
app: FastAPI,
config_dir: str,
socket_path: str,
name: str,
req: ActivateJailRequest,
) -> JailActivationResponse:
"""Activate a jail and manage crash recovery state.
"""Activate a jail and update the health-check cache.
This wrapper records the activation timestamp, delegates the actual
file-based activation workflow to the lower-level implementation, and
updates the health-check cache immediately so the UI reflects the
current fail2ban state.
This wrapper delegates the file-based activation workflow to the
lower-level implementation and runs an immediate probe so the UI
reflects the current fail2ban state.
"""
activation_time = record_activation(app, name)
result = await _activate_jail(config_dir, socket_path, name, req)
if not result.fail2ban_running:
create_pending_recovery(
app,
jail_name=name,
activated_at=activation_time,
)
await run_probe(socket_path)
return result
@@ -561,7 +541,6 @@ async def _rollback_activation_async(
async def deactivate_jail(
app: FastAPI,
config_dir: str,
socket_path: str,
name: str,
@@ -707,20 +686,17 @@ async def validate_jail_config(
async def rollback_jail(
app: FastAPI,
config_dir: str,
socket_path: str,
name: str,
start_cmd_parts: list[str],
) -> RollbackResponse:
"""Rollback a jail and clear pending recovery state on success."""
result = await _rollback_jail(config_dir, socket_path, name, start_cmd_parts)
"""Rollback a jail and return the result.
if result.fail2ban_running:
clear_pending_recovery(app)
clear_activation_record(app)
return result
The caller is responsible for clearing pending recovery state when the
operation succeeds.
"""
return await _rollback_jail(config_dir, socket_path, name, start_cmd_parts)
async def _rollback_jail(