Defined Type: rspamd::ucl::config
- Defined in:
- vendor_modules/rspamd/manifests/ucl/config.pp
Summary
manages a single UCL (Universal Configuration Language) config entryOverview
rspamd::ucl::config
Note:
This class is only for internal use, use rspam::config instead.
20 21 22 23 24 25 26 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 |
# File 'vendor_modules/rspamd/manifests/ucl/config.pp', line 20
define rspamd::ucl::config (
Stdlib::Absolutepath $file,
String $key,
$value,
Array[String] $sections = [],
Rspamd::Ucl::ValueType $type = 'auto',
Enum['present', 'absent'] $ensure = 'present',
Optional[String] $comment = undef,
) {
ensure_resource('rspamd::ucl::file', $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", '')
# strip the [x] array qualifier
$section_name = $sections[$i-1] ? {
/^(.*)\[\d+\]$/ => $1,
default => $sections[$i-1]
}
ensure_resource('concat::fragment', "rspamd ${file} UCL config ${section} 01 section start", {
target => $file,
content => "${indent}${section_name} {\n",
})
ensure_resource('concat::fragment', "rspamd ${file} UCL config ${section} 04 section end", { # ~ sorts last
target => $file,
content => "${indent}}\n",
})
}
}
# now for the value itself
$indent = sprintf("%${$depth*2}s", '')
$section = join($rsections, ' 03 ')
$entry_key = $key ? {
/^(.*)\[\d+\]$/ => $1,
default => $key
}
if ($comment) {
concat::fragment { "rspamd ${file} UCL config ${section} 02 ${key} 01 comment":
target => $file,
content => join(suffix(prefix(split($comment, '\n'), "${indent}# "), "\n")),
}
}
$printed_value = rspamd::ucl::print_config_value($value, $type)
$semicolon = $printed_value ? {
/\A<</ => '',
default => ";\n"
}
concat::fragment { "rspamd ${file} UCL config ${section} 02 ${key} 02":
target => $file,
content => "${indent}${entry_key} = ${printed_value}${semicolon}",
}
}
|