User plugin: improve error related to non existing idp

The user and stageuser commands return the following error
when the user is created/updated with a non existing idp:
$ ipa user-add testuser --first test --last user --idp dummy
ipa: ERROR: no such entry

The error is not descriptive enough and has been modified to
display instead:
$ ipa user-add testuser --first test --last user --idp dummy
ipa: ERROR: External IdP configuration dummy not found

Fixes: https://pagure.io/freeipa/issue/9416

Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Florence Blanc-Renaud 2023-07-19 13:24:55 +02:00 committed by Rob Crittenden
parent d2ed490ff4
commit f57a7dbf50
3 changed files with 15 additions and 3 deletions

View File

@ -755,7 +755,11 @@ class baseuser_mod(LDAPUpdate):
if 'ipaidpuser' not in obj_classes:
entry_attrs['objectclass'].append('ipaidpuser')
answer = self.api.Object['idp'].get_dn_if_exists(cl)
try:
answer = self.api.Object['idp'].get_dn_if_exists(cl)
except errors.NotFound:
reason = "External IdP configuration {} not found"
raise errors.NotFound(reason=_(reason).format(cl))
entry_attrs['ipaidpconfiglink'] = answer
# Note: we could have used the method add_missing_object_class

View File

@ -406,7 +406,11 @@ class stageuser_add(baseuser_add):
if 'ipaidpuser' not in entry_attrs['objectclass']:
entry_attrs['objectclass'].append('ipaidpuser')
answer = self.api.Object['idp'].get_dn_if_exists(cl)
try:
answer = self.api.Object['idp'].get_dn_if_exists(cl)
except errors.NotFound:
reason = "External IdP configuration {} not found"
raise errors.NotFound(reason=_(reason).format(cl))
entry_attrs['ipaidpconfiglink'] = answer
self.pre_common_callback(ldap, dn, entry_attrs, attrs_list, *keys,

View File

@ -649,7 +649,11 @@ class user_add(baseuser_add):
if 'ipaidpuser' not in entry_attrs['objectclass']:
entry_attrs['objectclass'].append('ipaidpuser')
answer = self.api.Object['idp'].get_dn_if_exists(rcl)
try:
answer = self.api.Object['idp'].get_dn_if_exists(rcl)
except errors.NotFound:
reason = "External IdP configuration {} not found"
raise errors.NotFound(reason=_(reason).format(rcl))
entry_attrs['ipaidpconfiglink'] = answer
self.pre_common_callback(ldap, dn, entry_attrs, attrs_list, *keys,