]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: /local-data/subtrees/*: drop parts that are not implemented
authorVladimír Čunát <vladimir.cunat@nic.cz>
Sat, 12 Aug 2023 11:13:59 +0000 (13:13 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 12 Sep 2023 10:12:55 +0000 (12:12 +0200)
Otherwise we'd let confusing things pass all validations.

manager/knot_resolver_manager/datamodel/local_data_schema.py
manager/tests/unit/datamodel/test_local_data.py

index b782d8e793a46454c021ab3c38c68e7fc673fa57..c9a73593dca4189723741e15deb2abd4917deb06 100644 (file)
@@ -23,31 +23,37 @@ class SubtreeSchema(ConfigSchema):
     tags: Tags to link with other policy rules.
     ttl: Default TTL value used for added local subtree.
     nodata: Use NODATA synthesis. NODATA will be synthesised for matching name, but mismatching type(e.g. AAAA query when only A exists).
-    addresses: Subtree addresses.
     roots: Subtree roots.
-    roots_file: Subtree roots from given file.
-    roots_url: Subtree roots form given URL.
-    refresh: Refresh time to update data from 'roots-file' or 'roots-url'.
     """
 
+    # addresses: Subtree addresses.
+    # roots_file: Subtree roots from given file.
+    # roots_url: Subtree roots form given URL.
+    # refresh: Refresh time to update data from 'roots-file' or 'roots-url'.
+
     type: Literal["empty", "nxdomain", "redirect"]
     tags: Optional[List[IDPattern]] = None
     ttl: Optional[TimeUnit] = None
     nodata: bool = True
-    addresses: Optional[List[IPAddress]] = None
     roots: Optional[List[DomainName]] = None
-    roots_file: Optional[File] = None
-    roots_url: Optional[EscapedStr] = None
-    refresh: Optional[TimeUnit] = None
 
+    # # These aren't implemented yet.
+    # addresses: Optional[List[IPAddress]] = None
+    # roots_file: Optional[File] = None
+    # roots_url: Optional[EscapedStr] = None
+    # refresh: Optional[TimeUnit] = None
+
+    # def _validate(self) -> None:
+    #    options_sum = sum([bool(self.roots), bool(self.roots_file), bool(self.roots_url)])
+    #    if options_sum > 1:
+    #        raise ValueError("only one of, 'roots', 'roots-file' or 'roots-url' can be configured")
+    #    elif options_sum < 1:
+    #        raise ValueError("one of, 'roots', 'roots-file' or 'roots-url' must be configured")
+    #    if self.refresh and not (self.roots_file or self.roots_url):
+    #        raise ValueError("'refresh' can be only configured with 'roots-file' or 'roots-url'")
     def _validate(self) -> None:
-        options_sum = sum([bool(self.roots), bool(self.roots_file), bool(self.roots_url)])
-        if options_sum > 1:
-            raise ValueError("only one of, 'roots', 'roots-file' or 'roots-url' can be configured")
-        elif options_sum < 1:
-            raise ValueError("one of, 'roots', 'roots-file' or 'roots-url' must be configured")
-        if self.refresh and not (self.roots_file or self.roots_url):
-            raise ValueError("'refresh' can be only configured with 'roots-file' or 'roots-url'")
+        if self.roots is None:
+            raise ValueError("'roots' is missing")
 
 
 class RPZSchema(ConfigSchema):
index fe529777a3e104ecd3b960b8e1e7076a37605eed..3ad6dd7dc74df056bc7065f084944a61e22c453c 100644 (file)
@@ -11,9 +11,10 @@ from knot_resolver_manager.utils.modeling.exceptions import DataValidationError
     "val",
     [
         {"type": "empty", "roots": ["sub2.example.org"]},
-        {"type": "empty", "roots-url": "https://example.org/blocklist.txt", "refresh": "1d"},
-        {"type": "nxdomain", "roots-file": "/etc/hosts"},  # must be an existing file or validation will fail
-        {"type": "redirect", "roots": ["sub4.example.org"], "addresses": ["127.0.0.1", "::1"]},
+        {"type": "nxdomain", "roots": ["sub3.example.org", "sub5.example.net."], "ttl": "1h"},
+        # {"type": "empty", "roots-url": "https://example.org/blocklist.txt", "refresh": "1d"},
+        # {"type": "nxdomain", "roots-file": "/etc/hosts"},  # must be an existing file or validation will fail
+        {"type": "redirect", "roots": ["sub4.example.org"]},
     ],
 )
 def test_subtree_valid(val: Any):