Skip to content

Commit d5192aa

Browse files
uniform port parameter and $port_override value assignment
1 parent 2a4e7bb commit d5192aa

File tree

6 files changed

+23
-48
lines changed

6 files changed

+23
-48
lines changed

manifests/server/database.pp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# @param locale Overrides the locale during creation of the database.
1010
# @param istemplate Defines the database as a template if set to true.
1111
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
12+
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
1213
define postgresql::server::database (
1314
Optional[String[1]] $comment = undef,
1415
String[1] $dbname = $title,
@@ -19,6 +20,7 @@
1920
Optional[String[1]] $locale = $postgresql::server::locale,
2021
Boolean $istemplate = false,
2122
Hash $connect_settings = $postgresql::server::default_connect_settings,
23+
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::params::port,
2224
) {
2325
$createdb_path = $postgresql::server::createdb_path
2426
$user = $postgresql::server::user
@@ -34,11 +36,10 @@
3436
$version = $postgresql::server::_version
3537
}
3638

37-
# If the connection settings do not contain a port, then use the local server port
3839
if $connect_settings != undef and 'PGPORT' in $connect_settings {
39-
$port = undef
40+
$port_override = $port
4041
} else {
41-
$port = $postgresql::server::port
42+
$port_override = $port
4243
}
4344

4445
# Set the defaults for the postgresql_psql resource
@@ -47,7 +48,7 @@
4748
psql_user => $user,
4849
psql_group => $group,
4950
psql_path => $psql_path,
50-
port => $port,
51+
port => $port_override,
5152
connect_settings => $connect_settings,
5253
}
5354

manifests/server/default_privileges.pp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# @param psql_db Defines the database to execute the grant against. This should not ordinarily be changed from the default.
1111
# @param psql_user Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
1212
# @param psql_path Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
13-
# @param port Specifies the port to access the server. Default value: The default user for the module, usually '5432'.
13+
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
1414
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1515
# @param group Specifies the user group to which the privileges will be granted.
1616
define postgresql::server::default_privileges (
@@ -59,15 +59,10 @@
5959
}
6060
}
6161

62-
#
63-
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
64-
#
65-
if $port != undef {
62+
if $connect_settings != undef and 'PGPORT' in $connect_settings {
6663
$port_override = $port
67-
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
68-
$port_override = undef
6964
} else {
70-
$port_override = $postgresql::server::port
65+
$port_override = $port
7166
}
7267

7368
if $target_role != undef {

manifests/server/extension.pp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# @param package_ensure
1919
# Overrides default package deletion behavior. By default, the package specified with package_name is installed when the extension is
2020
# activated and removed when the extension is deactivated. To override this behavior, set the ensure value for the package.
21-
# @param port Port to use when connecting.
21+
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
2222
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
2323
# @param database_resource_name Specifies the resource name of the DB being managed. Defaults to the parameter $database, if left blank.
2424
define postgresql::server::extension (
@@ -29,7 +29,7 @@
2929
Optional[String[1]] $version = undef,
3030
Enum['present', 'absent'] $ensure = 'present',
3131
Optional[String[1]] $package_name = undef,
32-
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
32+
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
3333
Hash $connect_settings = postgresql::default('default_connect_settings'),
3434
String[1] $database_resource_name = $database,
3535
) {
@@ -74,24 +74,17 @@
7474
}
7575
}
7676

77-
#
78-
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
79-
#
80-
if $port != undef {
77+
if $connect_settings != undef and 'PGPORT' in $connect_settings {
8178
$port_override = $port
82-
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
83-
$port_override = undef
8479
} else {
85-
$port_override = $postgresql::server::port
80+
$port_override = $port
8681
}
8782

8883
postgresql_psql { "${database}: ${command}":
89-
9084
psql_user => $user,
9185
psql_group => $group,
9286
psql_path => $psql_path,
9387
connect_settings => $connect_settings,
94-
9588
db => $database,
9689
port => $port_override,
9790
command => $command,

manifests/server/grant.pp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# @param object_arguments Specifies any arguments to be passed alongisde the access grant.
1313
# @param psql_db Specifies the database to execute the grant against. This should not ordinarily be changed from the default
1414
# @param psql_user Sets the OS user to run psql.
15-
# @param port Port to use when connecting.
15+
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
1616
# @param onlyif_exists Create grant only if doesn't exist
1717
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1818
# @param ensure Specifies whether to grant or revoke the privilege. Default is to grant the privilege. Valid values: 'present', 'absent'.
@@ -74,15 +74,10 @@
7474
$_object_name = $object_name
7575
}
7676

77-
#
78-
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
79-
#
80-
if $port != undef {
77+
if $connect_settings != undef and 'PGPORT' in $connect_settings {
8178
$port_override = $port
82-
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
83-
$port_override = undef
8479
} else {
85-
$port_override = $postgresql::server::port
80+
$port_override = $port
8681
}
8782

8883
## Munge the input values

manifests/server/reassign_owned_by.pp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# @summary Define for reassigning the ownership of objects within a database.
22
# @note
33
# This enables us to force the a particular ownership for objects within a database
4-
#
4+
#
55
# @param old_role Specifies the role or user who is the current owner of the objects in the specified db
66
# @param new_role Specifies the role or user who will be the new owner of these objects
77
# @param db Specifies the database to which the 'REASSIGN OWNED' will be applied
88
# @param psql_user Specifies the OS user for running psql.
9-
# @param port Port to use when connecting.
9+
# @param port Specifies the port for the PostgreSQL server port to connect to, default is 5432.
1010
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1111
define postgresql::server::reassign_owned_by (
1212
String $old_role,
@@ -21,15 +21,10 @@
2121
$group = $postgresql::server::group
2222
$psql_path = $postgresql::server::psql_path
2323

24-
#
25-
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
26-
#
27-
if $port != undef {
24+
if $connect_settings != undef and 'PGPORT' in $connect_settings {
2825
$port_override = $port
29-
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
30-
$port_override = undef
3126
} else {
32-
$port_override = $postgresql::server::port
27+
$port_override = $port
3328
}
3429

3530
$onlyif = "SELECT tablename FROM pg_catalog.pg_tables WHERE

manifests/server/role.pp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Boolean $createdb = false,
3030
Boolean $createrole = false,
3131
String[1] $db = $postgresql::server::default_database,
32-
Optional[Variant[String[1], Stdlib::Port, Integer]] $port = undef,
32+
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
3333
Boolean $login = true,
3434
Boolean $inherit = true,
3535
Boolean $superuser = false,
@@ -50,15 +50,11 @@
5050
} else {
5151
$password_hash
5252
}
53-
#
54-
# Port, order of precedence: $port parameter, $connect_settings[PGPORT], $postgresql::server::port
55-
#
56-
if $port != undef {
53+
54+
if $connect_settings != undef and 'PGPORT' in $connect_settings {
5755
$port_override = $port
58-
} elsif $connect_settings != undef and 'PGPORT' in $connect_settings {
59-
$port_override = undef
6056
} else {
61-
$port_override = $postgresql::server::port
57+
$port_override = $port
6258
}
6359

6460
# If possible use the version of the remote database, otherwise

0 commit comments

Comments
 (0)