Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define Enum on supported encryption types for postgresql_password #1611

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 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,9 @@
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
# Note that this Enum is also defined in:
# types/pg_password_encryption.pp
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
33 changes: 33 additions & 0 deletions spec/acceptance/db_deferred_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.unindent
$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
if run_shell('puppet --version').stdout[0].to_i < 7
skip # Deferred function fixes only in puppet 7, see https://tickets.puppetlabs.com/browse/PUP-11518
end
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']