File: common_macros.lua.j2

package info (click to toggle)
knot-resolver 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,392 kB
  • sloc: javascript: 42,732; ansic: 40,312; python: 12,616; cpp: 2,121; sh: 1,997; xml: 193; makefile: 181
file content (101 lines) | stat: -rw-r--r-- 2,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{% macro quotes(string) -%}
'{{ string }}'
{%- endmacro %}

{% macro boolean(val, negation=false) -%}
{%- if negation -%}
{{ 'false' if val else 'true' }}
{%- else-%}
{{ 'true' if val else 'false' }}
{%- endif -%}
{%- endmacro %}

{# Return string or table of strings #}
{% macro string_table(table) -%}
{%- if table is string -%}
'{{ table|string }}'
{%- else-%}
{
{%- for item in table -%}
'{{ item|string }}',
{%- endfor -%}
}
{%- endif -%}
{%- endmacro %}

{# Return str2ip or table of str2ip #}
{% macro str2ip_table(table) -%}
{%- if table is string -%}
kres.str2ip('{{ table|string }}')
{%- else-%}
{
{%- for item in table -%}
kres.str2ip('{{ item|string }}'),
{%- endfor -%}
}
{%- endif -%}
{%- endmacro %}

{# Return qtype or table of qtype #}
{% macro qtype_table(table) -%}
{%- if table is string -%}
kres.type.{{ table|string }}
{%- else-%}
{
{%- for item in table -%}
kres.type.{{ item|string }},
{%- endfor -%}
}
{%- endif -%}
{%- endmacro %}

{# Return server address or table of server addresses #}
{% macro servers_table(servers) -%}
{%- if servers is string -%}
'{{ servers|string }}'
{%- else-%}
{
{%- for item in servers -%}
{%- if item.address is defined and item.address -%}
'{{ item.address|string }}',
{%- else -%}
'{{ item|string }}',
{%- endif -%}
{%- endfor -%}
}
{%- endif -%}
{%- endmacro %}

{# Return server address or table of server addresses #}
{% macro tls_servers_table(servers) -%}
{
{%- for item in servers -%}
{%- if item.address is defined and item.address -%}
{'{{ item.address|string }}',{{ tls_server_auth(item) }}},
{%- else -%}
'{{ item|string }}',
{%- endif -%}
{%- endfor -%}
}
{%- endmacro %}

{% macro tls_server_auth(server) -%}
{%- if server.hostname -%}
hostname='{{ server.hostname|string }}',
{%- endif -%}
{%- if server.ca_file -%}
ca_file='{{ server.ca_file|string }}',
{%- endif -%}
{%- if server.pin_sha256 -%}
pin_sha256=
{%- if server.pin_sha256 is string -%}
'{{ server.pin_sha256|string }}',
{%- else -%}
{
{%- for pin in server.pin_sha256 -%}
'{{ pin|string }}',
{%- endfor -%}
}
{%- endif -%}
{%- endif -%}
{%- endmacro %}