Defined Type: rspamd::config
- Defined in:
- vendor_modules/rspamd/manifests/config.pp
Summary
this type manages a single config entryOverview
rspamd::config
Rspamd uses its own UCL (Unified Configuration Language) format. This format basically allows to define a hierarchy of configuration objects.
Since in puppet, we want to map each single config entry as its own resource, the hierarchy has been “flattened” to hierarchical keys.
A key/value pair `foo = bar` nested in a `section` object, would look like this in UCL:
“`json section
foo =
“`
To reference this key in a rspam::config variable, you would use the notation `section.foo`.
UCL also allows to define arrays, by specifying the same key multiple times. To map this feature to a flattened key name, we use a numerical index in brackets. For example, this UCL snippet
“`json statfile
token = "BAYES_HAM"
statfile
token = "BAYES_SPAM"
“`
would be mapped to
“` statfile.token = “BAYES_HAM” statfile.token = “BAYES_SPAM” “`
Title/Name format
This module manages keeps Rspamd's default configuration untouched, and manages only local override config files. This matches the procedure recommended by the Rspamd authors.
To specify which file a config entry should got to, you can use the `file` parameter.
For convenience reasons, however, this resource also allows to encode the values for $sections, $key, and $file into the resource's name (which is usally the same as its title).
If the $name of the resource matches the format “<file>:<sections>.<name>”, and all of $file, $sections, and $key have not been specified, the values from the name are used. This simplifies creating unique resources for identical settings in different files.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'vendor_modules/rspamd/manifests/config.pp', line 123
define rspamd::config (
$value,
Rspamd::Ucl::ValueType $type = 'auto',
Enum['merge', 'override'] $mode = 'merge',
Enum['present', 'absent'] $ensure = 'present',
Optional[String] $file = undef,
Optional[Array[String]] $sections = undef,
Optional[String] $key = undef,
Optional[String] $comment = undef,
) {
if (!$key and !$sections and !$file and $name =~ /\A([^:]+):(.+\.)?([^.]+)\z/) {
$configfile = $1
$configsections = $2 ? {
Undef => [],
default => split($2, '\.'),
}
$configkey = $3
} else {
$configfile = $file
$configsections = pick($sections, [])
$configkey = pick($key, $name)
}
unless $configfile {
fail("Could not detect file name in resource title ${title}, must specify one explicitly")
}
$folder = $mode ? {
'merge' => 'local.d',
'override' => 'override.d',
}
$full_filename = $configfile ? {
/\./ => $configfile,
default => "${configfile}.conf",
}
$full_file = "${rspamd::config_path}/${folder}/${full_filename}"
$full_key = join($configsections + $configkey, '/')
rspamd::ucl::config { "rspamd config ${full_file} ${full_key}":
ensure => $ensure,
file => $full_file,
sections => $configsections,
key => $configkey,
value => $value,
type => $type,
comment => $comment,
notify => Service['rspamd'],
}
}
|