mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 08:00:02 -06:00
Add a reason to the NotFound exception so we can provide more robust errors
This commit is contained in:
parent
de88954b91
commit
1c31b5bc08
@ -739,7 +739,7 @@ class NotFound(ExecutionError):
|
||||
"""
|
||||
|
||||
errno = 4001
|
||||
format = _('entry not found')
|
||||
format = _('%(reason)r')
|
||||
|
||||
class DuplicateEntry(ExecutionError):
|
||||
"""
|
||||
|
@ -81,7 +81,7 @@ def search_by_name(acis, aciname):
|
||||
# FIXME: need to log syntax errors, ignore for now
|
||||
pass
|
||||
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="Unable to find aci %s" % aciname)
|
||||
|
||||
def search_by_attr(acis, attrlist):
|
||||
"""
|
||||
@ -105,7 +105,7 @@ def search_by_attr(acis, attrlist):
|
||||
if results:
|
||||
return results
|
||||
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="Unable to find any ACIs with attribute %s" % ",".join(attrlist))
|
||||
|
||||
def search_by_taskgroup(acis, tgdn):
|
||||
"""
|
||||
@ -126,7 +126,7 @@ def search_by_taskgroup(acis, tgdn):
|
||||
if results:
|
||||
return results
|
||||
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="taskgroup %s not found" % tgdn)
|
||||
|
||||
def search_by_perm(acis, permlist):
|
||||
"""
|
||||
@ -148,7 +148,7 @@ def search_by_perm(acis, permlist):
|
||||
if results:
|
||||
return results
|
||||
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="No ACIs with permissions %s found" % ",".join(permlist))
|
||||
|
||||
def search_by_memberof(acis, memberoffilter):
|
||||
"""
|
||||
@ -174,7 +174,7 @@ def search_by_memberof(acis, memberoffilter):
|
||||
if results:
|
||||
return results
|
||||
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="Nothing found for %s" % memberoffilter)
|
||||
|
||||
class aci(Object):
|
||||
"""
|
||||
|
@ -291,7 +291,7 @@ class automount_delkey(crud.Del):
|
||||
keydn = k.get('dn')
|
||||
break
|
||||
if not keydn:
|
||||
raise errors.NotFound(msg='Entry not found')
|
||||
raise errors.NotFound(reason='Removing keys failed. key %s not found' % keyname)
|
||||
return ldap.delete(keydn)
|
||||
def output_for_cli(self, textui, result, *args, **options):
|
||||
"""
|
||||
@ -369,7 +369,7 @@ class automount_modkey(crud.Mod):
|
||||
keydn = k.get('dn')
|
||||
break
|
||||
if not keydn:
|
||||
raise errors.NotFound(msg='Entry not found')
|
||||
raise errors.NotFound(reason='Update failed, unable to find key %s' % keyname)
|
||||
return ldap.update(keydn, **kw)
|
||||
|
||||
def output_for_cli(self, textui, result, *args, **options):
|
||||
@ -517,7 +517,7 @@ class automount_showkey(crud.Get):
|
||||
keydn = k.get('dn')
|
||||
break
|
||||
if not keydn:
|
||||
raise errors.NotFound(msg='Entry not found')
|
||||
raise errors.NotFound(reason='Unable to find key %s' % keyname)
|
||||
# FIXME: should kw contain the list of attributes to display?
|
||||
if kw.get('all', False):
|
||||
return ldap.retrieve(keydn)
|
||||
|
@ -597,7 +597,7 @@ class dns2_del_rr(Command):
|
||||
try:
|
||||
attr_value.remove(data)
|
||||
except ValueError:
|
||||
raise errors.NotFound(message=u'resource record not found')
|
||||
raise errors.NotFound(reason=u'resource record not found')
|
||||
|
||||
# check if it's worth to keep this entry in LDAP
|
||||
if 'idnsZone' not in entry_attrs['objectclass']:
|
||||
|
@ -160,7 +160,7 @@ class user_add(crud.Create):
|
||||
kw['gidnumber'] = default_group.get('gidnumber')
|
||||
except errors.NotFound:
|
||||
# Fake an LDAP error so we can return something useful to the kw
|
||||
raise errors.NotFound("The default group for new users, '%s', cannot be found." % config.get('ipadefaultprimarygroup'))
|
||||
raise errors.NotFound(reason="The default group for new users, '%s', cannot be found." % config.get('ipadefaultprimarygroup'))
|
||||
except Exception, e:
|
||||
# catch everything else
|
||||
raise e
|
||||
|
@ -148,7 +148,7 @@ class user2_create(crud.Create):
|
||||
(group_dn, group_attrs) = ldap.get_entry(group_dn, ['gidNumber'])
|
||||
except errors.NotFound:
|
||||
error_msg = 'Default group for new users not found.'
|
||||
raise errors.NotFound(error_msg)
|
||||
raise errors.NotFound(reason=error_msg)
|
||||
# fill default group's gidNumber
|
||||
entry_attrs['gidnumber'] = group_attrs['gidNumber']
|
||||
|
||||
|
@ -298,7 +298,7 @@ class IPAdmin(SimpleLDAPObject):
|
||||
raise e
|
||||
except ldap.NO_SUCH_OBJECT, e:
|
||||
args = kw.get('args', '')
|
||||
raise errors.NotFound(msg=notfound(args))
|
||||
raise errors.NotFound(reason=notfound(args))
|
||||
except ldap.ALREADY_EXISTS, e:
|
||||
raise errors.DuplicateEntry()
|
||||
except ldap.CONSTRAINT_VIOLATION, e:
|
||||
@ -361,7 +361,7 @@ class IPAdmin(SimpleLDAPObject):
|
||||
self.__handle_errors(e, **kw)
|
||||
|
||||
if not obj:
|
||||
raise errors.NotFound(msg=notfound(args))
|
||||
raise errors.NotFound(reason=notfound(args))
|
||||
|
||||
elif isinstance(obj,Entry):
|
||||
return obj
|
||||
@ -383,7 +383,7 @@ class IPAdmin(SimpleLDAPObject):
|
||||
self.__handle_errors(e, **kw)
|
||||
|
||||
if not obj:
|
||||
raise errors.NotFound(msg=notfound(args))
|
||||
raise errors.NotFound(reason=notfound(args))
|
||||
|
||||
entries = []
|
||||
for s in obj:
|
||||
@ -421,7 +421,7 @@ class IPAdmin(SimpleLDAPObject):
|
||||
self.__handle_errors(e, **kw)
|
||||
|
||||
if not entries:
|
||||
raise errors.NotFound(msg=notfound(args))
|
||||
raise errors.NotFound(reason=notfound(args))
|
||||
|
||||
if partial == 1:
|
||||
counter = -1
|
||||
|
@ -270,7 +270,7 @@ def search(base, filter, attributes, timelimit=1, sizelimit=3000, scope=ldap.SCO
|
||||
results = context.ldap.conn.getListAsync(base, scope,
|
||||
filter, attributes, 0, None, None, timelimit, sizelimit)
|
||||
except ldap.NO_SUCH_OBJECT:
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason=filter)
|
||||
|
||||
counter = results[0]
|
||||
entries = [counter]
|
||||
@ -315,9 +315,9 @@ def get_ipa_config():
|
||||
searchfilter = "cn=ipaconfig"
|
||||
try:
|
||||
config = get_sub_entry("cn=etc," + api.env.basedn, searchfilter)
|
||||
except ldap.NO_SUCH_OBJECT, e:
|
||||
except ldap.NO_SUCH_OBJECT:
|
||||
# FIXME
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="IPA configuration cannot be loaded")
|
||||
|
||||
return config
|
||||
|
||||
@ -409,12 +409,12 @@ def add_member_to_group(member_dn, group_dn, memberattr='member'):
|
||||
|
||||
group = get_entry_by_dn(group_dn, None)
|
||||
if group is None:
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="cannot find group %s" % group_dn)
|
||||
|
||||
# check to make sure member_dn exists
|
||||
member_entry = get_base_entry(member_dn, "(objectClass=*)", ['dn','objectclass'])
|
||||
if not member_entry:
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="cannot find member %s" % member_dn)
|
||||
|
||||
# Add the new member to the group member attribute
|
||||
members = group.get(memberattr, [])
|
||||
@ -430,7 +430,7 @@ def remove_member_from_group(member_dn, group_dn, memberattr='member'):
|
||||
|
||||
group = get_entry_by_dn(group_dn, None)
|
||||
if group is None:
|
||||
raise errors.NotFound()
|
||||
raise errors.NotFound(reason="cannot find group %s" % group_dn)
|
||||
"""
|
||||
if group.get('cn') == "admins":
|
||||
member = get_entry_by_dn(member_dn, ['dn','uid'])
|
||||
|
Loading…
Reference in New Issue
Block a user