Skip to content

Commit b069929

Browse files
Merge pull request #2 from SuperTux88/fix-config-template
Extend and cleanup config template
2 parents f85dbd5 + 762f6fd commit b069929

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

rspamd/service.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ rspamd_service:
1616
service.running:
1717
- name: {{ rspamd.service.name }}
1818
- enable: true
19+
- reload: true

rspamd/templates/config.jinja

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{%- set control_params = ['module','enable'] %}
22
{%- set ind_increment = 4 %}
3-
{%- macro _config(attr, ind=4, operator=' = ') -%}
4-
{%- for n, v in attr.items() %}
3+
{%- macro _config(attr, ind=0, operator=' = ') -%}
4+
{#- We skip the module and enable params on first level #}
5+
{%- for n, v in attr.items() if n not in control_params or ind != 0 %}
56
{%- set operator=' ' if n.startswith('.include') else ' = ' %}
67
{%- if v is string %}
8+
{%- if v | regex_match('^([0-9]*[smhd])$') %}
9+
{{ n|indent(ind, True) }}{{ operator }}{{ v }};
10+
{%- else %}
711
{{ n|indent(ind, True) }}{{ operator }}"{{ v }}";
12+
{%- endif %}
813
{%- elif v is number %}
9-
{{ n|indent(ind, True) }}{{ operator }}{{ v }};
10-
{%- elif v is mapping %}
14+
{{ n|indent(ind, True) }}{{ operator }}{{ v|json }};
15+
{%- elif v is mapping %}
1116
{{ n|indent(ind, True) }} {
12-
{{ _config(v, ind+ind_increment) }}
17+
{{- _config(v, ind+ind_increment) }}
1318
{{ '}'|indent(ind, True) }}
1419
{%- elif v is iterable %}
1520
{{ n|indent(ind, True) }}{{ operator }}["{{ v |join('", "') }}"];
@@ -19,17 +24,4 @@
1924
# This file managed by Salt, do not edit by hand!!
2025
# Modify the salt pillar for rspamd, instead.
2126
#
22-
{%- for k, v in data.items() %}
23-
{#- We skip the module and enable params #}
24-
{%- if k not in control_params %}
25-
{%- if v is string %}
26-
{{ k }} = "{{ v }}";
27-
{%- elif v is number %}
28-
{{ k }} = {{ v }};
29-
{%- elif v is mapping %}
30-
{{ k }} {
31-
{{ _config(v) }}
32-
};
33-
{%- endif %}
34-
{%- endif %}
35-
{%- endfor %}
27+
{{ _config(data) }}

0 commit comments

Comments
 (0)