]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: allowed to get 'rundir' from default config
authorAleš Mrázek <ales.mrazek@nic.cz>
Mon, 19 Jun 2023 10:04:47 +0000 (12:04 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 19 Jun 2023 11:39:01 +0000 (13:39 +0200)
manager/knot_resolver_manager/datamodel/config_schema.py
manager/knot_resolver_manager/server.py

index c57a183f2f421cf8a5d019a017b3dfb6b7750912..4fdf5801d6636dad76ae8245ab1db90a7521b9c4 100644 (file)
@@ -205,9 +205,5 @@ def get_rundir_without_validation(data: Dict[str, Any]) -> Dir:
     """
 
     if "rundir" in data:
-        rundir = data["rundir"]
-    else:
-        _ = KresConfig(data)  # this should throw a descriptive error
-        assert False
-
-    return Dir(rundir, object_path="/rundir")
+        return Dir(data["rundir"], object_path="/rundir")
+    return KresConfig(data).rundir  # this should throw a descriptive error
index 88fb09902dab166730c896425e63ef2f6bed1f52..58e22e97c0579611ae0326d0da4a7ea216efeee0 100644 (file)
@@ -24,7 +24,11 @@ from knot_resolver_manager.compat import asyncio as asyncio_compat
 from knot_resolver_manager.config_store import ConfigStore
 from knot_resolver_manager.constants import DEFAULT_MANAGER_CONFIG_FILE, PID_FILE_NAME, init_user_constants
 from knot_resolver_manager.datamodel.config_schema import KresConfig, get_rundir_without_validation
-from knot_resolver_manager.datamodel.globals import Context, set_global_validation_context
+from knot_resolver_manager.datamodel.globals import (
+    Context,
+    reset_global_validation_context,
+    set_global_validation_context,
+)
 from knot_resolver_manager.datamodel.management_schema import ManagementSchema
 from knot_resolver_manager.exceptions import CancelStartupExecInsteadException, KresManagerException
 from knot_resolver_manager.kresd_controller import get_best_controller_implementation
@@ -476,10 +480,6 @@ async def start_server(config: Path = DEFAULT_MANAGER_CONFIG_FILE) -> int:
         # Make sure that the config path does not change meaning when we change working directory
         config = config.absolute()
 
-        # before processing any configuration, set validation context
-        #  - resolve_root = root against which all relative paths will be resolved
-        set_global_validation_context(Context(config.parent))
-
         # Preprocess config - load from file or in general take it to the last step before validation.
         config_raw = await _load_raw_config(config)
 
@@ -487,12 +487,18 @@ async def start_server(config: Path = DEFAULT_MANAGER_CONFIG_FILE) -> int:
         # working directory.
         #
         # If we fail to read rundir from unparsed config, the first config validation error comes from here
+        set_global_validation_context(Context(config.parent, False))  # Strict validation for Paths is off.
         _set_working_directory(config_raw)
+        reset_global_validation_context()
 
         # We don't want more than one manager in a single working directory. So we lock it with a PID file.
         # Warning - this does not prevent multiple managers with the same naming of kresd service.
         _lock_working_directory()
 
+        # before processing any configuration, set validation context
+        #  - resolve_root = root against which all relative paths will be resolved
+        set_global_validation_context(Context(config.parent))
+
         # After the working directory is set, we can initialize proper config store with a newly parsed configuration.
         config_store = await _init_config_store(config_raw)