Skip to content

Commit

Permalink
Fix default password_encryption in postgresql_password based on params
Browse files Browse the repository at this point in the history
  • Loading branch information
cruelsmith committed Sep 6, 2023
1 parent 6db5691 commit 3e04518
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4429,6 +4429,8 @@ Data type: `Optional[Optional[Postgresql::Pg_password_encryption]]`

Set type for password hash

Default value comes from `postgresql::params::password_encryption` and changes based on the `postgresql::globals::version`.

##### `salt`

Data type: `Optional[Optional[Variant[String[1], Integer]]]`
Expand Down
5 changes: 4 additions & 1 deletion lib/puppet/functions/postgresql/postgresql_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# If the Postgresql-Passwordhash should be of Datatype Sensitive[String]
# @param hash
# Set type for password hash
#
# Default value comes from `postgresql::params::password_encryption` and changes based on the `postgresql::globals::version`.
# @param salt
# Use a specific salt value for scram-sha-256, default is username
#
Expand All @@ -27,7 +29,8 @@
return_type 'Variant[String, Sensitive[String]]'
end

def default_impl(username, password, sensitive = false, hash = 'md5', salt = nil)
def default_impl(username, password, sensitive = false, hash = nil, salt = nil)
hash = call_function(:'postgresql::default', 'password_encryption') if hash.nil?
password = password.unwrap if password.respond_to?(:unwrap)
if password.is_a?(String) && password.match?(%r{^(md5[0-9a-f]{32}$|SCRAM-SHA-256\$)})
return Puppet::Pops::Types::PSensitiveType::Sensitive.new(password) if sensitive
Expand Down
2 changes: 2 additions & 0 deletions spec/functions/postgresql_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
require 'spec_helper'

describe 'postgresql_password' do
include_examples 'Ubuntu 18.04'

it_behaves_like 'postgresql_password function'
end
2 changes: 2 additions & 0 deletions spec/functions/postgresql_postgresql_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
require 'spec_helper'

describe 'postgresql::postgresql_password' do
include_examples 'Ubuntu 18.04'

it_behaves_like 'postgresql_password function'
end

0 comments on commit 3e04518

Please sign in to comment.