Puppet Function: unbound::flatten_record

Defined in:
functions/flatten_record.pp
Function type:
Puppet Language

Overview

unbound::flatten_record(Unbound::Record $value)String

Flatten a record type to its string form.

The string will include surrounding quotes as these differ depending on the record type.

Examples:

unbound::flatten_record({'name' => 'example.com.', 'type' => 'A', 'ip' => '192.0.2.1'})

Parameters:

  • value (Unbound::Record)

    The record to flatten.

Returns:

  • (String)

    The flattened string.

Since:

  • 2.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'functions/flatten_record.pp', line 14

function unbound::flatten_record(Unbound::Record $value) {

  $header = delete_undef_values($value['name', 'ttl', 'class', 'type'])

  $record = $value['type'] ? {
    'A'     => join($header + $value['ip'], ' '),
    'AAAA'  => join($header + $value['ip'], ' '),
    'MX'    => join($header + $value['priority', 'hostname'], ' '),
    'NS'    => join($header + $value['hostname'], ' '),
    'PTR'   => join($header + $value['hostname'], ' '),
    'SOA'   => join($header + $value['primary', 'email', 'serial', 'refresh', 'retry', 'expire', 'negative'], ' '),
    'TXT'   => join($header + "\"${value['value']}\"", ' '),
    default => fail("Unsupported type '${value['type']}'"),
  }

  # Do this separately so lint doesn't explode
  $value['type'] ? {
    'TXT'   => "'${record}'",
    default => "\"${record}\"",
  }
}