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

(MODULES-3804) Fix sort order of pg_hba_rule entries #1040

Merged
merged 1 commit into from
Jan 15, 2019
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,12 @@ Specifies a way to uniquely identify this resource, but functionally does nothin

Sets an order for placing the rule in `pg_hba.conf`.

This can be either a string or an integer.
If it is an integer, it will be converted to a string by zero-padding it to three digits.
E.g. `42` will be zero-padded to the string `'042'`.

The `pg_hba_rule` fragments are sorted using the `alpha` sorting [order](https://forge.puppet.com/puppetlabs/concat/reference#order).

Default value: 150.

#### `postgresql_version`
Expand Down
9 changes: 8 additions & 1 deletion manifests/server/pg_hba_rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
fail('You must specify an address property when type is host based')
}

if $order =~ Integer {
$_order = sprintf('%03d', $order)
}
else {
$_order = $order
}

$allowed_auth_methods = $postgresql_version ? {
'10' => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
'9.6' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
Expand All @@ -55,7 +62,7 @@
concat::fragment { $fragname:
target => $target,
content => template('postgresql/pg_hba_rule.conf'),
order => $order,
order => $_order,
}
}
}
89 changes: 89 additions & 0 deletions spec/unit/defines/server/pg_hba_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,93 @@ class { 'postgresql::server': }
end
end
end

context 'order' do
context 'default' do
let :pre_condition do
<<-MANIFEST
class { 'postgresql::server': }
MANIFEST
end

let :params do
{
type: 'local',
database: 'all',
user: 'all',
auth_method: 'ident',
}
end

it do
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '150')
end
end

context 'string' do
let :pre_condition do
<<-MANIFEST
class { 'postgresql::server': }
MANIFEST
end

let :params do
{
type: 'local',
database: 'all',
user: 'all',
auth_method: 'ident',
order: '12',
}
end

it do
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '12')
end
end

context 'short integer' do
let :pre_condition do
<<-MANIFEST
class { 'postgresql::server': }
MANIFEST
end

let :params do
{
type: 'local',
database: 'all',
user: 'all',
auth_method: 'ident',
order: 12,
}
end

it do
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '012')
end
end

context 'long integer' do
let :pre_condition do
<<-MANIFEST
class { 'postgresql::server': }
MANIFEST
end

let :params do
{
type: 'local',
database: 'all',
user: 'all',
auth_method: 'ident',
order: 1234,
}
end

it do
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '1234')
end
end
end
end