Skip to content

Commit 57daae5

Browse files
author
Martin Alfke
committed
Allow usage of grant and role when not managing postgresql::server
Some installations use other ways to install postgresql. But people still want to make use of grant and role defined type
1 parent 89ba58d commit 57daae5

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

manifests/server/grant.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# @param onlyif_exists Create grant only if doesn't exist
1212
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1313
# @param ensure Specifies whether to grant or revoke the privilege. Default is to grant the privilege. Valid values: 'present', 'absent'.
14+
# @param group Sets the OS group to run psql
15+
# @param psql_path Sets the path to psql command
1416
define postgresql::server::grant (
1517
String $role,
1618
String $db,
@@ -44,6 +46,8 @@
4446
Enum['present',
4547
'absent'
4648
] $ensure = 'present',
49+
String $group = $postgresql::server::group,
50+
String $psql_path = $postgresql::server::psql_path,
4751
) {
4852

4953
case $ensure {
@@ -60,8 +64,6 @@
6064
}
6165
}
6266

63-
$group = $postgresql::server::group
64-
$psql_path = $postgresql::server::psql_path
6567

6668
if ! $object_name {
6769
$_object_name = $db

manifests/server/role.pp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# @param username Defines the username of the role to create.
1515
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1616
# @param ensure Specify whether to create or drop the role. Specifying 'present' creates the role. Specifying 'absent' drops the role.
17+
# @param psql_user Sets the OS user to run psql
18+
# @param psql_group Sets the OS group to run psql
19+
# @param psql_path Sets path to psql command
20+
# @param module_workdir Specifies working directory under which the psql command should be executed. May need to specify if '/tmp' is on volume mounted with noexec option.
1721
define postgresql::server::role(
1822
$update_password = true,
1923
$password_hash = false,
@@ -28,12 +32,12 @@
2832
$connection_limit = '-1',
2933
$username = $title,
3034
$connect_settings = $postgresql::server::default_connect_settings,
35+
$psql_user = $postgresql::server::user,
36+
$psql_group = $postgresql::server::group,
37+
$psql_path = $postgresql::server::psql_path,
38+
$module_workdir = $postgresql::server::module_workdir,
3139
Enum['present', 'absent'] $ensure = 'present',
3240
) {
33-
$psql_user = $postgresql::server::user
34-
$psql_group = $postgresql::server::group
35-
$psql_path = $postgresql::server::psql_path
36-
$module_workdir = $postgresql::server::module_workdir
3741

3842
#
3943
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port

spec/unit/defines/server/grant_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,28 @@ class {'postgresql::server':}
292292
end
293293
end
294294

295+
context 'standalone not managing server' do
296+
let :params do
297+
{
298+
db: 'test',
299+
role: 'test',
300+
privilege: 'execute',
301+
object_name: ['myschema', 'test'],
302+
object_arguments: ['text', 'boolean'],
303+
object_type: 'function',
304+
group: 'postgresql',
305+
psql_path: '/usr/bin',
306+
psql_user: 'postgres',
307+
psql_db: 'db',
308+
port: 1542,
309+
connect_settings: {},
310+
}
311+
end
312+
313+
it { is_expected.to compile.with_all_deps }
314+
it { is_expected.not_to contain_class('postgresql::server') }
315+
end
316+
295317
context 'invalid object_type' do
296318
let :params do
297319
{

spec/unit/defines/server/role_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,29 @@
147147
it { is_expected.to compile }
148148
it { is_expected.to contain_postgresql__server__role('test') }
149149
end
150+
151+
context 'standalone not managing server' do
152+
let :params do
153+
{
154+
password_hash: 'new-pa$s',
155+
connect_settings: { 'PGHOST' => 'postgres-db-server',
156+
'DBVERSION' => '9.1',
157+
'PGPORT' => '1234',
158+
'PGUSER' => 'login-user',
159+
'PGPASSWORD' => 'login-pass' },
160+
psql_user: 'postgresql',
161+
psql_group: 'postgresql',
162+
psql_path: '/usr/bin',
163+
module_workdir: '/tmp',
164+
db: 'db',
165+
}
166+
end
167+
168+
let :pre_condition do
169+
''
170+
end
171+
172+
it { is_expected.to compile.with_all_deps }
173+
it { is_expected.not_to contain_class('postgresql::server') }
174+
end
150175
end

0 commit comments

Comments
 (0)