ldap.LdapClient.get_objects: add paged_search & pagesize parameters
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Benjamin Renard 2022-07-20 10:52:10 +02:00
parent 86eae5dae5
commit 31eeff367c

View file

@ -538,7 +538,8 @@ class LdapClient:
return vals if all_values else vals[0] return vals if all_values else vals[0]
return default if default or not all_values else [] return default if default or not all_values else []
def get_objects(self, name, filterstr, basedn, attrs, key_attr=None, warn=True): def get_objects(self, name, filterstr, basedn, attrs, key_attr=None, warn=True,
paged_search=False, pagesize=None):
""" """
Retrieve objects from LDAP Retrieve objects from LDAP
@ -551,17 +552,25 @@ class LdapClient:
:param warn: If True, a warning message will be logged if no object is found :param warn: If True, a warning message will be logged if no object is found
in LDAP directory (otherwise, it will be just a debug message) in LDAP directory (otherwise, it will be just a debug message)
(optional, default: True) (optional, default: True)
:param paged_search: If True, use paged search to list objects from LDAP directory
(optional, default: False)
:param pagesize: When using paged search, the page size
(optional, default: see LdapServer.paged_search)
""" """
if name in self._cached_objects: if name in self._cached_objects:
log.debug('Retreived %s objects from cache', name) log.debug('Retreived %s objects from cache', name)
else: else:
assert self._conn or self.initialize() assert self._conn or self.initialize()
log.debug('Looking for LDAP %s with (filter="%s" / basedn="%s")', name, filterstr, basedn) log.debug('Looking for LDAP %s with (filter="%s" / basedn="%s")', name, filterstr, basedn)
ldap_data = self._conn.search( if paged_search:
basedn=basedn, ldap_data = self._conn.paged_search(
filterstr=filterstr, basedn=basedn, filterstr=filterstr, attrs=attrs,
attrs=attrs pagesize=pagesize
) )
else:
ldap_data = self._conn.search(
basedn=basedn, filterstr=filterstr, attrs=attrs,
)
if not ldap_data: if not ldap_data:
if warn: if warn: