Puppet Function: cfweb::passwd_db

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

Overview

cfweb::passwd_db(String[1] $realm)String

Parameters:

  • realm (String[1])

Returns:

  • (String)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'functions/passwd_db.pp', line 6

function cfweb::passwd_db(String[1] $realm) >> String {
    $users = $cfweb::global::users[$realm]
    $algo = 'sha-512'
    $salt = $realm.regsubst('[^a-zA-Z0-9./]', '', 'G')

    if !$users {
        fail("Missing realm config: \$cfweb::global::users[${realm}]")
    }

    $lines = (
        ["# ${realm}"] +
        ($users.map |$user, $v| {
            if $v =~ String[1] {
                $end = pw_hash($v, $algo, $salt)
            } else {
                if $v['crypt'] =~ String[1] {
                    $p = $v['crypt']
                } elsif $v['plain'] =~ String[1] {
                    $p = pw_hash($v['plain'], $algo, $salt)
                } else {
                    fail("Either set 'crypt' or 'plain' for ${user}@${realm}")
                }

                $end = "${p}:${v['comment']}"
            }

            "${user}:${end}"
        }) +
        ['# end']
    )

    $lines.join("\n")
}