Puppet Function: rspamd::create_config_resources

Defined in:
vendor_modules/rspamd/functions/create_config_resources.pp
Function type:
Puppet Language

Summary

create rspamd::config resources from a nested hash (e.g. from hiera)

Overview

rspamd::create_config_resources(Hash[String, NotUndef] $config_hash, Hash $params = {}, Array[String] $sections = [])Any

Function: rspamd::create_config_resources()

Create rspamd::config resources from a nested hash, suitable for conveniently loading values from hiera. The key-value pairs from the hash represent config keys and values passed to rspamd::config for simple values, Hash values recursively create nested sections. Arrays that only contain Hash values are created as multi-value keys (or “duplicate sections”), while all other arrays are printed inline (e.g. [a,b,c]).

Parameters:

  • config_hash (Hash[String, NotUndef])

    a hash of (non-hierarchical) key names mapped to values

  • params (Hash) (defaults to: {})

    a hash of params passed to rspamd::config (must not include :sections, :key, or :value)

  • sections (Array[String]) (defaults to: [])

    the section names of the hierarchical key, will usually only be specified on recursive calls from within this function itself

Returns:

  • (Any)

See Also:

Author:

  • Bernhard Frauendienst <puppet@nospam.obeliks.de>



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'vendor_modules/rspamd/functions/create_config_resources.pp', line 24

function rspamd::create_config_resources(Hash[String, NotUndef] $config_hash, Hash $params={}, Array[String] $sections=[]) {
  $config_hash.each |$key, $value| {
    case $value {
      Hash: {
        rspamd::create_config_resources($value, $params, $sections + $key)
      }
      Array[Hash]: {
        $indexed_hash = $value.map |$index, $v| {
          { "${key}[${index}]" => $v }
        }.reduce({}) |$a,$b| { $a + $b }
        rspamd::create_config_resources($indexed_hash, $params, $sections)
      }
      default: {
        rspamd::config { "${params[file]}:${join($sections + $key, '.')}":
          sections => $sections,
          key      => $key,
          value    => $value,
          *        => $params
        }
      }
    }
  }
}