|
1 | 1 | # @api private
|
2 | 2 | class postgresql::server::passwd {
|
3 |
| - $postgres_password = if $postgresql::server::postgres_password =~ Sensitive { |
4 |
| - $postgresql::server::postgres_password.unwrap |
5 |
| - } else { |
6 |
| - $postgresql::server::postgres_password |
7 |
| - } |
8 |
| - |
9 |
| - $user = $postgresql::server::user |
10 |
| - $group = $postgresql::server::group |
11 |
| - $psql_path = $postgresql::server::psql_path |
12 |
| - $port = $postgresql::server::port |
13 |
| - $database = $postgresql::server::default_database |
14 |
| - $module_workdir = $postgresql::server::module_workdir |
15 |
| - |
16 |
| - # psql will default to connecting as $user if you don't specify name |
17 |
| - $_datbase_user_same = $database == $user |
18 |
| - $_dboption = $_datbase_user_same ? { |
19 |
| - false => " --dbname ${shell_escape($database)}", |
20 |
| - default => '' |
21 |
| - } |
22 |
| - |
23 |
| - if $postgres_password { |
24 |
| - # NOTE: this password-setting logic relies on the pg_hba.conf being |
25 |
| - # configured to allow the postgres system user to connect via psql |
26 |
| - # without specifying a password ('ident' or 'trust' security). This is |
27 |
| - # the default for pg_hba.conf. |
28 |
| - $escaped = postgresql::postgresql_escape($postgres_password) |
29 |
| - $exec_command = "${shell_escape($psql_path)}${_dboption} -c \"ALTER ROLE \\\"${shell_escape($user)}\\\" PASSWORD \${NEWPASSWD_ESCAPED}\"" |
30 |
| - exec { 'set_postgres_postgrespw': |
31 |
| - # This command works w/no password because we run it as postgres system |
32 |
| - # user |
33 |
| - command => $exec_command, |
34 |
| - user => $user, |
35 |
| - group => $group, |
36 |
| - logoutput => true, |
37 |
| - cwd => $module_workdir, |
38 |
| - environment => [ |
39 |
| - "PGPASSWORD=${postgres_password}", |
40 |
| - "PGPORT=${port}", |
41 |
| - "NEWPASSWD_ESCAPED=${escaped}", |
42 |
| - ], |
43 |
| - # With this command we're passing -h to force TCP authentication, which |
44 |
| - # does require a password. We specify the password via the PGPASSWORD |
45 |
| - # environment variable. If the password is correct (current), this |
46 |
| - # command will exit with an exit code of 0, which will prevent the main |
47 |
| - # command from running. |
48 |
| - unless => "${psql_path} -h localhost -p ${port} -c 'select 1' > /dev/null", |
49 |
| - path => '/usr/bin:/usr/local/bin:/bin', |
50 |
| - } |
| 3 | + postgresql::server::instance_passwd { 'main': |
| 4 | + user => $postgresql::server::user, |
| 5 | + group => $postgresql::server::group, |
| 6 | + psql_path => $postgresql::server::psql_path, |
| 7 | + port => $postgresql::server::port, |
| 8 | + database => $postgresql::server::default_database, |
| 9 | + module_workdir => $postgresql::server::module_workdir, |
| 10 | + postgres_password => $postgresql::server::postgres_password, |
51 | 11 | }
|
52 | 12 | }
|
0 commit comments