]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: local-data/rules: allow more combinations
authorVladimír Čunát <vladimir.cunat@nic.cz>
Sat, 26 Aug 2023 16:31:47 +0000 (18:31 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 12 Sep 2023 10:12:55 +0000 (12:12 +0200)
It's perhaps the main use case for 'redirect' to also define address(es)
for the apex.  An empty zone with address(es) in apex also makes sense.

manager/knot_resolver_manager/datamodel/local_data_schema.py
manager/knot_resolver_manager/datamodel/templates/macros/local_data_macros.lua.j2

index 5e81c8cb1773ca9790971e73887f20b07798d3a4..8d7ff0697af318bae429ee45cd77c1014a3fac4c 100644 (file)
@@ -38,7 +38,9 @@ class RuleSchema(ConfigSchema):
 
     def _validate(self) -> None:
         options_sum = sum([bool(self.address), bool(self.subtree), bool(self.file)])
-        if options_sum > 1:
+        if options_sum == 2 and bool(self.address) and self.subtree in {"empty", "redirect"}:
+            pass # these combinations still make sense
+        elif options_sum > 1:
             raise ValueError("only one of 'address', 'subtree' or 'file' can be configured")
         elif options_sum < 1:
             raise ValueError("one of 'address', 'subtree' or 'file' must be configured")
@@ -46,6 +48,9 @@ class RuleSchema(ConfigSchema):
         if bool(self.file) == bool(self.name):
             raise ValueError("one of 'file' or 'name' must be configured")
 
+        if bool(self.nodata) and bool(self.subtree) and not bool(self.address):
+            raise ValueError("'nodata' defined but unused with 'subtree'")
+
 
 class RPZSchema(ConfigSchema):
     """
index 64f35088198594ab7fb85bb5dceb91a790523b07..92e010df356d532872e30de5e71405a0b923c973 100644 (file)
@@ -85,7 +85,8 @@ assert(C.kr_rule_local_subtree(todname('{{ name }}'),
 {% for address in item.address %}
 {{ kr_rule_local_address(name, address, nodata if item.nodata is none else item.nodata, item.ttl or ttl, item.tags) }}
 {% endfor %}
-{% elif item.subtree %}
+{% endif %}
+{% if item.subtree %}
 {{ kr_rule_local_subtree(name, item.subtree, item.ttl or ttl, item.tags) }}
 {% endif %}
 {% endfor %}