Skip to content

Commit

Permalink
Simplify the ng.config template
Browse files Browse the repository at this point in the history
Use join and indent in an easier way to align multiple entries.
Contrary to the comment, it is possible to check for lists in jinja,
which makes the template much less complex.
  • Loading branch information
ixs authored and athienem committed Oct 27, 2018
1 parent af8be8b commit e09fbbf
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions fail2ban/ng/files/config.jinja
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#
# This file is managed by salt. Do not edit by hand.
#
{% macro print_config(name, value) %}
{%- set name_length = name|length %}
{%- if value is string %}
{{ name }} = {{ value }}
{%- elif value is number %}
{{ name }} = {{ value }}
{%- else %}
{#- Since strings are also sequences, there's no way to explicitly test for lists #}
{{ name }} = {{ value|first }}
{%- if value|length > 1 %}
{%- for item in value[1:] %}
{{ item|indent(width=name_length + 3, indentfirst=True) }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- macro print_config(name, value) %}
{%- if value is iterable and value is not string %}
{{ name }} = {{ value | join('\n') | indent(name | length + 3) }}
{%- else %}
{{ name }} = {{ value }}
{%- endif %}
{%- endmacro %}

{%- for section, section_data in config|dictsort %}
Expand Down

0 comments on commit e09fbbf

Please sign in to comment.