Remove FastAPI dependency from jail config service signatures
This commit is contained in:
@@ -47,6 +47,12 @@ from app.services import (
|
||||
jail_config_service,
|
||||
)
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.utils.runtime_state import (
|
||||
clear_activation_record,
|
||||
clear_pending_recovery,
|
||||
create_pending_recovery,
|
||||
record_activation,
|
||||
)
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/jails", tags=["Jail Config"])
|
||||
|
||||
@@ -376,8 +382,10 @@ async def activate_jail(
|
||||
"""
|
||||
req = body if body is not None else ActivateJailRequest()
|
||||
|
||||
activation_time = record_activation(app, name)
|
||||
|
||||
try:
|
||||
result = await jail_config_service.activate_jail(app, config_dir, socket_path, name, req)
|
||||
result = await jail_config_service.activate_jail(config_dir, socket_path, name, req)
|
||||
except JailNameError as exc:
|
||||
raise _bad_request(str(exc)) from exc
|
||||
except JailNotFoundInConfigError:
|
||||
@@ -406,7 +414,6 @@ async def activate_jail(
|
||||
summary="Deactivate an active jail",
|
||||
)
|
||||
async def deactivate_jail(
|
||||
app: AppDep,
|
||||
_auth: AuthDep,
|
||||
config_dir: Fail2BanConfigDirDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
@@ -418,7 +425,6 @@ async def deactivate_jail(
|
||||
full fail2ban reload so the jail stops immediately.
|
||||
|
||||
Args:
|
||||
app: FastAPI application instance.
|
||||
_auth: Validated session.
|
||||
name: Name of the jail to deactivate.
|
||||
|
||||
@@ -433,7 +439,7 @@ async def deactivate_jail(
|
||||
"""
|
||||
|
||||
try:
|
||||
result = await jail_config_service.deactivate_jail(app, config_dir, socket_path, name)
|
||||
result = await jail_config_service.deactivate_jail(config_dir, socket_path, name)
|
||||
except JailNameError as exc:
|
||||
raise _bad_request(str(exc)) from exc
|
||||
except JailNotFoundInConfigError:
|
||||
@@ -585,7 +591,7 @@ async def rollback_jail(
|
||||
start_cmd_parts: list[str] = start_cmd.split()
|
||||
|
||||
try:
|
||||
result = await jail_config_service.rollback_jail(app, config_dir, socket_path, name, start_cmd_parts)
|
||||
result = await jail_config_service.rollback_jail(config_dir, socket_path, name, start_cmd_parts)
|
||||
except JailNameError as exc:
|
||||
raise _bad_request(str(exc)) from exc
|
||||
except ConfigWriteError as exc:
|
||||
@@ -594,6 +600,10 @@ async def rollback_jail(
|
||||
detail=f"Failed to write config override: {exc}",
|
||||
) from exc
|
||||
|
||||
if result.fail2ban_running:
|
||||
clear_pending_recovery(app)
|
||||
clear_activation_record(app)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user