diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml index 53963e3..0227c09 100644 --- a/.kitchen.dokken.yml +++ b/.kitchen.dokken.yml @@ -105,3 +105,11 @@ suites: sasl: smtp_sasl_user_name: "kitchenuser" smtp_sasl_passwd: "not-a-real-thing" + +- name: canonical + run_list: + - recipe[postfix] + attributes: + postfix: + recipient_canonical_map_entries: + john: john@doe.com \ No newline at end of file diff --git a/.kitchen.yml b/.kitchen.yml index d27ae83..fcd3387 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,3 +47,12 @@ suites: sasl: smtp_sasl_user_name: "kitchenuser" smtp_sasl_passwd: "not-a-real-thing" + +- name: canonical + run_list: + - recipe[postfix] + attributes: + postfix: + recipient_canonical_map_entries: + john: john@doe.com + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a555331..6829c65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,12 @@ env: - INSTANCE=default-centos-7 - INSTANCE=default-ubuntu-1404 - INSTANCE=default-ubuntu-1604 + - INSTANCE=canonical-centos-6 + - INSTANCE=canonical-centos-7 + - INSTANCE=canonical-debian-7 + - INSTANCE=canonical-debian-8 + - INSTANCE=canonical-ubuntu-1404 + - INSTANCE=canonical-ubuntu-1604 before_script: - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) diff --git a/README.md b/README.md index 3531da4..053469c 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ This change in namespace to `node['postfix']['main']` should allow for greater f - `node['postfix']['sasl']['smtp_sasl_passwd']` - SASL password to use. Default empty. - `node['postfix']['sender_canonical_map_entries']` - (hash with key value pairs); default not configured. Setup generic canonical maps. See `man 5 canonical`. If has at least one value, then will be enabled in config. - `node['postfix']['smtp_generic_map_entries']` - (hash with key value pairs); default not configured. Setup generic postfix maps. See `man 5 generic`. If has at least one value, then will be enabled in config. +- `node['postfix']['recipient_canonical_map_entries']` - (hash with key value pairs); default not configured. Setup generic canonical maps. See `man 5 canonical`. If has at least one value, then will be enabled in config. + Example of json role config, for setup *_map_entries: diff --git a/attributes/default.rb b/attributes/default.rb index d467072..b64cc1f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -33,6 +33,7 @@ default['postfix']['main_template_source'] = 'postfix' default['postfix']['master_template_source'] = 'postfix' default['postfix']['sender_canonical_map_entries'] = {} default['postfix']['smtp_generic_map_entries'] = {} +default['postfix']['recipient_canonical_map_entries'] = {} default['postfix']['access_db_type'] = 'hash' default['postfix']['aliases_db_type'] = 'hash' default['postfix']['transport_db_type'] = 'hash' diff --git a/recipes/_common.rb b/recipes/_common.rb index 17d5e0e..fe141fd 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -109,6 +109,25 @@ unless node['postfix']['smtp_generic_map_entries'].empty? end end +execute 'update-postfix-recipient_canonical' do + command "postmap #{node['postfix']['conf_dir']}/recipient_canonical" + action :nothing +end + +unless node['postfix']['recipient_canonical_map_entries'].empty? + template "#{node['postfix']['conf_dir']}/recipient_canonical" do + owner 'root' + group node['root_group'] + mode '0644' + notifies :run, 'execute[update-postfix-recipient_canonical]' + notifies :reload, 'service[postfix]' + end + + unless node['postfix']['main'].key?('recipient_canonical_maps') + node.normal['postfix']['main']['recipient_canonical_maps'] = "hash:#{node['postfix']['conf_dir']}/recipient_canonical" + end +end + %w( main master ).each do |cfg| template "#{node['postfix']['conf_dir']}/#{cfg}.cf" do source "#{cfg}.cf.erb" diff --git a/templates/default/recipient_canonical.erb b/templates/default/recipient_canonical.erb new file mode 100644 index 0000000..bfff5c1 --- /dev/null +++ b/templates/default/recipient_canonical.erb @@ -0,0 +1,9 @@ +# +# Auto-generated by Chef. +# Local modifications will be overwritten. +# +# See man 5 canonical for format + +<% node['postfix']['recipient_canonical_map_entries'].each do |name, value| %> +<%= name %> <%= value %> +<% end unless node['postfix']['recipient_canonical_map_entries'].nil? %> diff --git a/test/integration/canonical/serverspec/canonical_spec.rb b/test/integration/canonical/serverspec/canonical_spec.rb new file mode 100644 index 0000000..3650087 --- /dev/null +++ b/test/integration/canonical/serverspec/canonical_spec.rb @@ -0,0 +1,23 @@ +# Copyright:: 2012-2017, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +require_relative './spec_helper' + +describe file('/etc/postfix/recipient_canonical.db') do + it { should be_file } +end + +describe file('/etc/postfix/main.cf') do + its(:content) { should match(%r{^\s*recipient_canonical_maps\s*=.*\/etc\/postfix\/recipient_canonical\s*$}) } +end