+id: dev
+rundir: etc/knot-resolver/runtime
+server:
+ workers: 1
+ management:
+ interface: 127.0.0.1@5000
cache:
storage: ../cache
logging:
network:
listen:
- interface: 127.0.0.1@5353
-server:
- id: dev
- workers: 1
- rundir: etc/knot-resolver/runtime
- management:
- interface: 127.0.0.1@5000
\ No newline at end of file
@property
def ID(self) -> str:
- return str(self._config_store.get().server.id)
+ return str(self._config_store.get().id)
_user_constants: Optional[_UserConstants] = None
async def _deny_id_changes(config_old: KresConfig, config_new: KresConfig) -> Result[None, str]:
- if config_old.server.id != config_new.server.id:
+ if config_old.id != config_new.id:
return Result.err(
"/id: Based on the ID, the manager recognizes subprocesses,"
" so it is not possible to change it while services are running."
import os
+import socket
import sys
from typing import Dict, Optional, Union
from knot_resolver_manager.datamodel.static_hints_schema import StaticHintsSchema
from knot_resolver_manager.datamodel.stub_zone_schema import StubZoneSchema
from knot_resolver_manager.datamodel.types import DomainName
+from knot_resolver_manager.datamodel.types.types import IDPattern, UncheckedPath
from knot_resolver_manager.datamodel.view_schema import ViewSchema
from knot_resolver_manager.utils import SchemaNode
Knot Resolver declarative configuration.
---
+ id: System-wide unique identifier of this instance. Used for grouping logs and tagging workers.
+ hostname: Internal DNS resolver hostname. Default is machine hostname.
+ rundir: Directory where the resolver can create files and which will be it's cwd.
server: DNS server control and management configuration.
options: Fine-tuning global parameters of DNS resolver operation.
network: Network connections and protocols configuration.
lua: Custom Lua configuration.
"""
- server: ServerSchema
+ id: IDPattern
+ hostname: Optional[str] = None
+ rundir: UncheckedPath = UncheckedPath(".")
+ server: ServerSchema = ServerSchema()
options: OptionsSchema = OptionsSchema()
network: NetworkSchema = NetworkSchema()
static_hints: StaticHintsSchema = StaticHintsSchema()
_PREVIOUS_SCHEMA = Raw
+ id: IDPattern
+ hostname: str
+ rundir: UncheckedPath
server: ServerSchema
options: OptionsSchema
network: NetworkSchema
monitoring: MonitoringSchema
lua: LuaSchema
+ def _hostname(self, obj: Raw) -> str:
+ if obj.hostname is None:
+ return socket.gethostname()
+ return obj.hostname
+
def _dnssec(self, obj: Raw) -> Union[Literal[False], DnssecSchema]:
if obj.dnssec is True:
return DnssecSchema()
import logging
import os
-import socket
from typing import Any, Optional, Union
from typing_extensions import Literal
InterfacePort,
IntPositive,
IPAddressPort,
- UncheckedPath,
)
-from knot_resolver_manager.datamodel.types.types import IDPattern
from knot_resolver_manager.exceptions import DataException
from knot_resolver_manager.utils import SchemaNode
DNS server control and management configuration.
---
- id: System-wide unique identifier of this manager instance. Used for grouping logs and tagging kresd processes.
- hostname: Internal DNS resolver hostname. Default is machine hostname.
workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available.
backend: Forces the manager to use a specific service supervisor.
watchdog: Disable systemd watchdog, enable with defaults or set new configuration. Can only be used with 'systemd' backend.
- rundir: Directory where the resolver can create files and which will be it's cwd.
management: Configuration of management HTTP API.
webmgmt: Configuration of legacy web management endpoint.
"""
- id: IDPattern
- hostname: Optional[str] = None
workers: Union[Literal["auto"], IntPositive] = IntPositive(1)
backend: BackendEnum = "auto"
watchdog: Union[bool, WatchDogSchema] = True
- rundir: UncheckedPath = UncheckedPath(".")
management: ManagementSchema = ManagementSchema({"unix-socket": "./manager.sock"})
webmgmt: Optional[WebmgmtSchema] = None
_PREVIOUS_SCHEMA = Raw
- id: IDPattern
- hostname: str
workers: IntPositive
backend: BackendEnum = "auto"
watchdog: Union[bool, WatchDogSchema]
- rundir: UncheckedPath = UncheckedPath(".")
management: ManagementSchema
webmgmt: Optional[WebmgmtSchema]
- def _hostname(self, obj: Raw) -> Any:
- if obj.hostname is None:
- return socket.gethostname()
- return obj.hostname
-
def _workers(self, obj: Raw) -> Any:
if obj.workers == "auto":
return IntPositive(_cpu_count())
{% if not cfg.lua.script_only %}
+-- hostname
+hostname('{{ cfg.hostname }}')
+
-- LOGGING section
{% include "logging.lua.j2" %}
--- server.hostname
-hostname('{{ cfg.server.hostname }}')
-
{% if cfg.server.watchdog -%}
-- server.watchdog
modules.load('watchdog')
async def _deny_working_directory_changes(config_old: KresConfig, config_new: KresConfig) -> Result[None, str]:
- if config_old.server.rundir != config_new.server.rundir:
+ if config_old.rundir != config_new.rundir:
return Result.err("Changing manager's `rundir` during runtime is not allowed.")
return Result.ok(None)
def _set_working_directory(config_raw: ParsedTree) -> None:
config = KresConfig(config_raw)
- if not config.server.rundir.to_path().exists():
- raise KresManagerException(f"`rundir` directory ({config.server.rundir}) does not exist!")
+ if not config.rundir.to_path().exists():
+ raise KresManagerException(f"`rundir` directory ({config.rundir}) does not exist!")
- os.chdir(config.server.rundir.to_path())
+ os.chdir(config.rundir.to_path())
def _lock_working_directory(attempt: int = 0) -> None:
def test_dnssec_false():
- config = KresConfig({"server": {"id": "test"}, "dnssec": False})
+ config = KresConfig({"id": "test", "dnssec": False})
assert config.dnssec == False
def test_dns64_prefix_default():
- assert str(KresConfig({"server": {"id": "test"}, "dns64": True}).dns64.prefix) == "64:ff9b::/96"
+ assert str(KresConfig({"id": "test", "dns64": True}).dns64.prefix) == "64:ff9b::/96"
def test_config_json_schema():
"""
Creates an instance of KresConfig without requiring any arguments.
"""
- return KresConfig({"server": {"id": "test"}})
+ return KresConfig({"id": "test"})