From 03f29dc0b8b357fb4c6eca44d8ed5ba0fa2097a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20Mr=C3=A1zek?= Date: Thu, 6 Feb 2025 11:44:41 +0100 Subject: [PATCH] datamodel: local-data: added watchdog for RPZSchema --- doc/_static/config.schema.json | 15 ++++++++ .../datamodel/local_data_schema.py | 37 +++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/doc/_static/config.schema.json b/doc/_static/config.schema.json index 0bedbbc4e..754403734 100644 --- a/doc/_static/config.schema.json +++ b/doc/_static/config.schema.json @@ -928,6 +928,21 @@ "type": "string", "description": "Path to the RPZ zone file." }, + "watchdog": { + "anyOf": [ + { + "type": "string", + "enum": [ + "auto" + ] + }, + { + "type": "boolean" + } + ], + "description": "Enables files watchdog for configured RPZ file. Requires the optional 'watchdog' dependency.", + "default": "auto" + }, "tags": { "type": [ "array", diff --git a/python/knot_resolver/datamodel/local_data_schema.py b/python/knot_resolver/datamodel/local_data_schema.py index ee2297784..8c2f97fdd 100644 --- a/python/knot_resolver/datamodel/local_data_schema.py +++ b/python/knot_resolver/datamodel/local_data_schema.py @@ -1,5 +1,6 @@ -from typing import Dict, List, Literal, Optional +from typing import Any, Dict, List, Literal, Optional, Union +from knot_resolver.constants import WATCHDOG_LIB from knot_resolver.datamodel.types import ( DomainName, EscapedStr, @@ -54,16 +55,36 @@ class RuleSchema(ConfigSchema): class RPZSchema(ConfigSchema): - """ - Configuration or Response Policy Zone (RPZ). + class Raw(ConfigSchema): + """ + Configuration or Response Policy Zone (RPZ). - --- - file: Path to the RPZ zone file. - tags: Tags to link with other policy rules. - """ + --- + file: Path to the RPZ zone file. + watchdog: Enables files watchdog for configured RPZ file. Requires the optional 'watchdog' dependency. + tags: Tags to link with other policy rules. + """ + + file: ReadableFile + watchdog: Union[Literal["auto"], bool] = "auto" + tags: Optional[List[IDPattern]] = None + + _LAYER = Raw file: ReadableFile - tags: Optional[List[IDPattern]] = None + watchdog: bool + tags: Optional[List[IDPattern]] + + def _watchdog(self, obj: Raw) -> Any: + if obj.watchdog == "auto": + return WATCHDOG_LIB + return obj.watchdog + + def _validate(self): + if self.watchdog and not WATCHDOG_LIB: + raise ValueError( + "'watchdog' is enabled, but the required 'watchdog' dependency (optional) is not installed" + ) class LocalDataSchema(ConfigSchema): -- 2.47.2