Skip to content

Commit 685e845

Browse files
authored
Merge branch 'be' into grant_loop
2 parents a5dadd6 + 4065abe commit 685e845

5 files changed

Lines changed: 52 additions & 12 deletions

File tree

manifests/globals.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
},
200200
'Amazon' => '9.2',
201201
default => $facts['os']['release']['major'] ? {
202+
'10' => '16',
202203
'9' => '13',
203204
'8' => '10',
204205
'7' => '9.2',

manifests/server.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
# @param pg_hba_auth_password_encryption
100100
# Specify the type of encryption set for the password in pg_hba_conf,
101101
# this value is usefull if you want to start enforcing scram-sha-256, but give users transition time.
102+
# @param databases Specifies a hash from which to generate postgresql::server::database resources.
102103
# @param roles Specifies a hash from which to generate postgresql::server::role resources.
103104
# @param grants Specifies a hash from which to generate postgresql::server::grant resources.
104105
# @param config_entries Specifies a hash from which to generate postgresql::server::config_entry resources.
@@ -186,6 +187,7 @@
186187
Optional[Postgresql::Pg_password_encryption] $pg_hba_auth_password_encryption = undef,
187188
Optional[String] $extra_systemd_config = $postgresql::params::extra_systemd_config,
188189

190+
Hash[String[1], Hash] $databases = {},
189191
Hash[String, Hash] $roles = {},
190192
Hash[String[1], Hash] $grants = {},
191193
Hash[String, Any] $config_entries = {},
@@ -215,6 +217,12 @@
215217
-> Class['postgresql::server::service']
216218
-> Class['postgresql::server::passwd']
217219

220+
$databases.each |$databasename, $database| {
221+
postgresql::server::database { $databasename:
222+
* => $database,
223+
}
224+
}
225+
218226
$roles.each |$rolename, $role| {
219227
postgresql::server::role { $rolename:
220228
* => $role,

manifests/server/default_privileges.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
}
146146

147147
$_unless = $ensure ? {
148-
'absent' => "SELECT 1 WHERE NOT EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s%s' = ANY (defaclacl)%s and defaclobjtype = '%s')", # lint:ignore:140chars
149-
default => "SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s%s' = ANY (defaclacl)%s and defaclobjtype = '%s')", # lint:ignore:140chars
148+
'absent' => "SELECT 1 WHERE NOT EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"%s\"=%s%s' = ANY (defaclacl)%s and defaclobjtype = '%s')", # lint:ignore:140chars
149+
default => "SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"%s\"=%s%s' = ANY (defaclacl)%s and defaclobjtype = '%s')", # lint:ignore:140chars
150150
}
151151

152152
$unless_cmd = sprintf($_unless, $role, $_check_privilege, $_check_target_role, $_check_schema, $_check_type)

metadata.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,25 @@
3131
"operatingsystemrelease": [
3232
"7",
3333
"8",
34-
"9"
34+
"9",
35+
"10"
3536
]
3637
},
3738
{
3839
"operatingsystem": "CentOS",
3940
"operatingsystemrelease": [
4041
"7",
4142
"8",
42-
"9"
43+
"9",
44+
"10"
4345
]
4446
},
4547
{
4648
"operatingsystem": "OracleLinux",
4749
"operatingsystemrelease": [
4850
"7",
49-
"9"
51+
"9",
52+
"10"
5053
]
5154
},
5255
{
@@ -84,14 +87,16 @@
8487
"operatingsystem": "Rocky",
8588
"operatingsystemrelease": [
8689
"8",
87-
"9"
90+
"9",
91+
"10"
8892
]
8993
},
9094
{
9195
"operatingsystem": "AlmaLinux",
9296
"operatingsystemrelease": [
9397
"8",
94-
"9"
98+
"9",
99+
"10"
95100
]
96101
}
97102
],

spec/defines/server/default_privileges_spec.rb

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,33 @@
9292
# rubocop:disable Layout/LineLength
9393
expect(subject).to contain_postgresql_psql('default_privileges:test')
9494
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test"')
95-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
95+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test\"=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
96+
# rubocop:enable Layout/LineLength
97+
end
98+
end
99+
100+
context 'supported privilege and a role name with a hyphen' do
101+
let :params do
102+
{
103+
db: 'test',
104+
role: 'test-foo',
105+
privilege: 'all',
106+
object_type: 'tables'
107+
}
108+
end
109+
110+
let :pre_condition do
111+
"class {'postgresql::server':}"
112+
end
113+
114+
it { is_expected.to compile.with_all_deps }
115+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
116+
117+
it do
118+
# rubocop:disable Layout/LineLength
119+
expect(subject).to contain_postgresql_psql('default_privileges:test')
120+
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test-foo"')
121+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test-foo\"=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
96122
# rubocop:enable Layout/LineLength
97123
end
98124
end
@@ -163,7 +189,7 @@ class { 'postgresql::server': }
163189
# rubocop:disable Layout/LineLength
164190
expect(subject).to contain_postgresql_psql('default_privileges:test')
165191
.with_command('ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO "test"')
166-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=UC' = ANY (defaclacl) AND nspname IS NULL and defaclobjtype = 'n')")
192+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test\"=UC' = ANY (defaclacl) AND nspname IS NULL and defaclobjtype = 'n')")
167193
# rubocop:enable Layout/LineLength
168194
end
169195
end
@@ -282,7 +308,7 @@ class { 'postgresql::server': }
282308
# rubocop:disable Layout/LineLength
283309
expect(subject).to contain_postgresql_psql('default_privileges:test')
284310
.with_command('ALTER DEFAULT PRIVILEGES IN SCHEMA my_schema GRANT ALL ON TABLES TO "test"')
285-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')")
311+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test\"=arwdDxt' = ANY (defaclacl) AND nspname = 'my_schema' and defaclobjtype = 'r')")
286312
# rubocop:enable Layout/LineLength
287313
end
288314
end
@@ -309,7 +335,7 @@ class { 'postgresql::server': }
309335
# rubocop:disable Layout/LineLength
310336
expect(subject).to contain_postgresql_psql('default_privileges:test')
311337
.with_command('ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO "test"')
312-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt' = ANY (defaclacl) AND nspname IS NULL and defaclobjtype = 'r')")
338+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test\"=arwdDxt' = ANY (defaclacl) AND nspname IS NULL and defaclobjtype = 'r')")
313339
# rubocop:enable Layout/LineLength
314340
end
315341
end
@@ -367,7 +393,7 @@ class {'postgresql::server':}
367393
# rubocop:disable Layout/LineLength
368394
expect(subject).to contain_postgresql_psql('default_privileges:test')
369395
.with_command('ALTER DEFAULT PRIVILEGES FOR ROLE target IN SCHEMA public GRANT ALL ON TABLES TO "test"')
370-
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=arwdDxt/target' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
396+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '\"test\"=arwdDxt/target' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r')")
371397
# rubocop:enable Layout/LineLength
372398
end
373399
end

0 commit comments

Comments
 (0)