-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathknot-template.conf.jinja
78 lines (75 loc) · 2.37 KB
/
knot-template.conf.jinja
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
{# mandatory context: settings, log_default, template_default #}
{%- set dns = settings %}
{%- if dns.log is not defined %}
{% do dns.update( {'log', log_default} ) %}
{%- endif %}
{%- if dns.template is not defined %}
{%- do dns.update( {'template', [template_default]} ) %}
{%- endif %}
{%- if dns.template|selectattr('id', 'equalto', 'default')|map(attribute='id')|first != 'default' %}
{%- set template = dns.template+ [template_default] %}
{%- do dns.update( {'template', template} ) %}
{%- endif %}
{%- do dns.pop('enabled') %}
{%- for z in range(dns.zone|length) %}
{%- if dns.zone[z].source is defined %}
{%- do dns.zone[z].pop('source') %}
{%- endif %}
{%- if dns.zone[z].context is defined %}
{%- do dns.zone[z].pop('context') %}
{%- endif %}
{%- if dns.zone[z].contents is defined %}
{%- do dns.zone[z].pop('contents') %}
{%- endif %}
{%- endfor %}
{%- macro iter_first(data, section, keyname) %}
{%- if data[section] is defined %}
{{ section }}:
{%- for i in data[section] %}
- {{ keyname }}: {{ i[keyname] }}
{%- for v,d in i.items() %}
{%- if v != keyname %}
{%- if d is iterable and d is not string and d|length > 1 %}
{{ v }}: [{{ d|join(',') }}]
{%- elif d is iterable and d is not string and d|length == 1 %}
{{ v }}: {{ d[0] }}
{%- else %}
{{ v }}: {{ d }}
{%- endif %}
{%- endif %}
{%- endfor %}
{% endfor %}
{%- endif %}
{%- endmacro %}
{%- if dns.server is defined %}
server:
{%- for k,v in dns.server.items() %}
{%- if k == 'listen' and v is iterable and v is not string and v|length > 1 %}
listen: [{{ v|join(',') }}]
{%- else %}
{{ k }}: {{ v }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if dns.control is defined %}
control:
{{ dns.control|yaml(False)|indent(2,True) }}
{%- endif %}
{%- if dns.statistics is defined %}
statistics:
{{ dns.statistics|yaml(False)|indent(2,True) }}
{%- endif %}
{%- if dns.database is defined %}
database:
{{ dns.database|yaml(False)|indent(2,True) }}
{%- endif %}
{{ iter_first (dns, 'module', 'id') }}
{{ iter_first (dns, 'log', 'target') }}
{{ iter_first (dns, 'keystore', 'id') }}
{{ iter_first (dns, 'submission', 'id') }}
{{ iter_first (dns, 'policy', 'id') }}
{{ iter_first (dns, 'key', 'id') }}
{{ iter_first (dns, 'remote', 'id') }}
{{ iter_first (dns, 'acl', 'id') }}
{{ iter_first (dns, 'template', 'id') }}
{{ iter_first (dns, 'zone', 'domain') }}