Skip to content

Commit ad6a877

Browse files
authored
Merge pull request puppetlabs#1040 from Uninett/fix-hba-order
(MODULES-3804) Fix sort order of pg_hba_rule entries
2 parents 24b8015 + 95db843 commit ad6a877

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,12 @@ Specifies a way to uniquely identify this resource, but functionally does nothin
14001400

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

1403+
This can be either a string or an integer.
1404+
If it is an integer, it will be converted to a string by zero-padding it to three digits.
1405+
E.g. `42` will be zero-padded to the string `'042'`.
1406+
1407+
The `pg_hba_rule` fragments are sorted using the `alpha` sorting [order](https://forge.puppet.com/puppetlabs/concat/reference#order).
1408+
14031409
Default value: 150.
14041410

14051411
#### `postgresql_version`

manifests/server/pg_hba_rule.pp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
fail('You must specify an address property when type is host based')
3333
}
3434

35+
if $order =~ Integer {
36+
$_order = sprintf('%03d', $order)
37+
}
38+
else {
39+
$_order = $order
40+
}
41+
3542
$allowed_auth_methods = $postgresql_version ? {
3643
'10' => ['trust', 'reject', 'scram-sha-256', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
3744
'9.6' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'bsd'],
@@ -55,7 +62,7 @@
5562
concat::fragment { $fragname:
5663
target => $target,
5764
content => template('postgresql/pg_hba_rule.conf'),
58-
order => $order,
65+
order => $_order,
5966
}
6067
}
6168
}

spec/unit/defines/server/pg_hba_rule_spec.rb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,93 @@ class { 'postgresql::server': }
145145
end
146146
end
147147
end
148+
149+
context 'order' do
150+
context 'default' do
151+
let :pre_condition do
152+
<<-MANIFEST
153+
class { 'postgresql::server': }
154+
MANIFEST
155+
end
156+
157+
let :params do
158+
{
159+
type: 'local',
160+
database: 'all',
161+
user: 'all',
162+
auth_method: 'ident',
163+
}
164+
end
165+
166+
it do
167+
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '150')
168+
end
169+
end
170+
171+
context 'string' do
172+
let :pre_condition do
173+
<<-MANIFEST
174+
class { 'postgresql::server': }
175+
MANIFEST
176+
end
177+
178+
let :params do
179+
{
180+
type: 'local',
181+
database: 'all',
182+
user: 'all',
183+
auth_method: 'ident',
184+
order: '12',
185+
}
186+
end
187+
188+
it do
189+
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '12')
190+
end
191+
end
192+
193+
context 'short integer' do
194+
let :pre_condition do
195+
<<-MANIFEST
196+
class { 'postgresql::server': }
197+
MANIFEST
198+
end
199+
200+
let :params do
201+
{
202+
type: 'local',
203+
database: 'all',
204+
user: 'all',
205+
auth_method: 'ident',
206+
order: 12,
207+
}
208+
end
209+
210+
it do
211+
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '012')
212+
end
213+
end
214+
215+
context 'long integer' do
216+
let :pre_condition do
217+
<<-MANIFEST
218+
class { 'postgresql::server': }
219+
MANIFEST
220+
end
221+
222+
let :params do
223+
{
224+
type: 'local',
225+
database: 'all',
226+
user: 'all',
227+
auth_method: 'ident',
228+
order: 1234,
229+
}
230+
end
231+
232+
it do
233+
is_expected.to contain_concat__fragment('pg_hba_rule_test').with(order: '1234')
234+
end
235+
end
236+
end
148237
end

0 commit comments

Comments
 (0)