From: Aleš Mrázek Date: Thu, 6 Feb 2025 10:44:41 +0000 (+0100) Subject: datamodel: local-data: added watchdog for RPZSchema X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fenvironments%2Fdocs-develop-mana-rbp6vi%2Fdeployments%2F6318;p=thirdparty%2Fknot-resolver.git datamodel: local-data: added watchdog for RPZSchema --- 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):