Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/puppet/functions/postgresql/postgresql_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
required_param 'Variant[String[1], Integer]', :username
required_param 'Variant[String[1], Sensitive[String[1]], Integer]', :password
optional_param 'Boolean', :sensitive
optional_param 'Optional[Postgresql::Pg_password_encryption]', :hash
# The following Enum is also defined in `types/pg_password_encryption.pp` but type alias can't be used in Deferred functions.
optional_param 'Optional[Enum["md5", "scram-sha-256"]]', :hash
optional_param 'Optional[Variant[String[1], Integer]]', :salt
return_type 'Variant[String, Sensitive[String]]'
end
Expand Down
30 changes: 30 additions & 0 deletions spec/acceptance/db_deferred_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'postgresql::server::db:' do
let(:user) { 'user_test' }
let(:password) { 'deferred_password_test' }
let(:database) { 'test_database' }

let(:pp_one) do
<<~MANIFEST
$user = '#{user}'
$password = '#{password}'
$database = '#{database}'

include postgresql::server
postgresql::server::db { $database:
user => $user,
password => Deferred('unwrap', [$password]),
}
MANIFEST
end

it 'creates a database with with the password in the deferred function' do
apply_manifest(pp_one)
psql_cmd = "PGPASSWORD=#{password} PGUSER=#{user} PGDATABASE=#{database} psql -h 127.0.0.1 -d postgres -c '\\q'"
run_shell("cd /tmp; su #{shellescape('postgres')} -c #{shellescape(psql_cmd)}",
acceptable_exit_codes: [0])
end
end
2 changes: 2 additions & 0 deletions types/pg_password_encryption.pp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# @summary the supported password_encryption
# Note that this Enum is also defined in:
# lib/puppet/functions/postgresql/postgresql_password.rb
type Postgresql::Pg_password_encryption = Enum['md5', 'scram-sha-256']
Loading