From c432ae23dcc2b932a4431df952e3a04dbda85fd0 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Tue, 9 Apr 2019 20:06:16 +0200 Subject: [PATCH 1/3] mapping.j2: fixed handling of OrderedDict in Python 3 --- postfix/files/mapping.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/postfix/files/mapping.j2 b/postfix/files/mapping.j2 index 1e564c6..7daf28d 100644 --- a/postfix/files/mapping.j2 +++ b/postfix/files/mapping.j2 @@ -21,6 +21,7 @@ {%- else %} {#- Some settings need order, handle OrderedDict #} {% for item in data %} -{{ format_value(item.keys()[0], item.values()[0]) }} +{%- set key, value = item.popitem() %} +{{ format_value(key, value) }} {%- endfor -%} {%- endif %} From bb6746c5b7da5b4f3f03c0f23be5f62e13e81e60 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Tue, 9 Apr 2019 20:47:45 +0200 Subject: [PATCH 2/3] Explain multiple entries in virtual_alias_maps via pillar.example --- pillar.example | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pillar.example b/pillar.example index 9108208..e905d66 100644 --- a/pillar.example +++ b/pillar.example @@ -235,3 +235,24 @@ postfix: - someuser_1@example.com - someuser_2@example.com - singlealiasexample: someuser_3@example.com + + +### +# +# Multiple virtual_alias_maps entries: +# +# You are free to define alternative mapping names +# and use them as 'variables' in your Postfix config: +# (Credit for the idea and the example goes to @roskens.) + +postfix: + config: + virtual_alias_maps: $virtual_alias_1_maps $virtual_alias_2_maps + virtual_alias_1_maps: hash:/etc/postfix/virtual + virtual_alias_2_maps: pcre:/etc/postfix/virtual.pcre + mapping: + virtual_alias_1_maps: + root: + - me + virtual_alias_2_maps: + - '/(\S+)_(devel|preprod|prod)@sub.example.com$/': '$(1)@$(2).sub.example.com' From fbaa2dcabb35fbac381ea502b7d5862c5205bb97 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Tue, 9 Apr 2019 20:12:23 +0200 Subject: [PATCH 3/3] main.cf: ignore only actually used keys of 'postfix:mapping'; fixes #89 --- postfix/files/main.cf | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/postfix/files/main.cf b/postfix/files/main.cf index 1b701d6..9fbd6ef 100644 --- a/postfix/files/main.cf +++ b/postfix/files/main.cf @@ -1,17 +1,8 @@ {%- from "postfix/map.jinja" import postfix with context -%} {%- set config = salt['pillar.get']('postfix:config', {}) -%} -{%- if not salt['pillar.get']('postfix:mapping', False) %} -{#- Let the user configure mapping manually. -#} -{%- set processed_parameters = [] %} -{%- else -%} -{#- TODO: alias_maps probably belongs here, too: #} -{%- set processed_parameters = [ - 'virtual_alias_maps', - 'smtp_sasl_password_maps', - 'sender_canonical_maps', - ] %} -{%- endif -%} +{#- " | list": Python3.6 retuns dict_keys here, which needs to be converted into a list here. -#} +{%- set processed_parameters = salt['pillar.get']('postfix:mapping', {}).keys() | list %} {%- macro set_parameter(parameter, default=None) -%} {% set value = config.get(parameter, default) %}