diff options
author | Petr Viktorin <pviktori@redhat.com> | 2013-01-18 08:16:55 -0500 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2013-03-01 16:59:43 +0100 |
commit | d9b3c91d47b246f2bafbe290c4988d0faf3a8cea (patch) | |
tree | 13bb52d6017440cde722daef839f21737134e474 | |
parent | a7a81238a8caea31c322be9acc19662ca9192870 (diff) | |
download | freeipa.git-d9b3c91d47b246f2bafbe290c4988d0faf3a8cea.tar.gz freeipa.git-d9b3c91d47b246f2bafbe290c4988d0faf3a8cea.tar.xz freeipa.git-d9b3c91d47b246f2bafbe290c4988d0faf3a8cea.zip |
Implement some of IPAdmin's legacy methods in terms of LDAPConnection methods
These will serve as templates for changes in the calling code.
Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
-rw-r--r-- | ipaserver/ipaldap.py | 82 |
1 files changed, 25 insertions, 57 deletions
diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py index 9abd3b72..40d9f9e8 100644 --- a/ipaserver/ipaldap.py +++ b/ipaserver/ipaldap.py @@ -1651,60 +1651,34 @@ class IPAdmin(LDAPConnection): self.__bind_with_wait(self.sasl_interactive_bind_s, timeout, None, auth_tokens) self.__lateinit() - def getEntry(self, base, scope, filterstr='(objectClass=*)', attrlist=None, attrsonly=0): - """This wraps the search function. It is common to just get one entry""" - - try: - res = self.search(base, scope, filterstr, attrlist, attrsonly) - objtype, obj = self.result(res) - except ldap.LDAPError, e: - arg_desc = 'base="%s", scope=%s, filterstr="%s"' % (base, scope, filterstr) - self.__handle_errors(e, arg_desc=arg_desc) - - if not obj: - arg_desc = 'base="%s", scope=%s, filterstr="%s"' % (base, scope, filterstr) - raise errors.NotFound(reason=arg_desc) - - elif isinstance(obj,Entry): - return obj - else: # assume list/tuple - return obj[0] - - def getList(self, base, scope, filterstr='(objectClass=*)', attrlist=None, attrsonly=0): - """This wraps the search function to find multiple entries.""" - - try: - res = self.search(base, scope, filterstr, attrlist, attrsonly) - objtype, obj = self.result(res) - except ldap.LDAPError, e: - arg_desc = 'base="%s", scope=%s, filterstr="%s"' % (base, scope, filterstr) - self.__handle_errors(e, arg_desc=arg_desc) - - if not obj: - arg_desc = 'base="%s", scope=%s, filterstr="%s"' % (base, scope, filterstr) - raise errors.NotFound(reason=arg_desc) - - entries = [] - for s in obj: - entries.append(s) + def getEntry(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[0] - return entries + 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): - """This wraps the add function. It assumes that the entry is already - populated with all of the desired objectclasses and attributes""" - - if not isinstance(entry, Entry): - raise TypeError('addEntry expected an Entry object, got %s instead' % entry.__class__) - - try: - self.add_s(entry.dn, entry.toTupleList()) - except ldap.LDAPError, e: - arg_desc = 'entry=%s: %s' % (entry.dn, entry.toTupleList()) - self.__handle_errors(e, arg_desc=arg_desc) + # FIXME: for backwards compatibility only + self.add_entry(entry.dn, entry) return True def updateEntry(self,dn,oldentry,newentry): + # FIXME: for backwards compatibility only """This wraps the mod function. It assumes that the entry is already populated with all of the desired objectclasses and attributes""" @@ -1722,6 +1696,7 @@ class IPAdmin(LDAPConnection): return True def generateModList(self, old_entry, new_entry): + # FIXME: for backwards compatibility only """A mod list generator that computes more precise modification lists than the python-ldap version. For single-value attributes always use a REPLACE operation, otherwise use ADD/DEL. @@ -1802,15 +1777,8 @@ class IPAdmin(LDAPConnection): return True def deleteEntry(self, dn): - """This wraps the delete function. Use with caution.""" - - assert isinstance(dn, DN) - - try: - self.delete_s(dn) - except ldap.LDAPError, e: - arg_desc = 'dn=%s' % (dn) - self.__handle_errors(e, arg_desc=arg_desc) + # FIXME: for backwards compatibility only + self.delete_entry(dn) return True def waitForEntry(self, dn, timeout=7200, attr='', quiet=True): |