1
1
import logging
2
2
import os
3
3
import socket
4
+ from pathlib import Path
4
5
from typing import Any , Dict , List , Literal , Optional , Tuple , Union
5
6
6
- from knot_resolver .constants import API_SOCK_FILE , RUN_DIR , VERSION
7
+ from knot_resolver .constants import API_SOCK_NAME , RUN_DIR , VERSION
7
8
from knot_resolver .datamodel .cache_schema import CacheSchema
8
9
from knot_resolver .datamodel .defer_schema import DeferSchema
9
10
from knot_resolver .datamodel .dns64_schema import Dns64Schema
@@ -95,7 +96,7 @@ class Raw(ConfigSchema):
95
96
rundir: Directory where the resolver can create files and which will be it's cwd.
96
97
workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available.
97
98
max_workers: The maximum number of workers allowed. Cannot be changed in runtime.
98
- management: Configuration of management HTTP API.
99
+ management: Configuration of management HTTP API. By default, unix-socket is located in 'rundir'.
99
100
webmgmt: Configuration of legacy web management endpoint.
100
101
options: Fine-tuning global parameters of DNS resolver operation.
101
102
network: Network connections and protocols configuration.
@@ -118,7 +119,7 @@ class Raw(ConfigSchema):
118
119
rundir : WritableDir = lazy_default (WritableDir , str (RUN_DIR ))
119
120
workers : Union [Literal ["auto" ], IntPositive ] = IntPositive (1 )
120
121
max_workers : IntPositive = IntPositive (WORKERS_MAX )
121
- management : ManagementSchema = lazy_default (ManagementSchema , {"unix-socket" : str (API_SOCK_FILE )})
122
+ management : ManagementSchema = lazy_default (ManagementSchema , {"unix-socket" : str (API_SOCK_NAME )})
122
123
webmgmt : Optional [WebmgmtSchema ] = None
123
124
options : OptionsSchema = OptionsSchema ()
124
125
network : NetworkSchema = NetworkSchema ()
@@ -173,6 +174,14 @@ def _workers(self, obj: Raw) -> Any:
173
174
)
174
175
return obj .workers
175
176
177
+ def _management (self , obj : Raw ) -> Any :
178
+ if obj .management .unix_socket :
179
+ soc = Path (obj .management .unix_socket .serialize ())
180
+ if soc .is_absolute ():
181
+ return obj .management
182
+ return ManagementSchema ({"unix-socket" : str (obj .rundir .to_path () / soc )})
183
+ return obj .management
184
+
176
185
def _dnssec (self , obj : Raw ) -> Any :
177
186
if obj .dnssec is True :
178
187
return DnssecSchema ()
@@ -259,7 +268,7 @@ def kres_config_json_schema() -> Dict[str, Any]:
259
268
"""
260
269
261
270
context = get_global_validation_context ()
262
- set_global_validation_context (Context (None , False ))
271
+ set_global_validation_context (Context (RUN_DIR , False ))
263
272
264
273
schema = KresConfig .json_schema (
265
274
schema_id = f"https://www.knot-resolver.cz/documentation/v{ VERSION } /_static/config.schema.json" ,
0 commit comments