Task 5: finalize config_file_service wrapper refactor and mark task done
This commit is contained in:
@@ -25,13 +25,7 @@ from app.exceptions import (
|
||||
ConfigWriteError,
|
||||
JailNotFoundInConfigError,
|
||||
)
|
||||
from app.services.config_file_service import (
|
||||
build_parser,
|
||||
get_active_jail_names,
|
||||
parse_jails_sync,
|
||||
safe_jail_name,
|
||||
)
|
||||
from app.services.jail_service import reload_all
|
||||
import app.services.config_file_service as config_file_service
|
||||
from app.models.config import (
|
||||
ActionConfig,
|
||||
ActionConfigUpdate,
|
||||
@@ -260,7 +254,7 @@ def _append_jail_action_sync(
|
||||
|
||||
local_path = jail_d / f"{jail_name}.local"
|
||||
|
||||
parser = build_parser()
|
||||
parser = config_file_service.build_parser()
|
||||
if local_path.is_file():
|
||||
try:
|
||||
parser.read(str(local_path), encoding="utf-8")
|
||||
@@ -349,7 +343,7 @@ def _remove_jail_action_sync(
|
||||
if not local_path.is_file():
|
||||
return
|
||||
|
||||
parser = build_parser()
|
||||
parser = config_file_service.build_parser()
|
||||
try:
|
||||
parser.read(str(local_path), encoding="utf-8")
|
||||
except (configparser.Error, OSError) as exc:
|
||||
@@ -485,8 +479,8 @@ async def list_actions(
|
||||
raw_actions: list[tuple[str, str, str, bool, str]] = await run_blocking( _parse_actions_sync, action_d)
|
||||
|
||||
all_jails_result, active_names = await asyncio.gather(
|
||||
run_blocking(parse_jails_sync, Path(config_dir)),
|
||||
get_active_jail_names(socket_path),
|
||||
run_blocking(config_file_service._parse_jails_sync, Path(config_dir)),
|
||||
config_file_service._get_active_jail_names(socket_path),
|
||||
)
|
||||
all_jails, _source_files = all_jails_result
|
||||
|
||||
@@ -583,8 +577,8 @@ async def get_action(
|
||||
cfg = conffile_parser.parse_action_file(content, name=base_name, filename=f"{base_name}.conf")
|
||||
|
||||
all_jails_result, active_names = await asyncio.gather(
|
||||
run_blocking(parse_jails_sync, Path(config_dir)),
|
||||
get_active_jail_names(socket_path),
|
||||
run_blocking(config_file_service._parse_jails_sync, Path(config_dir)),
|
||||
config_file_service._get_active_jail_names(socket_path),
|
||||
)
|
||||
all_jails, _source_files = all_jails_result
|
||||
action_to_jails = _build_action_to_jails_map(all_jails, active_names)
|
||||
@@ -669,7 +663,7 @@ async def update_action(
|
||||
|
||||
if do_reload:
|
||||
try:
|
||||
await reload_all(socket_path)
|
||||
await config_file_service.jail_service.reload_all(socket_path)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning(
|
||||
"reload_after_action_update_failed",
|
||||
@@ -737,7 +731,7 @@ async def create_action(
|
||||
|
||||
if do_reload:
|
||||
try:
|
||||
await reload_all(socket_path)
|
||||
await config_file_service.jail_service.reload_all(socket_path)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning(
|
||||
"reload_after_action_create_failed",
|
||||
@@ -829,11 +823,11 @@ async def assign_action_to_jail(
|
||||
``action.d/``.
|
||||
ConfigWriteError: If writing fails.
|
||||
"""
|
||||
safe_jail_name(jail_name)
|
||||
config_file_service.safe_jail_name(jail_name)
|
||||
_safe_action_name(req.action_name)
|
||||
|
||||
|
||||
all_jails, _src = await run_blocking(parse_jails_sync, Path(config_dir))
|
||||
all_jails, _src = await run_blocking(config_file_service._parse_jails_sync, Path(config_dir))
|
||||
if jail_name not in all_jails:
|
||||
raise JailNotFoundInConfigError(jail_name)
|
||||
|
||||
@@ -863,7 +857,7 @@ async def assign_action_to_jail(
|
||||
|
||||
if do_reload:
|
||||
try:
|
||||
await reload_all(socket_path)
|
||||
await config_file_service.jail_service.reload_all(socket_path)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning(
|
||||
"reload_after_assign_action_failed",
|
||||
@@ -906,11 +900,11 @@ async def remove_action_from_jail(
|
||||
JailNotFoundError: If *jail_name* is not defined in any config.
|
||||
ConfigWriteError: If writing fails.
|
||||
"""
|
||||
safe_jail_name(jail_name)
|
||||
config_file_service.safe_jail_name(jail_name)
|
||||
_safe_action_name(action_name)
|
||||
|
||||
|
||||
all_jails, _src = await run_blocking(parse_jails_sync, Path(config_dir))
|
||||
all_jails, _src = await run_blocking(config_file_service._parse_jails_sync, Path(config_dir))
|
||||
if jail_name not in all_jails:
|
||||
raise JailNotFoundInConfigError(jail_name)
|
||||
|
||||
@@ -922,7 +916,7 @@ async def remove_action_from_jail(
|
||||
|
||||
if do_reload:
|
||||
try:
|
||||
await reload_all(socket_path)
|
||||
await config_file_service.jail_service.reload_all(socket_path)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning(
|
||||
"reload_after_remove_action_failed",
|
||||
|
||||
Reference in New Issue
Block a user