]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: templates: fix undefined variables and attributes docs-develop-loca-69s24w/deployments/6478
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 27 Mar 2025 12:07:56 +0000 (13:07 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Thu, 27 Mar 2025 12:07:56 +0000 (13:07 +0100)
python/knot_resolver/datamodel/templates/macros/common_macros.lua.j2
python/knot_resolver/datamodel/templates/macros/forward_macros.lua.j2
python/knot_resolver/datamodel/templates/macros/policy_macros.lua.j2
python/knot_resolver/datamodel/templates/rate_limiting.lua.j2
tests/manager/datamodel/templates/test_policy_macros.py

index 4c2ba11a8e55c90d37c47a44f53e864a8cb10697..a599bee0bbd40ea545117a337c0c630caf27abcb 100644 (file)
@@ -56,7 +56,7 @@ kres.type.{{ item|string }},
 {%- else-%}
 {
 {%- for item in servers -%}
-{%- if item.address -%}
+{%- if item.address is defined and item.address -%}
 '{{ item.address|string }}',
 {%- else -%}
 '{{ item|string }}',
@@ -70,7 +70,7 @@ kres.type.{{ item|string }},
 {% macro tls_servers_table(servers) -%}
 {
 {%- for item in servers -%}
-{%- if item.address -%}
+{%- if item.address is defined and item.address -%}
 {'{{ item.address|string }}',{{ tls_server_auth(item) }}},
 {%- else -%}
 '{{ item|string }}',
index b7723fb0719dc76fe02272046d193f8c4a01c767..1f3549b168c866ee656aba0d6b86d46d17d1a993 100644 (file)
@@ -5,7 +5,7 @@
 {%- endmacro %}
 
 {% macro forward_server(server) -%}
-{%- if server.address -%}
+{%- if server.address is defined and server.address-%}
 {%- for addr in server.address -%}
 {'{{ addr }}',
 {%- if server.transport == 'tls' -%}
index 94683356723b1be6f83f27b47dde4c48eeaa728d..b89d0e3f2b3d2c470f32f23a09861f46ef42eaf6 100644 (file)
@@ -56,7 +56,7 @@ policy.TAGS_ASSIGN({{ string_table(tags) }})
 {%- endmacro %}
 
 {% macro policy_get_tagset(tags) -%}
-{%- if tags -%}
+{%- if tags is defined and tags-%}
 policy.get_tagset({{ string_table(tags) }})
 {%- else -%}
 0
index 63f92125717fd997da8014f7dadf168b1e31dcb4..1f2a546d082f0dd90ab8fead7606d5d5562f14b6 100644 (file)
@@ -1,6 +1,6 @@
 {% from 'macros/common_macros.lua.j2' import boolean %}
 
-{% if cfg.rate_limiting.rate_limit -%}
+{% if cfg.rate_limiting.rate_limit is defined and cfg.rate_limiting.rate_limit -%}
 assert(C.ratelimiting_init(
        '{{ cfg.rundir }}/ratelimiting',
        {{ cfg.rate_limiting.capacity }},
index 09aac85de283838894907cb1d6a13682ecf19b88..5fded1b4c928c315f6cc781d9f6a23027949a854 100644 (file)
@@ -66,7 +66,7 @@ def test_policy_suffix_common():
 {{ policy_suffix_common(action, suffix, common) }}"""
 
     tmpl = template_from_str(tmpl_str)
-    assert tmpl.render(action=action, suffix=suffix) == f"policy.suffix_common({action},{suffix})"
+    assert tmpl.render(action=action, suffix=suffix, common=None) == f"policy.suffix_common({action},{suffix})"
     assert (
         tmpl.render(action=action, suffix=suffix, common=common) == f"policy.suffix_common({action},{suffix},{common})"
     )
@@ -89,7 +89,7 @@ def test_policy_rpz():
 {{ policy_rpz(action, path, watch) }}"""
 
     tmpl = template_from_str(tmpl_str)
-    assert tmpl.render(action=action, path=path) == f"policy.rpz({action},'{path}',false)"
+    assert tmpl.render(action=action, path=path, watch=False) == f"policy.rpz({action},'{path}',false)"
     assert tmpl.render(action=action, path=path, watch=True) == f"policy.rpz({action},'{path}',true)"