|
74 | 74 | psql_path => $psql_path,
|
75 | 75 | connect_settings => $connect_settings,
|
76 | 76 | cwd => $module_workdir,
|
77 |
| - require => Postgresql_psql["CREATE ROLE ${username} ENCRYPTED PASSWORD ****"], |
| 77 | + # require => Postgresql_psql["CREATE ROLE ${username} ENCRYPTED PASSWORD ****"], |
78 | 78 | }
|
79 | 79 |
|
80 | 80 | if $ensure == 'present' {
|
|
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) { |
| 87 | + |
| 88 | + if (type($password_hash_unsensitive) =~ Type[Deferred]) { |
| 89 | + $password_sql = Deferred('new', [String, $password_hash_unsensitive]) |
| 90 | + } elsif ($password_hash_unsensitive != false) { |
88 | 91 | $password_sql = "ENCRYPTED PASSWORD '${password_hash_unsensitive}'"
|
89 | 92 | } else {
|
90 | 93 | $password_sql = ''
|
91 | 94 | }
|
92 | 95 |
|
93 |
| - 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}"), |
95 |
| - unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}'", |
96 |
| - require => undef, |
97 |
| - sensitive => true, |
| 96 | + if type($password_sql) =~ Type[Deferred] { |
| 97 | + Deferred('postgresql::create_role', [$db, |
| 98 | + $port_override, |
| 99 | + $psql_user, |
| 100 | + $psql_group, |
| 101 | + $psql_path, |
| 102 | + $connect_settings, |
| 103 | + $module_workdir, |
| 104 | + $username, |
| 105 | + $password_sql, |
| 106 | + $login_sql, |
| 107 | + $createrole_sql, |
| 108 | + $createdb_sql, |
| 109 | + $superuser_sql, |
| 110 | + $replication_sql, |
| 111 | + $connection_limit]) |
| 112 | + } else { |
| 113 | + postgresql::create_role($db, |
| 114 | + $port_override, |
| 115 | + $psql_user, |
| 116 | + $psql_group, |
| 117 | + $psql_path, |
| 118 | + $connect_settings, |
| 119 | + $module_workdir, |
| 120 | + $username, |
| 121 | + $password_sql, |
| 122 | + $login_sql, |
| 123 | + $createrole_sql, |
| 124 | + $createdb_sql, |
| 125 | + $superuser_sql, |
| 126 | + $replication_sql, |
| 127 | + $connection_limit) |
98 | 128 | }
|
99 | 129 |
|
100 | 130 | postgresql_psql { "ALTER ROLE \"${username}\" ${superuser_sql}":
|
|
133 | 163 | unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}' AND rolconnlimit = ${connection_limit}",
|
134 | 164 | }
|
135 | 165 |
|
136 |
| - 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 { |
140 |
| - $pwd_hash_sql = postgresql::postgresql_password( |
141 |
| - $username, |
142 |
| - $password_hash, |
143 |
| - $password_hash =~ Sensitive[String], |
144 |
| - $hash, |
145 |
| - $salt, |
146 |
| - ) |
147 |
| - } |
148 |
| - 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}'"), |
151 |
| - sensitive => true, |
152 |
| - } |
| 166 | + if type($password_hash_unsensitive) =~ Type[Deferred] { |
| 167 | + $pwd_hash_sql = Deferred('postgresql::pwd_hash_sql', [$password_hash_unsensitive, $password_hash, $update_password, $username, $hash, $salt]) |
| 168 | + } else { |
| 169 | + $pwd_hash_sql = postgresql::pwd_hash_sql( |
| 170 | + $password_hash_unsensitive, |
| 171 | + $password_hash, |
| 172 | + $update_password, |
| 173 | + $username, |
| 174 | + $hash, |
| 175 | + $salt) |
| 176 | + } |
| 177 | + if (type($pwd_hash_sql) =~ Type[Deferred]) { |
| 178 | + Deferred('postgresql::update_psql', [$db, |
| 179 | + $port_override, |
| 180 | + $psql_user, |
| 181 | + $psql_group, |
| 182 | + $psql_path, |
| 183 | + $connect_settings, |
| 184 | + $module_workdir, |
| 185 | + $username, |
| 186 | + $pwd_hash_sql]) |
| 187 | + } elsif $pwd_hash_sql { |
| 188 | + postgresql::update_psql($db, |
| 189 | + $port_override, |
| 190 | + $psql_user, |
| 191 | + $psql_group, |
| 192 | + $psql_path, |
| 193 | + $connect_settings, |
| 194 | + $module_workdir, |
| 195 | + $username, |
| 196 | + $pwd_hash_sql) |
153 | 197 | }
|
154 | 198 | } else {
|
155 | 199 | # ensure == absent
|
|
0 commit comments