Defined Type: dovecot::configentry
- Defined in:
- manifests/configentry.pp
Summary
Manages a single dovecot config entry.Overview
Note:
This class is only for internal use, use dovecot::config instead.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'manifests/configentry.pp', line 27
define dovecot::configentry (
Stdlib::Absolutepath $file,
String $key,
Variant[Boolean, Integer, String] $value,
Optional[String] $comment = undef,
Enum['present', 'absent'] $ensure = 'present',
Array[String] $sections = [],
) {
ensure_resource('dovecot::configfile', $file)
$rsections = ['/'] + $sections
$depth = length($sections)
if ($depth > 0) {
Integer[1,$depth].each |$i| {
$section = join($rsections[0, $i + 1], ' 03 ')
$indent = sprintf("%${($i - 1) * 2}s", '')
$section_name = $sections[$i - 1]
ensure_resource('concat::fragment', "dovecot ${file} config ${section} 01 section start", {
target => $file,
content => "${indent}${section_name} {\n",
})
ensure_resource('concat::fragment', "dovecot ${file} config ${section} 05 section end", {
target => $file,
content => "${indent}}\n",
})
}
}
# now for the value itself
$indent = sprintf("%${$depth * 2}s", '')
$section = join($rsections, ' 03 ')
if ($comment) {
concat::fragment { "dovecot ${file} config ${section} 02 ${key} 01 comment":
target => $file,
content => join(suffix(prefix(split($comment, '\n'), "${indent}# "), "\n")),
}
}
case $key {
'!include', '!include_try': {
concat::fragment { "dovecot ${file} config ${section} 04 ${key} ${value}":
target => $file,
content => "${key} ${value}\n",
}
}
/\A!/: {
fail("Key must not start with an exclamation mark: ${key}")
}
default: {
$printed_value = dovecot::print_config_value($value)
concat::fragment { "dovecot ${file} config ${section} 02 ${key} 02":
target => $file,
content => "${indent}${key} = ${printed_value}\n",
}
}
}
}
|