Skip to content

Commit 0ecebc7

Browse files
figlessalexjfisher
authored andcommitted
Don't use type alias in postgresql_password
Type aliases from modules aren't available on the agent. See https://puppet.atlassian.net/browse/PUP-7197 This means that calls to `postgresql::postgresql_password` can't be deferred if the `hash` parameter uses the type `Postgresql::Pg_password_encryption`. Instead we have to use the raw `Enum`, (which unfortunately causes code duplication, but this is unavoidable). Using this function with `Deferred` is not just a theoretical use-case. The module itself tries to here. https://github.com/puppetlabs/puppetlabs-postgresql/blob/20704ffae24dcf970784697b1798c09d026fb7f8/manifests/server/role.pp#L162
1 parent 20704ff commit 0ecebc7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lib/puppet/functions/postgresql/postgresql_password.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
required_param 'Variant[String[1], Integer]', :username
2525
required_param 'Variant[String[1], Sensitive[String[1]], Integer]', :password
2626
optional_param 'Boolean', :sensitive
27-
optional_param 'Optional[Postgresql::Pg_password_encryption]', :hash
27+
# The following Enum is also defined in `types/pg_password_encryption.pp` but type alias can't be used in Deferred functions.
28+
optional_param 'Optional[Enum["md5", "scram-sha-256"]]', :hash
2829
optional_param 'Optional[Variant[String[1], Integer]]', :salt
2930
return_type 'Variant[String, Sensitive[String]]'
3031
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'postgresql::server::db:' do
6+
let(:user) { 'user_test' }
7+
let(:password) { 'deferred_password_test' }
8+
let(:database) { 'test_database' }
9+
10+
let(:pp_one) do
11+
<<-MANIFEST.unindent
12+
$user = #{user}
13+
$password = #{password}
14+
$database = #{database}
15+
16+
include postgresql::server
17+
postgresql::server::db { $database:
18+
user => $user,
19+
password => Deferred('unwrap', [$password]),
20+
}
21+
MANIFEST
22+
end
23+
24+
it 'creates a database with with the password in the deferred function' do
25+
if run_shell('puppet --version').stdout[0].to_i < 7
26+
skip # Deferred function fixes only in puppet 7, see https://tickets.puppetlabs.com/browse/PUP-11518
27+
end
28+
apply_manifest(pp_one)
29+
psql_cmd = "PGPASSWORD=#{password} PGUSER=#{user} PGDATABASE=#{database} psql -h 127.0.0.1 -d postgres -c '\\q'"
30+
run_shell("cd /tmp; su #{shellescape('postgres')} -c #{shellescape(psql_cmd)}",
31+
acceptable_exit_codes: [0])
32+
end
33+
end

types/pg_password_encryption.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# @summary the supported password_encryption
2+
# Note that this Enum is also defined in:
3+
# lib/puppet/functions/postgresql/postgresql_password.rb
24
type Postgresql::Pg_password_encryption = Enum['md5', 'scram-sha-256']

0 commit comments

Comments
 (0)