From: Aleš Mrázek Date: Fri, 28 Feb 2025 09:17:17 +0000 (+0100) Subject: client: command: get_socket_from_config improved X-Git-Tag: v6.0.12~12^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c467aceded3cfa6eb077439d63b8637d17155c3;p=thirdparty%2Fknot-resolver.git client: command: get_socket_from_config improved --- diff --git a/python/knot_resolver/client/command.py b/python/knot_resolver/client/command.py index 3966f8ca9..7a679885a 100644 --- a/python/knot_resolver/client/command.py +++ b/python/knot_resolver/client/command.py @@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Tuple, Type, TypeVar from urllib.parse import quote from knot_resolver.constants import API_SOCK_FILE, CONFIG_FILE -from knot_resolver.datamodel.types import IPAddressPort +from knot_resolver.datamodel.types import IPAddressPort, WritableFilePath from knot_resolver.utils.modeling import parsing from knot_resolver.utils.modeling.exceptions import DataValidationError from knot_resolver.utils.requests import SocketDesc @@ -154,16 +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()) + mkey = "management" if mkey in data: management = data[mkey] - if "unix-socket" in management: + + skey = "unix-socket" + if skey in management: + sock = WritableFilePath(management[skey], object_path=f"/{mkey}/{skey}") return SocketDesc( - f'http+unix://{quote(management["unix-socket"], safe="")}/', + f'http+unix://{quote(str(sock), safe="")}/', f'Key "/management/unix-socket" in "{config}" file', ) - if "interface" in management: - ip = IPAddressPort(management["interface"], object_path=f"/{mkey}/interface") + ikey = "interface" + if ikey in data[mkey]: + ip = IPAddressPort(management[ikey], object_path=f"/{mkey}/{ikey}") return SocketDesc( f"http://{ip.addr}:{ip.port}", f'Key "/management/interface" in "{config}" file',