Skip to content

Commit

Permalink
Merge pull request #1487 from bastelfreak/connection
Browse files Browse the repository at this point in the history
Cleanup useless $connect_setting validation
  • Loading branch information
bastelfreak authored Aug 31, 2023
2 parents 8ac380b + ece7751 commit 934c5bb
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions manifests/server/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

# If possible use the version of the remote database, otherwise
# fallback to our local DB version
if $connect_settings != undef and 'DBVERSION' in $connect_settings {
if 'DBVERSION' in $connect_settings {
$version = $connect_settings['DBVERSION']
} else {
$version = $postgresql::server::_version
}

# If the connection settings do not contain a port, then use the local server port
if $connect_settings != undef and 'PGPORT' in $connect_settings {
if 'PGPORT' in $connect_settings {
$port = undef
} else {
$port = $postgresql::server::port
Expand Down
12 changes: 6 additions & 6 deletions manifests/server/default_privileges.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
) {
# If possible use the version of the remote database, otherwise
# fallback to our local DB version
if $connect_settings != undef and 'DBVERSION' in $connect_settings {
if 'DBVERSION' in $connect_settings {
$version = $connect_settings['DBVERSION']
} else {
$version = $postgresql::server::_version
Expand All @@ -62,15 +62,15 @@
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
if $port {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
} elsif 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
}

if $target_role != undef {
if $target_role {
$_target_role = " FOR ROLE ${target_role}"
$_check_target_role = "/${target_role}"
} else {
Expand Down Expand Up @@ -178,11 +178,11 @@
environment => 'PGOPTIONS=--client-min-messages=error',
}

if($role != undef and defined(Postgresql::Server::Role[$role])) {
if defined(Postgresql::Server::Role[$role]) {
Postgresql::Server::Role[$role] -> Postgresql_psql["default_privileges:${name}"]
}

if($db != undef and defined(Postgresql::Server::Database[$db])) {
if defined(Postgresql::Server::Database[$db]) {
Postgresql::Server::Database[$db] -> Postgresql_psql["default_privileges:${name}"]
}
}
4 changes: 2 additions & 2 deletions manifests/server/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
if $port {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
} elsif 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
Expand Down
6 changes: 3 additions & 3 deletions manifests/server/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
if $port {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = undef
Expand Down Expand Up @@ -483,11 +483,11 @@
onlyif => $_onlyif,
}

if($role != undef and defined(Postgresql::Server::Role[$role])) {
if defined(Postgresql::Server::Role[$role]) {
Postgresql::Server::Role[$role] -> Postgresql_psql["grant:${name}"]
}

if($db != undef and defined(Postgresql::Server::Database[$db])) {
if defined(Postgresql::Server::Database[$db]) {
Postgresql::Server::Database[$db] -> Postgresql_psql["grant:${name}"]
}
}
2 changes: 1 addition & 1 deletion manifests/server/grant_role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
connect_settings => $connect_settings,
}

if ! $connect_settings or empty($connect_settings) {
if empty($connect_settings) {
Class['postgresql::server'] -> Postgresql_psql["grant_role:${name}"]
}
if defined(Postgresql::Server::Role[$role]) {
Expand Down
13 changes: 4 additions & 9 deletions manifests/server/reassign_owned_by.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@
$group = $postgresql::server::group
$psql_path = $postgresql::server::psql_path

#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
if 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
$port_override = $port
}

$onlyif = "SELECT tablename FROM pg_catalog.pg_tables WHERE
Expand All @@ -54,14 +49,14 @@
onlyif => $onlyif,
}

if($old_role != undef and defined(Postgresql::Server::Role[$old_role])) {
if defined(Postgresql::Server::Role[$old_role]) {
Postgresql::Server::Role[$old_role] -> Postgresql_psql["reassign_owned_by:${db}:${sql_command}"]
}
if($new_role != undef and defined(Postgresql::Server::Role[$new_role])) {
Postgresql::Server::Role[$new_role] -> Postgresql_psql["reassign_owned_by:${db}:${sql_command}"]
}

if($db != undef and defined(Postgresql::Server::Database[$db])) {
if defined(Postgresql::Server::Database[$db]) {
Postgresql::Server::Database[$db] -> Postgresql_psql["reassign_owned_by:${db}:${sql_command}"]
}
}
6 changes: 3 additions & 3 deletions manifests/server/role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
if $port {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
} elsif 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
}

# If possible use the version of the remote database, otherwise
# fallback to our local DB version
if $connect_settings != undef and 'DBVERSION' in $connect_settings {
if 'DBVERSION' in $connect_settings {
$version = $connect_settings['DBVERSION']
} else {
$version = $postgresql::server::_version
Expand Down
2 changes: 1 addition & 1 deletion manifests/server/schema.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Postgresql::Server::Db <| dbname == $db |> -> Postgresql::Server::Schema[$name]

# If the connection settings do not contain a port, then use the local server port
if $connect_settings != undef and 'PGPORT' in $connect_settings {
if 'PGPORT' in $connect_settings {
$port = undef
} else {
$port = $postgresql::server::port
Expand Down
2 changes: 1 addition & 1 deletion manifests/server/tablespace.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$module_workdir = $postgresql::server::module_workdir

# If the connection settings do not contain a port, then use the local server port
if $connect_settings != undef and 'PGPORT' in $connect_settings {
if 'PGPORT' in $connect_settings {
$port = undef
} else {
$port = $postgresql::server::port
Expand Down

0 comments on commit 934c5bb

Please sign in to comment.