Unverified Commit 9db2a110 authored by Raphaël Pinson's avatar Raphaël Pinson Committed by GitHub

Transport: allow [host]:port smtp syntax (#285)

* Transport: allow [host]:port syntax

Fix #241

* Flatten changes

* Fix spec tests for transport

* Remove transport node when using smtp

* No way to store bool result

* Fix test when nexthop is undef
parent 5b2aeb94
......@@ -49,25 +49,48 @@ define postfix::transport (
) {
include ::postfix::augeas
$smtp_nexthop = ("${nexthop}" =~ /\[.*\]/)
case $ensure {
'present': {
if ($destination) {
$change_destination = "set pattern[. = '${name}']/transport '${destination}'"
} else {
$change_destination = "clear pattern[. = '${name}']/transport"
if ($smtp_nexthop) {
$change_destination = "rm pattern[. = '${name}']/transport"
} else {
if ($destination) {
$change_destination = "set pattern[. = '${name}']/transport '${destination}'"
} else {
$change_destination = "clear pattern[. = '${name}']/transport"
}
}
if ($nexthop) {
$change_nexthop = "set pattern[. = '${name}']/nexthop '${nexthop}'"
if ($smtp_nexthop) {
$nexthop_split = split($nexthop, ':')
$change_nexthop = [
"rm pattern[. = '${name}']/nexthop",
"set pattern[. = '${name}']/host '${nexthop_split[0]}'",
"set pattern[. = '${name}']/port '${nexthop_split[1]}'",
]
} else {
$change_nexthop = [
"rm pattern[. = '${name}']/host",
"rm pattern[. = '${name}']/port",
"set pattern[. = '${name}']/nexthop '${nexthop}'",
]
}
} else {
$change_nexthop = "clear pattern[. = '${name}']/nexthop"
$change_nexthop = [
"clear pattern[. = '${name}']/nexthop",
"rm pattern[. = '${name}']/host",
"rm pattern[. = '${name}']/port",
]
}
$changes = [
$changes = flatten([
"set pattern[. = '${name}'] '${name}'",
$change_destination,
$change_nexthop,
]
])
}
'absent': {
......
......@@ -113,6 +113,8 @@ describe 'postfix::transport' do
"set pattern[. = 'foo'] 'foo'",
"clear pattern[. = 'foo']/transport",
"clear pattern[. = 'foo']/nexthop",
"rm pattern[. = 'foo']/host",
"rm pattern[. = 'foo']/port",
],
)
}
......@@ -136,12 +138,40 @@ describe 'postfix::transport' do
changes: [
"set pattern[. = 'foo'] 'foo'",
"set pattern[. = 'foo']/transport 'bar'",
"rm pattern[. = 'foo']/host",
"rm pattern[. = 'foo']/port",
"set pattern[. = 'foo']/nexthop 'baz'",
],
)
}
end
context 'when overriding default values with [host]' do
let(:params) do
{
destination: 'bar',
nexthop: '[baz]:1234',
file: '/tmp/transport',
ensure: 'present',
}
end
it { is_expected.to contain_class('postfix::augeas') }
it {
is_expected.to contain_augeas('Postfix transport - foo').with(
incl: '/tmp/transport',
lens: 'Postfix_Transport.lns',
changes: [
"set pattern[. = 'foo'] 'foo'",
"rm pattern[. = 'foo']/transport",
"rm pattern[. = 'foo']/nexthop",
"set pattern[. = 'foo']/host '[baz]'",
"set pattern[. = 'foo']/port '1234'",
],
)
}
end
context 'when ensuring absence' do
let(:params) do
{
......
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