Skip to content

Commit 90e1522

Browse files
committed
Only require password when used
If the if in line 39 evaluates to false, the user has been created elsewhere, and we don't actually use (and thus need) password in `postgresql::server::db` class.
1 parent e53ff08 commit 90e1522

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

manifests/server/db.pp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# @summary Define for conveniently creating a role, database and assigning the correctpermissions.
22
#
3-
# @param user User to create and assign access to the database upon creation. Mandatory.
4-
# @param password Required Sets the password for the created user.
3+
# @param user User to assign access to the database upon creation (will be created if not defined elsewhere). Mandatory.
4+
# @param password Sets the password for the created user (if a user is created).
55
# @param comment Defines a comment to be stored about the database using the PostgreSQL COMMENT command.
66
# @param dbname Sets the name of the database to be created.
77
# @param encoding Overrides the character set during creation of the database.
@@ -13,7 +13,7 @@
1313
# @param owner Sets a user as the owner of the database.
1414
define postgresql::server::db (
1515
$user,
16-
Variant[String, Sensitive[String]] $password,
16+
Optional[Variant[String, Sensitive[String]]] $password = undef,
1717
$comment = undef,
1818
$dbname = $title,
1919
$encoding = $postgresql::server::encoding,
@@ -37,6 +37,9 @@
3737
}
3838

3939
if ! defined(Postgresql::Server::Role[$user]) {
40+
if ! $password {
41+
fail('Please provide password or create a user: if you rely on postgresql::server::db to create a user, a password is needed')
42+
}
4043
postgresql::server::role { $user:
4144
password_hash => $password,
4245
before => Postgresql::Server::Database[$dbname],

0 commit comments

Comments
 (0)