Skip to content
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

uniform port parameter and $port_override value assignment #1469

Closed
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
11 changes: 4 additions & 7 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,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
) {
$createdb_path = $postgresql::server::createdb_path
$user = $postgresql::server::user
Expand All @@ -34,20 +36,15 @@
$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
} else {
$port = $postgresql::server::port
}
$port_override = pick($port, $postgresql::server::port)

# Set the defaults for the postgresql_psql resource
Postgresql_psql {
db => $default_db,
psql_user => $user,
psql_group => $group,
psql_path => $psql_path,
port => $port,
port => $port_override,
connect_settings => $connect_settings,
}

Expand Down
15 changes: 3 additions & 12 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 All @@ -28,7 +28,7 @@
String $schema = 'public',
String $psql_db = $postgresql::server::default_database,
String $psql_user = $postgresql::server::user,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
Hash $connect_settings = $postgresql::server::default_connect_settings,
Enum['present', 'absent'] $ensure = 'present',
String $group = $postgresql::server::group,
Expand Down Expand Up @@ -59,16 +59,7 @@
}
}

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

if $target_role != undef {
$_target_role = " FOR ROLE ${target_role}"
Expand Down
16 changes: 2 additions & 14 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 Down Expand Up @@ -73,25 +73,13 @@
fail("Unknown value for ensure '${ensure}'.")
}
}

#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
}
$port_override = pick($port, $postgresql::server::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
15 changes: 3 additions & 12 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 @@ -41,7 +41,7 @@
Array[String[1],0] $object_arguments = [],
String $psql_db = $postgresql::server::default_database,
String $psql_user = $postgresql::server::user,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
Boolean $onlyif_exists = false,
Hash $connect_settings = $postgresql::server::default_connect_settings,
Enum['present', 'absent'] $ensure = 'present',
Expand Down Expand Up @@ -74,16 +74,7 @@
$_object_name = $object_name
}

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

## Munge the input values
$_object_type = upcase($object_type)
Expand Down
17 changes: 4 additions & 13 deletions manifests/server/reassign_owned_by.pp
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
# @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,
String $new_role,
String $db,
String $psql_user = $postgresql::server::user,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
Hash $connect_settings = $postgresql::server::default_connect_settings,
) {
$sql_command = "REASSIGN OWNED BY \"${old_role}\" TO \"${new_role}\""

$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 {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
}
$port_override = pick($port, $postgresql::server::port)

$onlyif = "SELECT tablename FROM pg_catalog.pg_tables WHERE
schemaname NOT IN ('pg_catalog', 'information_schema') AND
Expand Down
12 changes: 2 additions & 10 deletions manifests/server/role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,8 @@
} else {
$password_hash
}
#
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
#
if $port != undef {
$port_override = $port
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
$port_override = undef
} else {
$port_override = $postgresql::server::port
}

$port_override = pick($port, $postgresql::server::port)

# If possible use the version of the remote database, otherwise
# fallback to our local DB version
Expand Down
Loading