Improve the error message when an entry is not found.

We used to return the entire argument string ala:

('dc=freeipa,dc=org', 2, 'uid=foo', ['*'])

This adds a regex to try to print anything after = in the filter.
Not perfect but better.
This commit is contained in:
Rob Crittenden 2007-12-06 16:48:26 -05:00
parent 2a2d866552
commit 04cccd4426

View File

@ -356,13 +356,13 @@ class IPAdmin(SimpleLDAPObject):
type, obj = self.result(res) type, obj = self.result(res)
except ldap.NO_SUCH_OBJECT: except ldap.NO_SUCH_OBJECT:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND, raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
"no such entry for " + str(args)) notfound(args))
except ldap.LDAPError, e: except ldap.LDAPError, e:
raise ipaerror.gen_exception(ipaerror.LDAP_DATABASE_ERROR, None, e) raise ipaerror.gen_exception(ipaerror.LDAP_DATABASE_ERROR, None, e)
if not obj: if not obj:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND, raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
"no such entry for " + str(args)) notfound(args))
elif isinstance(obj,Entry): elif isinstance(obj,Entry):
return obj return obj
else: # assume list/tuple else: # assume list/tuple
@ -386,7 +386,7 @@ class IPAdmin(SimpleLDAPObject):
if not obj: if not obj:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND, raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
"no such entry for " + str(args)) notfound(args))
all_users = [] all_users = []
for s in obj: for s in obj:
@ -424,7 +424,7 @@ class IPAdmin(SimpleLDAPObject):
if not entries: if not entries:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND, raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
"no such entry for " + str(args)) notfound(args))
if partial == 1: if partial == 1:
counter = -1 counter = -1
@ -717,3 +717,16 @@ class IPAdmin(SimpleLDAPObject):
"""Returns True if the given string is a DN, False otherwise.""" """Returns True if the given string is a DN, False otherwise."""
return (dn.find("=") > 0) return (dn.find("=") > 0)
is_a_dn = staticmethod(is_a_dn) is_a_dn = staticmethod(is_a_dn)
def notfound(args):
"""Return a string suitable for displaying as an error when a
search returns no results.
This just returns whatever is after the equals sign"""
filter = args[2]
try:
target = re.match(r'\(.*=(.*)\)', filter).group(1)
except:
target = filter
return "%s not found" % str(target)