|
21 | 21 | # @param hash Specify the hash method for pg password |
22 | 22 | # @param salt Specify the salt use for the scram-sha-256 encoding password (default username) |
23 | 23 | define postgresql::server::role ( |
24 | | - Boolean $update_password = true, |
25 | | - Variant[Boolean, String, Sensitive[String]] $password_hash = false, |
26 | | - Boolean $createdb = false, |
27 | | - Boolean $createrole = false, |
28 | | - String[1] $db = $postgresql::server::default_database, |
29 | | - Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef, |
30 | | - Boolean $login = true, |
31 | | - Boolean $inherit = true, |
32 | | - Boolean $superuser = false, |
33 | | - Boolean $replication = false, |
34 | | - String[1] $connection_limit = '-1', |
35 | | - String[1] $username = $title, |
36 | | - Hash $connect_settings = $postgresql::server::default_connect_settings, |
37 | | - String[1] $psql_user = $postgresql::server::user, |
38 | | - String[1] $psql_group = $postgresql::server::group, |
39 | | - Variant[String[1], Stdlib::Absolutepath] $psql_path = $postgresql::server::psql_path, |
40 | | - String[1] $module_workdir = $postgresql::server::module_workdir, |
41 | | - Enum['present', 'absent'] $ensure = 'present', |
42 | | - Enum['md5', 'scram-sha-256'] $hash = 'md5', |
43 | | - Optional[Variant[String[1], Integer]] $salt = undef, |
| 24 | + Boolean $update_password = true, |
| 25 | + Variant[Boolean, String, Sensitive[String]] $password_hash = false, |
| 26 | + Boolean $createdb = false, |
| 27 | + Boolean $createrole = false, |
| 28 | + String[1] $db = $postgresql::server::default_database, |
| 29 | + Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef, |
| 30 | + Boolean $login = true, |
| 31 | + Boolean $inherit = true, |
| 32 | + Boolean $superuser = false, |
| 33 | + Boolean $replication = false, |
| 34 | + String[1] $connection_limit = '-1', |
| 35 | + String[1] $username = $title, |
| 36 | + Hash $connect_settings = $postgresql::server::default_connect_settings, |
| 37 | + String[1] $psql_user = $postgresql::server::user, |
| 38 | + String[1] $psql_group = $postgresql::server::group, |
| 39 | + Variant[String[1], Stdlib::Absolutepath] $psql_path = $postgresql::server::psql_path, |
| 40 | + String[1] $module_workdir = $postgresql::server::module_workdir, |
| 41 | + Enum['present', 'absent'] $ensure = 'present', |
| 42 | + Optional[Enum['md5', 'scram-sha-256']] $hash = undef, |
| 43 | + Optional[Variant[String[1], Integer]] $salt = undef, |
44 | 44 | ) { |
45 | 45 | $password_hash_unsensitive = if $password_hash =~ Sensitive[String] { |
46 | 46 | $password_hash.unwrap |
|
106 | 106 | ] |
107 | 107 | ) |
108 | 108 | } else { |
109 | | - $create_role_command = "CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}" |
| 109 | + $create_role_command = "CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}" # lint:ignore:140chars |
110 | 110 | } |
111 | 111 |
|
112 | 112 | postgresql_psql { "CREATE ROLE ${username} ENCRYPTED PASSWORD ****": |
|
152 | 152 | unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}' AND rolconnlimit = ${connection_limit}", |
153 | 153 | } |
154 | 154 |
|
| 155 | + $_hash = if $hash { |
| 156 | + $hash |
| 157 | + } elsif $connect_settings != undef and 'DBVERSION' in $connect_settings { |
| 158 | + if (versioncmp($version, '14') >= 0) { 'scram-sha-256' } else { undef } |
| 159 | + } else { |
| 160 | + $postgresql::server::password_encryption |
| 161 | + } |
155 | 162 | if $password_hash_unsensitive and $update_password { |
156 | 163 | if $password_hash_unsensitive =~ Deferred { |
157 | | - $pwd_hash_sql = Deferred ( 'postgresql::postgresql_password', [$username, |
158 | | - $password_hash, |
| 164 | + $pwd_hash_sql = Deferred ( 'postgresql::postgresql_password', [ |
| 165 | + $username, |
| 166 | + $password_hash_unsensitive, |
159 | 167 | false, |
160 | | - $hash, |
| 168 | + $_hash, |
161 | 169 | $salt, |
162 | 170 | ] |
163 | 171 | ) |
164 | | - } |
165 | | - else { |
| 172 | + } else { |
166 | 173 | $pwd_hash_sql = postgresql::postgresql_password( |
167 | 174 | $username, |
168 | | - $password_hash, |
| 175 | + $password_hash_unsensitive, |
169 | 176 | false, |
170 | | - $hash, |
| 177 | + $_hash, |
171 | 178 | $salt, |
172 | 179 | ) |
173 | 180 | } |
|
0 commit comments