Skip to content

Commit

Permalink
uniform port parameter and $port_override value assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHoenscheid committed Aug 25, 2023
1 parent 2a4e7bb commit d5192aa
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 48 deletions.
9 changes: 5 additions & 4 deletions manifests/server/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# @param locale Overrides the locale during creation of the database.
# @param istemplate Defines the database as a template if set to true.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
define postgresql::server::database (
Optional[String[1]] $comment = undef,
String[1] $dbname = $title,
Expand All @@ -19,6 +20,7 @@
Optional[String[1]] $locale = $postgresql::server::locale,
Boolean $istemplate = false,
Hash $connect_settings = $postgresql::server::default_connect_settings,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::params::port,
) {
$createdb_path = $postgresql::server::createdb_path
$user = $postgresql::server::user
Expand All @@ -34,11 +36,10 @@
$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 {
$port = undef
$port_override = $port
} else {
$port = $postgresql::server::port
$port_override = $port
}

# Set the defaults for the postgresql_psql resource
Expand All @@ -47,7 +48,7 @@
psql_user => $user,
psql_group => $group,
psql_path => $psql_path,
port => $port,
port => $port_override,
connect_settings => $connect_settings,
}

Expand Down
11 changes: 3 additions & 8 deletions manifests/server/default_privileges.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# @param psql_db Defines the database to execute the grant against. This should not ordinarily be changed from the default.
# @param psql_user Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
# @param psql_path Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
# @param port Specifies the port to access the server. Default value: The default user for the module, usually '5432'.
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param group Specifies the user group to which the privileges will be granted.
define postgresql::server::default_privileges (
Expand Down Expand Up @@ -59,15 +59,10 @@
}
}

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

if $target_role != undef {
Expand Down
15 changes: 4 additions & 11 deletions manifests/server/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# @param package_ensure
# Overrides default package deletion behavior. By default, the package specified with package_name is installed when the extension is
# activated and removed when the extension is deactivated. To override this behavior, set the ensure value for the package.
# @param port Port to use when connecting.
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param database_resource_name Specifies the resource name of the DB being managed. Defaults to the parameter $database, if left blank.
define postgresql::server::extension (
Expand All @@ -29,7 +29,7 @@
Optional[String[1]] $version = undef,
Enum['present', 'absent'] $ensure = 'present',
Optional[String[1]] $package_name = undef,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Hash $connect_settings = postgresql::default('default_connect_settings'),
String[1] $database_resource_name = $database,
) {
Expand Down Expand Up @@ -74,24 +74,17 @@
}
}

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

postgresql_psql { "${database}: ${command}":

psql_user => $user,
psql_group => $group,
psql_path => $psql_path,
connect_settings => $connect_settings,

db => $database,
port => $port_override,
command => $command,
Expand Down
11 changes: 3 additions & 8 deletions manifests/server/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# @param object_arguments Specifies any arguments to be passed alongisde the access grant.
# @param psql_db Specifies the database to execute the grant against. This should not ordinarily be changed from the default
# @param psql_user Sets the OS user to run psql.
# @param port Port to use when connecting.
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
# @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'.
Expand Down Expand Up @@ -74,15 +74,10 @@
$_object_name = $object_name
}

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

## Munge the input values
Expand Down
13 changes: 4 additions & 9 deletions manifests/server/reassign_owned_by.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# @summary Define for reassigning the ownership of objects within a database.
# @note
# This enables us to force the a particular ownership for objects within a database
#
#
# @param old_role Specifies the role or user who is the current owner of the objects in the specified db
# @param new_role Specifies the role or user who will be the new owner of these objects
# @param db Specifies the database to which the 'REASSIGN OWNED' will be applied
# @param psql_user Specifies the OS user for running psql.
# @param port Port to use when connecting.
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
define postgresql::server::reassign_owned_by (
String $old_role,
Expand All @@ -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 != undef {
if $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = $port
} elsif $connect_settings != undef and '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 Down
12 changes: 4 additions & 8 deletions manifests/server/role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Boolean $createdb = false,
Boolean $createrole = false,
String[1] $db = $postgresql::server::default_database,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Boolean $login = true,
Boolean $inherit = true,
Boolean $superuser = false,
Expand All @@ -50,15 +50,11 @@
} else {
$password_hash
}
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {

if $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
$port_override = $port
}

# If possible use the version of the remote database, otherwise
Expand Down

0 comments on commit d5192aa

Please sign in to comment.