]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Revert "datamodel: management socket default based on rundir"
authorAleš Mrázek <ales.mrazek@nic.cz>
Fri, 28 Feb 2025 09:07:35 +0000 (10:07 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 28 Feb 2025 09:07:35 +0000 (10:07 +0100)
This reverts commit 10fb87547af05cd78e76dfb94951c34f4554d090.

doc/_static/config.schema.json
python/knot_resolver/client/command.py
python/knot_resolver/datamodel/config_schema.py
tests/manager/datamodel/test_config_schema.py

index a429b15ddb5c869009378f6bab2aac8c39ef5061..0bedbbc4ed1b314e73bd6539b33142f0148b0452 100644 (file)
@@ -54,7 +54,7 @@
             "default": 256
         },
         "management": {
-            "description": "Configuration of management HTTP API. By default, unix-socket is located in 'rundir'.",
+            "description": "Configuration of management HTTP API.",
             "type": "object",
             "properties": {
                 "unix-socket": {
@@ -75,7 +75,7 @@
                 }
             },
             "default": {
-                "unix_socket": "kres-api.sock",
+                "unix_socket": "/run/knot-resolver/kres-api.sock",
                 "interface": null
             }
         },
index 464eb16e6186220f562b8c2fc5768fa38f68a759..3966f8ca93663b58cbe619cb665f982d3158471a 100644 (file)
@@ -4,7 +4,7 @@ from pathlib import Path
 from typing import Dict, List, Optional, Set, Tuple, Type, TypeVar
 from urllib.parse import quote
 
-from knot_resolver.constants import API_SOCK_FILE, API_SOCK_NAME, CONFIG_FILE, RUN_DIR
+from knot_resolver.constants import API_SOCK_FILE, CONFIG_FILE
 from knot_resolver.datamodel.types import IPAddressPort
 from knot_resolver.utils.modeling import parsing
 from knot_resolver.utils.modeling.exceptions import DataValidationError
@@ -154,38 +154,21 @@ def get_socket_from_config(config: Path, optional_file: bool) -> Optional[Socket
     try:
         with open(config, "r", encoding="utf8") as f:
             data = parsing.try_to_parse(f.read())
-
-        rkey = "rundir"
-        rundir = Path(data[rkey]) if rkey in data else RUN_DIR
-
         mkey = "management"
         if mkey in data:
             management = data[mkey]
-
-            ikey = "interface"
-            if ikey in data[mkey]:
-                ip = IPAddressPort(data[mkey][ikey], object_path=f"/{mkey}/{ikey}")
+            if "unix-socket" in management:
                 return SocketDesc(
-                    f"http://{ip.addr}:{ip.port}",
-                    f'Key "/management/interface" in "{config}" file',
+                    f'http+unix://{quote(management["unix-socket"], safe="")}/',
+                    f'Key "/management/unix-socket" in "{config}" file',
                 )
-
-            skey = "unix-socket"
-            if skey in management:
-                socket = Path(management[skey])
-                if not socket.is_absolute():
-                    socket = rundir / socket
+            if "interface" in management:
+                ip = IPAddressPort(management["interface"], object_path=f"/{mkey}/interface")
                 return SocketDesc(
-                    f'http+unix://{quote(str(socket), safe="")}/',
-                    f'Key "/management/unix-socket" in "{config}" file',
+                    f"http://{ip.addr}:{ip.port}",
+                    f'Key "/management/interface" in "{config}" file',
                 )
-
-        socket = rundir / API_SOCK_NAME
-        return SocketDesc(
-            f'http+unix://{quote(str(socket), safe="")}/',
-            f'Key "/rundir" in "{config}" file',
-        )
-
+        return None
     except ValueError as e:
         raise DataValidationError(*e.args) from e  # pylint: disable=no-value-for-parameter
     except OSError as e:
index f8733cb11e61c7649b821ecd6c9dbf5f8624db6b..410e94d7c9c3520d4f577d77d5ec319ed72f83b6 100644 (file)
@@ -1,10 +1,9 @@
 import logging
 import os
 import socket
-from pathlib import Path
 from typing import Any, Dict, List, Literal, Optional, Tuple, Union
 
-from knot_resolver.constants import API_SOCK_NAME, RUN_DIR, VERSION
+from knot_resolver.constants import API_SOCK_FILE, RUN_DIR, VERSION
 from knot_resolver.datamodel.cache_schema import CacheSchema
 from knot_resolver.datamodel.defer_schema import DeferSchema
 from knot_resolver.datamodel.dns64_schema import Dns64Schema
@@ -96,7 +95,7 @@ class KresConfig(ConfigSchema):
         rundir: Directory where the resolver can create files and which will be it's cwd.
         workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available.
         max_workers: The maximum number of workers allowed. Cannot be changed in runtime.
-        management: Configuration of management HTTP API. By default, unix-socket is located in 'rundir'.
+        management: Configuration of management HTTP API.
         webmgmt: Configuration of legacy web management endpoint.
         options: Fine-tuning global parameters of DNS resolver operation.
         network: Network connections and protocols configuration.
@@ -119,7 +118,7 @@ class KresConfig(ConfigSchema):
         rundir: WritableDir = lazy_default(WritableDir, str(RUN_DIR))
         workers: Union[Literal["auto"], IntPositive] = IntPositive(1)
         max_workers: IntPositive = IntPositive(WORKERS_MAX)
-        management: ManagementSchema = lazy_default(ManagementSchema, {"unix-socket": str(API_SOCK_NAME)})
+        management: ManagementSchema = lazy_default(ManagementSchema, {"unix-socket": str(API_SOCK_FILE)})
         webmgmt: Optional[WebmgmtSchema] = None
         options: OptionsSchema = OptionsSchema()
         network: NetworkSchema = NetworkSchema()
@@ -174,14 +173,6 @@ class KresConfig(ConfigSchema):
             )
         return obj.workers
 
-    def _management(self, obj: Raw) -> Any:
-        if obj.management.unix_socket:
-            soc = Path(obj.management.unix_socket.serialize())
-            if soc.is_absolute():
-                return obj.management
-            return ManagementSchema({"unix-socket": str(obj.rundir.to_path() / soc)})
-        return obj.management
-
     def _dnssec(self, obj: Raw) -> Any:
         if obj.dnssec is True:
             return DnssecSchema()
@@ -268,7 +259,7 @@ def kres_config_json_schema() -> Dict[str, Any]:
     """
 
     context = get_global_validation_context()
-    set_global_validation_context(Context(RUN_DIR, False))
+    set_global_validation_context(Context(None, False))
 
     schema = KresConfig.json_schema(
         schema_id=f"https://www.knot-resolver.cz/documentation/v{VERSION}/_static/config.schema.json",
index 437cade8d68dbd5e3d8e5190c56690d4b775661e..9ec2b31b281784bdaf8b2b4546a2c2a9522db743 100644 (file)
@@ -1,9 +1,7 @@
 import inspect
 import json
-import os
 from typing import Any, Dict, Type, cast
 
-from knot_resolver.constants import API_SOCK_FILE, API_SOCK_NAME, RUN_DIR
 from knot_resolver.datamodel import KresConfig
 from knot_resolver.datamodel.lua_schema import LuaSchema
 from knot_resolver.utils.modeling import BaseSchema
@@ -51,31 +49,10 @@ def test_config_check_str_type():
 def test_config_defaults():
     config = KresConfig()
 
-    # Management API default
-    assert config.management.unix_socket.to_path() == API_SOCK_FILE
-
     # DNS64 default
     assert config.dns64 == False
 
 
-def test_management_unix_socket():
-    cwd = os.getcwd()
-    config = KresConfig({"rundir": cwd})
-    assert str(config.management.unix_socket) == f"{cwd}/{API_SOCK_NAME}"
-
-    my_soc = "my-new.soc"
-    config = KresConfig({"management": {"unix-socket": my_soc}})
-    assert str(config.management.unix_socket) == f"{RUN_DIR}/{my_soc}"
-
-
-def test_management_interface():
-    cwd = os.getcwd()
-    config = KresConfig({"rundir": cwd, "management": {"interface": "127.0.0.1@5000"}})
-
-    assert config.management.unix_socket == None
-    assert str(config.management.interface) == "127.0.0.1@5000"
-
-
 def test_dnssec_false():
     config = KresConfig({"dnssec": False})