Skip to content

Allow usage of grant and role when not managing postgresql::server #1159

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

Merged
merged 1 commit into from
Apr 1, 2020
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: 4 additions & 2 deletions manifests/server/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# @param onlyif_exists Create grant only if doesn't exist
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param ensure Specifies whether to grant or revoke the privilege. Default is to grant the privilege. Valid values: 'present', 'absent'.
# @param group Sets the OS group to run psql
# @param psql_path Sets the path to psql command
define postgresql::server::grant (
String $role,
String $db,
Expand Down Expand Up @@ -44,6 +46,8 @@
Enum['present',
'absent'
] $ensure = 'present',
String $group = $postgresql::server::group,
String $psql_path = $postgresql::server::psql_path,
) {

case $ensure {
Expand All @@ -60,8 +64,6 @@
}
}

$group = $postgresql::server::group
$psql_path = $postgresql::server::psql_path

if ! $object_name {
$_object_name = $db
Expand Down
12 changes: 8 additions & 4 deletions manifests/server/role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# @param username Defines the username of the role to create.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param ensure Specify whether to create or drop the role. Specifying 'present' creates the role. Specifying 'absent' drops the role.
# @param psql_user Sets the OS user to run psql
# @param psql_group Sets the OS group to run psql
# @param psql_path Sets path to psql command
# @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.
define postgresql::server::role(
$update_password = true,
$password_hash = false,
Expand All @@ -28,12 +32,12 @@
$connection_limit = '-1',
$username = $title,
$connect_settings = $postgresql::server::default_connect_settings,
$psql_user = $postgresql::server::user,
$psql_group = $postgresql::server::group,
$psql_path = $postgresql::server::psql_path,
$module_workdir = $postgresql::server::module_workdir,
Enum['present', 'absent'] $ensure = 'present',
) {
$psql_user = $postgresql::server::user
$psql_group = $postgresql::server::group
$psql_path = $postgresql::server::psql_path
$module_workdir = $postgresql::server::module_workdir

#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
Expand Down
22 changes: 22 additions & 0 deletions spec/unit/defines/server/grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ class {'postgresql::server':}
end
end

context 'standalone not managing server' do
let :params do
{
db: 'test',
role: 'test',
privilege: 'execute',
object_name: ['myschema', 'test'],
object_arguments: ['text', 'boolean'],
object_type: 'function',
group: 'postgresql',
psql_path: '/usr/bin',
psql_user: 'postgres',
psql_db: 'db',
port: 1542,
connect_settings: {},
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_class('postgresql::server') }
end

context 'invalid object_type' do
let :params do
{
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/defines/server/role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,29 @@
it { is_expected.to compile }
it { is_expected.to contain_postgresql__server__role('test') }
end

context 'standalone not managing server' do
let :params do
{
password_hash: 'new-pa$s',
connect_settings: { 'PGHOST' => 'postgres-db-server',
'DBVERSION' => '9.1',
'PGPORT' => '1234',
'PGUSER' => 'login-user',
'PGPASSWORD' => 'login-pass' },
psql_user: 'postgresql',
psql_group: 'postgresql',
psql_path: '/usr/bin',
module_workdir: '/tmp',
db: 'db',
}
end

let :pre_condition do
''
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_class('postgresql::server') }
end
end