]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: local-data: added watchdog for RPZSchema
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 6 Feb 2025 10:44:41 +0000 (11:44 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 1 Apr 2025 14:09:12 +0000 (16:09 +0200)
doc/_static/config.schema.json
python/knot_resolver/datamodel/local_data_schema.py

index 0bedbbc4ed1b314e73bd6539b33142f0148b0452..754403734593b0883c841125a729260247674051 100644 (file)
                                 "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",
index ee22977849b4a01a713d12a682d2903cfc3fbe9a..478a0e2310ef6d6fd02519310666a9e64a501352 100644 (file)
@@ -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) -> None:
+        if self.watchdog and not WATCHDOG_LIB:
+            raise ValueError(
+                "'watchdog' is enabled, but the required 'watchdog' dependency (optional) is not installed"
+            )
 
 
 class LocalDataSchema(ConfigSchema):