|
84 | 84 | $createdb_sql = $createdb ? { true => 'CREATEDB', default => 'NOCREATEDB' }
|
85 | 85 | $superuser_sql = $superuser ? { true => 'SUPERUSER', default => 'NOSUPERUSER' }
|
86 | 86 | $replication_sql = $replication ? { true => 'REPLICATION', default => '' }
|
87 |
| - if ($password_hash_unsensitive != false) { |
88 |
| - $password_sql = "ENCRYPTED PASSWORD '${password_hash_unsensitive}'" |
| 87 | + |
| 88 | + if $password_hash_unsensitive =~ Deferred { |
| 89 | + $password_sql = Deferred('postgresql::prepend_sql_password', [$password_hash_unsensitive]) |
| 90 | + } elsif ($password_hash_unsensitive != false) { |
| 91 | + $password_sql = postgresql::prepend_sql_password($password_hash_unsensitive) |
89 | 92 | } else {
|
90 | 93 | $password_sql = ''
|
91 | 94 | }
|
92 | 95 |
|
| 96 | + if $password_sql =~ Deferred { |
| 97 | + $create_role_command = Deferred('sprintf', ["CREATE ROLE \"%s\" %s %s %s %s %s %s CONNECTION LIMIT %s", |
| 98 | + $username, |
| 99 | + $password_sql, |
| 100 | + $login_sql, |
| 101 | + $createrole_sql, |
| 102 | + $createdb_sql, |
| 103 | + $superuser_sql, |
| 104 | + $replication_sql, |
| 105 | + $connection_limit]) |
| 106 | + } else { |
| 107 | + $create_role_command = "CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}" |
| 108 | + } |
| 109 | + |
93 | 110 | postgresql_psql { "CREATE ROLE ${username} ENCRYPTED PASSWORD ****":
|
94 |
| - command => Sensitive("CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}"), |
| 111 | + command => Sensitive($create_role_command), |
95 | 112 | unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}'",
|
96 | 113 | require => undef,
|
97 | 114 | sensitive => true,
|
|
134 | 151 | }
|
135 | 152 |
|
136 | 153 | if $password_hash_unsensitive and $update_password {
|
137 |
| - if($password_hash_unsensitive =~ /^(md5|SCRAM-SHA-256).+/) { |
138 |
| - $pwd_hash_sql = $password_hash_unsensitive |
139 |
| - } else { |
| 154 | + if $password_hash_unsensitive =~ Deferred { |
| 155 | + $pwd_hash_sql = Deferred('postgresql::postgresql_password',[$username, |
| 156 | + $password_hash, |
| 157 | + false, |
| 158 | + $hash, |
| 159 | + $salt]) |
| 160 | + } |
| 161 | + else { |
140 | 162 | $pwd_hash_sql = postgresql::postgresql_password(
|
141 | 163 | $username,
|
142 | 164 | $password_hash,
|
|
145 | 167 | $salt,
|
146 | 168 | )
|
147 | 169 | }
|
| 170 | + if $pwd_hash_sql =~ Deferred { |
| 171 | + $pw_command = Deferred('sprintf', ["ALTER ROLE \"%s\" ENCRYPTED PASSWORD '%s'", $username, $pwd_hash_sql]) |
| 172 | + $unless_pw_command = Deferred('sprintf', ["SELECT 1 FROM pg_shadow WHERE usename = '%s' AND passwd = '%s'", |
| 173 | + $username, |
| 174 | + $pwd_hash_sql]) |
| 175 | + } else { |
| 176 | + $pw_command = "ALTER ROLE \"${username}\" ENCRYPTED PASSWORD '${pwd_hash_sql}'" |
| 177 | + $unless_pw_command = "SELECT 1 FROM pg_shadow WHERE usename = '${username}' AND passwd = '${pwd_hash_sql}'" |
| 178 | + } |
148 | 179 | postgresql_psql { "ALTER ROLE ${username} ENCRYPTED PASSWORD ****":
|
149 |
| - command => Sensitive("ALTER ROLE \"${username}\" ENCRYPTED PASSWORD '${pwd_hash_sql}'"), |
150 |
| - unless => Sensitive("SELECT 1 FROM pg_shadow WHERE usename = '${username}' AND passwd = '${pwd_hash_sql}'"), |
| 180 | + command => Sensitive($pw_command), |
| 181 | + unless => Sensitive($unless_pw_command), |
151 | 182 | sensitive => true,
|
152 | 183 | }
|
153 | 184 | }
|
|
0 commit comments