Refactor app helpers and use AppStateDep in config router

Move service-dependent helper wrappers from app.utils to app.helpers and update config router activation/rollback to use explicit AppState dependency.
This commit is contained in:
2026-04-07 20:39:56 +02:00
parent ed3aa61c35
commit 1e39e5a1d6
11 changed files with 98 additions and 30 deletions

View File

@@ -0,0 +1,6 @@
"""Cross-service helpers and shared abstractions.
Modules in ``app.helpers`` are allowed to depend on the service layer when they
implement shared business logic used by multiple service modules. This keeps
``app.utils`` independent and low-level.
"""

View File

@@ -0,0 +1,19 @@
"""Shared config-file helpers reused across service modules."""
from __future__ import annotations
from app.services.config_file_service import (
_build_inactive_jail,
_get_active_jail_names,
_ordered_config_files,
_parse_jails_sync,
_validate_jail_config_sync,
)
__all__ = [
"_ordered_config_files",
"_parse_jails_sync",
"_build_inactive_jail",
"_get_active_jail_names",
"_validate_jail_config_sync",
]

View File

@@ -0,0 +1,23 @@
"""Shared jail management helpers for service-layer code."""
from __future__ import annotations
from typing import TYPE_CHECKING
from app.services.jail_service import reload_all
if TYPE_CHECKING:
from collections.abc import Sequence
async def reload_jails(
socket_path: str,
include_jails: Sequence[str] | None = None,
exclude_jails: Sequence[str] | None = None,
) -> None:
"""Reload fail2ban jails using the shared jail service helper."""
await reload_all(
socket_path,
include_jails=list(include_jails) if include_jails is not None else None,
exclude_jails=list(exclude_jails) if exclude_jails is not None else None,
)

View File

@@ -0,0 +1,21 @@
"""Shared log-related helpers for service-layer code."""
from __future__ import annotations
from typing import TYPE_CHECKING
from app.services.log_service import preview_log as _preview_log
from app.services.log_service import test_regex as _test_regex
if TYPE_CHECKING:
from app.models.config import LogPreviewRequest, LogPreviewResponse, RegexTestRequest, RegexTestResponse
def preview_log(req: LogPreviewRequest) -> LogPreviewResponse:
"""Return log preview results using the shared log service."""
return _preview_log(req)
def test_regex(req: RegexTestRequest) -> RegexTestResponse:
"""Validate a regex pattern using the shared log service."""
return _test_regex(req)