Skip to content

Commit ee913b2

Browse files
committed
Add option pool_lifetime option to ldap
This patch adds another option to the ldap connection. Next to the other pool connections, it is now possible to set the `pool_lifetime`.
1 parent 014e121 commit ee913b2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

example/plugins/microservices/ldap_attribute_store.yaml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ config:
2727
# pool_keepalive: seconds to wait between calls to server to keep the
2828
# connection alive; default: 10
2929
pool_keepalive: 10
30+
# pool_lifetime: number of seconds before recreating a new connection
31+
# in a pooled connection strategy.
32+
pool_lifetime: None
3033

3134
# Attributes to return from LDAP query.
3235
query_return_attributes:

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class LdapAttributeStore(ResponseMicroService):
6161
"client_strategy": "REUSABLE",
6262
"pool_size": 10,
6363
"pool_keepalive": 10,
64+
"pool_lifetime": None,
6465
}
6566

6667
def __init__(self, config, *args, **kwargs):
@@ -307,13 +308,17 @@ def _ldap_connection_factory(self, config):
307308

308309
pool_size = config["pool_size"]
309310
pool_keepalive = config["pool_keepalive"]
311+
pool_lifetime = config["pool_lifetime"]
310312
pool_name = ''.join(random.sample(string.ascii_lowercase, 6))
311313

312314
if client_strategy == ldap3.REUSABLE:
313315
msg = "Using pool size {}".format(pool_size)
314316
logger.debug(msg)
315317
msg = "Using pool keep alive {}".format(pool_keepalive)
316318
logger.debug(msg)
319+
if pool_lifetime:
320+
msg = "Using pool lifetime {}".format(pool_lifetime)
321+
logger.debug(msg)
317322

318323
try:
319324
connection = ldap3.Connection(
@@ -327,6 +332,7 @@ def _ldap_connection_factory(self, config):
327332
pool_name=pool_name,
328333
pool_size=pool_size,
329334
pool_keepalive=pool_keepalive,
335+
pool_lifetime=pool_lifetime,
330336
)
331337
msg = "Successfully connected to LDAP server"
332338
logger.debug(msg)

0 commit comments

Comments
 (0)