From 4779865ea30dba0b5f0594cdc4633b0cc93bf36a Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 21 Jan 2013 08:39:09 -0500 Subject: Replace getList by a get_entries method The find_entries method is cumbersome to use: it requires keyword arguments for simple uses, and callers are tempted to ignore the 'truncated' flag it returns. Introduce a simpler method, get_entries, that returns the found list directly, and raises an errors if the list is truncated. Replace the getList method by get_entries. Part of the work for: https://fedorahosted.org/freeipa/ticket/2660 --- ipaserver/ipaldap.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'ipaserver/ipaldap.py') diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py index 7fceb889..78021201 100644 --- a/ipaserver/ipaldap.py +++ b/ipaserver/ipaldap.py @@ -1069,6 +1069,24 @@ class LDAPConnection(object): ) return self.combine_filters(flts, rules) + def get_entries(self, base_dn, scope=None, filter=None, attrs_list=None): + """Return a list of matching entries. + + Raises an error if the list is truncated by the server + + :param base_dn: dn of the entry at which to start the search + :param scope: search scope, see LDAP docs (default ldap2.SCOPE_SUBTREE) + :param filter: LDAP filter to apply + :param attrs_list: ist of attributes to return, all if None (default) + + Use the find_entries method for more options. + """ + entries, truncated = self.find_entries( + base_dn=base_dn, scope=scope, filter=filter, attrs_list=attrs_list) + if truncated: + raise errors.LimitsExceeded() + return entries + def find_entries(self, filter=None, attrs_list=None, base_dn=None, scope=_ldap.SCOPE_SUBTREE, time_limit=None, size_limit=None, normalize=True, search_refs=False): @@ -1629,16 +1647,6 @@ class IPAdmin(LDAPConnection): ) return result[0] - def getList(self, base, scope, filterstr='(objectClass=*)', attrlist=None): - # FIXME: for backwards compatibility only - result, truncated = self.find_entries( - filter=filterstr, - attrs_list=attrlist, - base_dn=base, - scope=scope, - ) - return result - def addEntry(self, entry): # FIXME: for backwards compatibility only self.add_entry(entry.dn, entry) -- cgit