Skip to content

Commit

Permalink
Add option pool_lifetime option to ldap
Browse files Browse the repository at this point in the history
This patch adds another option to the ldap connection. Next to the other pool
connections, it is now possible to set the `pool_lifetime`.
  • Loading branch information
Sven Haardiek committed Dec 11, 2021
1 parent 43fd132 commit ce98675
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ config:
# pool_keepalive: seconds to wait between calls to server to keep the
# connection alive; default: 10
pool_keepalive: 10
# pool_lifetime: number of seconds before recreating a new connection
# in a pooled connection strategy.
pool_lifetime: None

# Attributes to return from LDAP query.
query_return_attributes:
Expand Down
6 changes: 6 additions & 0 deletions src/satosa/micro_services/ldap_attribute_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LdapAttributeStore(ResponseMicroService):
"client_strategy": "REUSABLE",
"pool_size": 10,
"pool_keepalive": 10,
"pool_lifetime": None,
}

def __init__(self, config, *args, **kwargs):
Expand Down Expand Up @@ -307,13 +308,17 @@ def _ldap_connection_factory(self, config):

pool_size = config["pool_size"]
pool_keepalive = config["pool_keepalive"]
pool_lifetime = config["pool_lifetime"]
pool_name = ''.join(random.sample(string.ascii_lowercase, 6))

if client_strategy == ldap3.REUSABLE:
msg = "Using pool size {}".format(pool_size)
logger.debug(msg)
msg = "Using pool keep alive {}".format(pool_keepalive)
logger.debug(msg)
if pool_lifetime:
msg = "Using pool lifetime {}".format(pool_lifetime)
logger.debug(msg)

try:
connection = ldap3.Connection(
Expand All @@ -327,6 +332,7 @@ def _ldap_connection_factory(self, config):
pool_name=pool_name,
pool_size=pool_size,
pool_keepalive=pool_keepalive,
pool_lifetime=pool_lifetime,
)
msg = "Successfully connected to LDAP server"
logger.debug(msg)
Expand Down

0 comments on commit ce98675

Please sign in to comment.