Skip to content

Commit

Permalink
Merge pull request #2 from SuperTux88/fix-config-template
Browse files Browse the repository at this point in the history
Extend and cleanup config template
  • Loading branch information
javierbertoli authored Jul 11, 2020
2 parents f85dbd5 + 762f6fd commit b069929
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions rspamd/service.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rspamd_service:
service.running:
- name: {{ rspamd.service.name }}
- enable: true
- reload: true
30 changes: 11 additions & 19 deletions rspamd/templates/config.jinja
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{%- set control_params = ['module','enable'] %}
{%- set ind_increment = 4 %}
{%- macro _config(attr, ind=4, operator=' = ') -%}
{%- for n, v in attr.items() %}
{%- macro _config(attr, ind=0, operator=' = ') -%}
{#- We skip the module and enable params on first level #}
{%- for n, v in attr.items() if n not in control_params or ind != 0 %}
{%- set operator=' ' if n.startswith('.include') else ' = ' %}
{%- if v is string %}
{%- if v | regex_match('^([0-9]*[smhd])$') %}
{{ n|indent(ind, True) }}{{ operator }}{{ v }};
{%- else %}
{{ n|indent(ind, True) }}{{ operator }}"{{ v }}";
{%- endif %}
{%- elif v is number %}
{{ n|indent(ind, True) }}{{ operator }}{{ v }};
{%- elif v is mapping %}
{{ n|indent(ind, True) }}{{ operator }}{{ v|json }};
{%- elif v is mapping %}
{{ n|indent(ind, True) }} {
{{ _config(v, ind+ind_increment) }}
{{- _config(v, ind+ind_increment) }}
{{ '}'|indent(ind, True) }}
{%- elif v is iterable %}
{{ n|indent(ind, True) }}{{ operator }}["{{ v |join('", "') }}"];
Expand All @@ -19,17 +24,4 @@
# This file managed by Salt, do not edit by hand!!
# Modify the salt pillar for rspamd, instead.
#
{%- for k, v in data.items() %}
{#- We skip the module and enable params #}
{%- if k not in control_params %}
{%- if v is string %}
{{ k }} = "{{ v }}";
{%- elif v is number %}
{{ k }} = {{ v }};
{%- elif v is mapping %}
{{ k }} {
{{ _config(v) }}
};
{%- endif %}
{%- endif %}
{%- endfor %}
{{ _config(data) }}

0 comments on commit b069929

Please sign in to comment.