Skip to content

Commit 78e183c

Browse files
committed
Merge pull request #142 from kamilszymanski/connection_limit
Allow to set connection limit for new role
2 parents 490db27 + e7b25d6 commit 78e183c

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ Weither to grant super user capability for the new role. Defaults to `false`.
346346
####`replication`
347347
If `true` provides replication capabilities for this role. Defaults to `false`.
348348

349+
####`connection_limit`
350+
Specifies how many concurrent connections the role can make. Defaults to `-1` meaning no limit.
351+
349352
###Resource: postgresql::tablespace
350353
This defined type can be used to create a tablespace. For example:
351354

manifests/database_user.pp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@
3939

4040
define postgresql::database_user(
4141
$password_hash,
42-
$createdb = false,
43-
$createrole = false,
44-
$db = $postgresql::params::user,
45-
$superuser = false,
46-
$replication = false,
47-
$user = $title
42+
$createdb = false,
43+
$createrole = false,
44+
$db = $postgresql::params::user,
45+
$superuser = false,
46+
$replication = false,
47+
$connection_limit = -1,
48+
$user = $title
4849
) {
4950
postgresql::role { $user:
50-
db => $db,
51-
password_hash => $password_hash,
52-
login => true,
53-
createdb => $createdb,
54-
superuser => $superuser,
55-
createrole => $createrole,
56-
replication => $replication,
51+
db => $db,
52+
password_hash => $password_hash,
53+
login => true,
54+
createdb => $createdb,
55+
superuser => $superuser,
56+
createrole => $createrole,
57+
replication => $replication,
58+
connection_limit => $connection_limit,
5759
}
5860
}

manifests/role.pp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818

1919
define postgresql::role(
2020
$password_hash,
21-
$createdb = false,
22-
$createrole = false,
23-
$db = 'postgres',
24-
$login = false,
25-
$superuser = false,
26-
$replication = false,
27-
$username = $title
21+
$createdb = false,
22+
$createrole = false,
23+
$db = 'postgres',
24+
$login = false,
25+
$superuser = false,
26+
$replication = false,
27+
$connection_limit = -1,
28+
$username = $title
2829
) {
2930
include postgresql::params
3031

@@ -40,8 +41,8 @@
4041
$superuser_sql = $superuser ? { true => 'SUPERUSER' , default => 'NOSUPERUSER' }
4142
$replication_sql = $replication ? { true => 'REPLICATION' , default => '' }
4243

43-
# TODO: FIXME: Will not correct the superuser / createdb / createrole / login / replication status of a role that already exists
44-
postgresql_psql {"CREATE ROLE \"${username}\" ENCRYPTED PASSWORD '${password_hash}' ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql}":
44+
# TODO: FIXME: Will not correct the superuser / createdb / createrole / login / replication status nor the connection limit of a role that already exists
45+
postgresql_psql {"CREATE ROLE \"${username}\" ENCRYPTED PASSWORD '${password_hash}' ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}":
4546
db => $db,
4647
psql_user => $postgresql::params::user,
4748
unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'",

0 commit comments

Comments
 (0)