]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
jinja2: some fixes for using StrictUndefined
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 26 Sep 2023 19:52:56 +0000 (21:52 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 9 Oct 2023 11:22:58 +0000 (13:22 +0200)
manager/knot_resolver_manager/datamodel/templates/macros/common_macros.lua.j2
manager/knot_resolver_manager/datamodel/templates/macros/forward_macros.lua.j2
manager/knot_resolver_manager/datamodel/templates/macros/policy_macros.lua.j2
manager/tests/unit/datamodel/templates/test_policy_macros.py

index 4c2ba11a8e55c90d37c47a44f53e864a8cb10697..da5bcf4a9678eeec3f83fb310c210c2d01357885 100644 (file)
@@ -14,7 +14,7 @@
 {% macro string_table(table) -%}
 {%- if table is string -%}
 '{{ table|string }}'
-{%- else-%}
+{%- elif table -%}
 {
 {%- for item in table -%}
 '{{ item|string }}',
@@ -56,7 +56,7 @@ kres.type.{{ item|string }},
 {%- else-%}
 {
 {%- for item in servers -%}
-{%- if item.address -%}
+{%- if item.address is defined -%}
 '{{ 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-%}
 {'{{ item.address|string }}',{{ tls_server_auth(item) }}},
 {%- else -%}
 '{{ item|string }}',
index b7723fb0719dc76fe02272046d193f8c4a01c767..d53f380d93355e6d17dbfe9a3d2135906439aaaf 100644 (file)
@@ -5,7 +5,7 @@
 {%- endmacro %}
 
 {% macro forward_server(server) -%}
-{%- if server.address -%}
+{% if server.address is defined %}
 {%- for addr in server.address -%}
 {'{{ addr }}',
 {%- if server.transport == 'tls' -%}
index 347532e6ba7272d44e8e6001e174cfcf6f14254b..fece212e5e5d4bc83f0cd3d096d96555b0d5b4e0 100644 (file)
@@ -49,7 +49,7 @@ policy.TAGS_ASSIGN({{ string_table(tags) }})
 {%- endmacro %}
 
 {% macro policy_get_tagset(tags) -%}
-{%- if tags -%}
+{%- if tags is defined-%}
 policy.get_tagset({{ string_table(tags) }})
 {%- else -%}
 0
index 2920a2069b1cd96846fd434c8bf17d5bedbc37f8..60646670b57db558165e9d4e7ff5ab1b7240ec86 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=None) == f"policy.rpz({action},'{path}',false)"
     assert tmpl.render(action=action, path=path, watch=True) == f"policy.rpz({action},'{path}',true)"