Skip to content

Commit 029754c

Browse files
authored
Merge pull request #1611 from figless/enum_postgresql_password
Don't use type alias in `postgresql_password` parameter
2 parents 20704ff + e57da89 commit 029754c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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
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+
apply_manifest(pp_one)
26+
psql_cmd = "PGPASSWORD=#{password} PGUSER=#{user} PGDATABASE=#{database} psql -h 127.0.0.1 -d postgres -c '\\q'"
27+
run_shell("cd /tmp; su #{shellescape('postgres')} -c #{shellescape(psql_cmd)}",
28+
acceptable_exit_codes: [0])
29+
end
30+
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)