ldap: add nocache parameter to LdapClient.get_objects method
Some checks failed
Run tests / tests (push) Failing after 1m32s

This commit is contained in:
Benjamin Renard 2024-06-12 10:27:37 +02:00
parent 9e3faee819
commit 384e8a441d
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -575,6 +575,7 @@ class LdapClient:
warn=True,
paged_search=False,
pagesize=None,
nocache=False,
):
"""
Retrieve objects from LDAP
@ -592,9 +593,11 @@ class LdapClient:
(optional, default: False)
:param pagesize: When using paged search, the page size
(optional, default: see LdapServer.paged_search)
:param nocache: If True, disable using cache
"""
if name in self._cached_objects:
if name in self._cached_objects and not nocache:
log.debug("Retrieved %s objects from cache", name)
objects = self._cached_objects[name]
else:
assert self._conn or self.initialize()
log.debug(
@ -624,13 +627,11 @@ class LdapClient:
if not obj_dn or not isinstance(obj_attrs, dict):
continue
objects[obj_dn] = self._get_obj(obj_dn, obj_attrs)
if not nocache:
self._cached_objects[name] = objects
if not key_attr or key_attr == "dn":
return self._cached_objects[name]
return {
self.get_attr(self._cached_objects[name][dn], key_attr): self._cached_objects[name][dn]
for dn in self._cached_objects[name]
}
return objects
return {self.get_attr(objects[dn], key_attr): objects[dn] for dn in objects}
def get_object(self, type_name, object_name, filterstr, basedn, attrs, warn=True):
"""