Commit f9a114b2 authored by Raphaël Pinson's avatar Raphaël Pinson Committed by Raphaël Pinson
Browse files

Support multiple destinations in postfix::virtual (Fix #164)

parent e8fe4c71
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
# === Parameters # === Parameters
# #
# [*name*] - name of address postfix will lookup. See virtual(8). # [*name*] - name of address postfix will lookup. See virtual(8).
# [*destination*] - where the emails will be delivered to. See virtual(8). # [*destination*] - a list of destinations where the emails will be delivered to. See virtual(8).
# [*ensure*] - present/absent, defaults to present. # [*ensure*] - present/absent, defaults to present.
# [*file*] - A string defining the location of the pre-hash map. # [*file*] - a string defining the location of the pre-hash map.
# #
# === Requires # === Requires
# #
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
# node "toto.example.com" { # node "toto.example.com" {
# #
# include postfix # include postfix
# # # postfix::hash { "/etc/postfix/virtual":
# postfix::hash { "/etc/postfix/virtual":
# ensure => present, # ensure => present,
# } # }
# postfix::config { "virtual_alias_maps": # postfix::config { "virtual_alias_maps":
...@@ -30,24 +29,29 @@ ...@@ -30,24 +29,29 @@
# } # }
# postfix::virtual { "user@example.com": # postfix::virtual { "user@example.com":
# ensure => present, # ensure => present,
# destination => "root", # destination => ['root', 'postmaster'],
# } # }
# } # }
# #
define postfix::virtual ( define postfix::virtual (
String $destination, Variant[String, Array[String]] $destination,
Stdlib::Absolutepath $file='/etc/postfix/virtual', Stdlib::Absolutepath $file='/etc/postfix/virtual',
Enum['present', 'absent'] $ensure='present' Enum['present', 'absent'] $ensure='present'
) { ) {
include ::postfix::augeas include ::postfix::augeas
$dest_sets = [$destination].flatten.map |$i, $d| {
$idx = $i+1
"set \$entry/destination[${idx}] '${d}'"
}
case $ensure { case $ensure {
'present': { 'present': {
$changes = [ $changes = [
"set pattern[. = '${name}'] '${name}'", "defnode entry pattern[. = '${name}'] '${name}'",
# TODO: support more than one destination 'rm $entry/destination',
"set pattern[. = '${name}']/destination '${destination}'", $dest_sets,
] ].flatten
} }
'absent': { 'absent': {
......
...@@ -26,7 +26,7 @@ describe 'postfix::virtual' do ...@@ -26,7 +26,7 @@ describe 'postfix::virtual' do
context 'when sending wrong type for destination' do context 'when sending wrong type for destination' do
let (:params) { { let (:params) { {
:destination => ['bar'], :destination => true,
} } } }
it 'should fail' do it 'should fail' do
...@@ -98,8 +98,9 @@ describe 'postfix::virtual' do ...@@ -98,8 +98,9 @@ describe 'postfix::virtual' do
:incl => '/etc/postfix/virtual', :incl => '/etc/postfix/virtual',
:lens => 'Postfix_Virtual.lns', :lens => 'Postfix_Virtual.lns',
:changes => [ :changes => [
"set pattern[. = 'foo'] 'foo'", "defnode entry pattern[. = 'foo'] 'foo'",
"set pattern[. = 'foo']/destination 'bar'", "rm $entry/destination",
"set $entry/destination[1] 'bar'",
]) ])
} }
end end
...@@ -116,8 +117,29 @@ describe 'postfix::virtual' do ...@@ -116,8 +117,29 @@ describe 'postfix::virtual' do
:incl => '/tmp/virtual', :incl => '/tmp/virtual',
:lens => 'Postfix_Virtual.lns', :lens => 'Postfix_Virtual.lns',
:changes => [ :changes => [
"set pattern[. = 'foo'] 'foo'", "defnode entry pattern[. = 'foo'] 'foo'",
"set pattern[. = 'foo']/destination 'bar'", "rm $entry/destination",
"set $entry/destination[1] 'bar'",
])
}
end
context 'when passing destination as array' do
let (:params) { {
:destination => ['bar', 'baz'],
:file => '/tmp/virtual',
:ensure => 'present',
} }
it { is_expected.to contain_class('postfix::augeas') }
it { is_expected.to contain_augeas('Postfix virtual - foo').with(
:incl => '/tmp/virtual',
:lens => 'Postfix_Virtual.lns',
:changes => [
"defnode entry pattern[. = 'foo'] 'foo'",
"rm $entry/destination",
"set $entry/destination[1] 'bar'",
"set $entry/destination[2] 'baz'",
]) ])
} }
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment