From 31eeff367c50b0c3481e9bfa465cbe411cc866b6 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 20 Jul 2022 10:52:10 +0200 Subject: [PATCH] ldap.LdapClient.get_objects: add paged_search & pagesize parameters --- mylib/ldap.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mylib/ldap.py b/mylib/ldap.py index 8748309..2bf9079 100644 --- a/mylib/ldap.py +++ b/mylib/ldap.py @@ -538,7 +538,8 @@ class LdapClient: return vals if all_values else vals[0] 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 @@ -551,17 +552,25 @@ class LdapClient: :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) (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: log.debug('Retreived %s objects from cache', name) else: assert self._conn or self.initialize() log.debug('Looking for LDAP %s with (filter="%s" / basedn="%s")', name, filterstr, basedn) - ldap_data = self._conn.search( - basedn=basedn, - filterstr=filterstr, - attrs=attrs - ) + if paged_search: + ldap_data = self._conn.paged_search( + basedn=basedn, filterstr=filterstr, attrs=attrs, + pagesize=pagesize + ) + else: + ldap_data = self._conn.search( + basedn=basedn, filterstr=filterstr, attrs=attrs, + ) if not ldap_data: if warn: