URL: https://github.com/freeipa/freeipa/pull/101
Author: stlaz
 Title: #101: Improved vault-show error message
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/101/head:pr101
git checkout pr101
From fd39db9f8263ffbfd41791fffaf4514d9ce01953 Mon Sep 17 00:00:00 2001
From: Stanislav Laznicka <slazn...@redhat.com>
Date: Fri, 25 Nov 2016 15:46:29 +0100
Subject: [PATCH 1/2] Added kwargs to handle_not_found method

Adding kwargs allows invocation options to be passed to
handle_not_found() to improve 'Not found' messages.

https://fedorahosted.org/freeipa/ticket/5950
---
 ipaserver/plugins/automount.py |  2 +-
 ipaserver/plugins/baseldap.py  | 23 ++++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/ipaserver/plugins/automount.py b/ipaserver/plugins/automount.py
index c4cf2d6..a5be853 100644
--- a/ipaserver/plugins/automount.py
+++ b/ipaserver/plugins/automount.py
@@ -568,7 +568,7 @@ def get_dn(self, *keys, **kwargs):
 
         return dn
 
-    def handle_not_found(self, *keys):
+    def handle_not_found(self, *keys, **kwargs):
         pkey = keys[-1]
         key = pkey.split(self.rdn_separator)[0]
         info = self.rdn_separator.join(pkey.split(self.rdn_separator)[1:])
diff --git a/ipaserver/plugins/baseldap.py b/ipaserver/plugins/baseldap.py
index 5770641..66b555e 100644
--- a/ipaserver/plugins/baseldap.py
+++ b/ipaserver/plugins/baseldap.py
@@ -750,7 +750,7 @@ def get_password_attributes(self, ldap, dn, entry_attrs):
             except errors.NotFound:
                 entry_attrs[attr] = False
 
-    def handle_not_found(self, *keys):
+    def handle_not_found(self, *keys, **kwargs):
         pkey = ''
         if self.primary_key:
             pkey = keys[-1]
@@ -1013,7 +1013,7 @@ def process_attr_options(self, entry_attrs, dn, keys, options):
                     dn, needldapattrs
                 )
             except errors.NotFound:
-                self.obj.handle_not_found(*keys)
+                self.obj.handle_not_found(*keys, **options)
 
             # Provide a nice error message when user tries to delete an
             # attribute that does not exist on the entry (and user is not
@@ -1218,7 +1218,7 @@ def execute(self, *keys, **options):
                 entry_attrs = self._exc_wrapper(keys, options, ldap.get_entry)(
                     entry_attrs.dn, attrs_list)
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         self.obj.get_indirect_members(entry_attrs, attrs_list)
 
@@ -1318,7 +1318,7 @@ def execute(self, *keys, **options):
                 dn, attrs_list
             )
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         self.obj.get_indirect_members(entry_attrs, attrs_list)
 
@@ -1459,7 +1459,7 @@ def execute(self, *keys, **options):
             if not rdnupdate:
                 raise e
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         try:
             entry_attrs = self._exc_wrapper(keys, options, ldap.get_entry)(
@@ -1540,12 +1540,12 @@ def delete_subtree(base_dn):
                 try:
                     self._exc_wrapper(nkeys, options, ldap.delete_entry)(base_dn)
                 except errors.NotFound:
-                    self.obj.handle_not_found(*nkeys)
+                    self.obj.handle_not_found(*nkeys, **options)
 
             try:
                 self._exc_wrapper(nkeys, options, ldap.delete_entry)(dn)
             except errors.NotFound:
-                self.obj.handle_not_found(*nkeys)
+                self.obj.handle_not_found(*nkeys, **options)
             except errors.NotAllowedOnNonLeaf:
                 if not self.subtree_delete:
                     raise
@@ -1702,7 +1702,7 @@ def execute(self, *keys, **options):
                 dn, attrs_list
             )
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         self.obj.get_indirect_members(entry_attrs, attrs_list)
 
@@ -1803,7 +1803,7 @@ def execute(self, *keys, **options):
                 dn, attrs_list
             )
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         self.obj.get_indirect_members(entry_attrs, attrs_list)
 
@@ -2022,7 +2022,8 @@ def execute(self, *args, **options):
         except errors.EmptyResult:
             (entries, truncated) = ([], False)
         except errors.NotFound:
-            self.api.Object[self.obj.parent_object].handle_not_found(*keys)
+            self.api.Object[self.obj.parent_object].handle_not_found(
+                *keys, **options)
 
         for callback in self.get_callbacks('post'):
             truncated = callback(self, ldap, entries, truncated, *args, **options)
@@ -2337,7 +2338,7 @@ def execute(self, *keys, **options):
 
             self._exc_wrapper(keys, options, ldap.update_entry)(update)
         except errors.NotFound:
-            self.obj.handle_not_found(*keys)
+            self.obj.handle_not_found(*keys, **options)
 
         try:
             entry_attrs = self._exc_wrapper(keys, options, ldap.get_entry)(

From edb940170c8433608af73bccc1f3b137f0acc35c Mon Sep 17 00:00:00 2001
From: Stanislav Laznicka <slazn...@redhat.com>
Date: Wed, 21 Sep 2016 13:41:45 +0200
Subject: [PATCH 2/2] Improved vault error messages

Added more information to the NotFound error that may occur during
execution of vault commands. It was not clear whether the vault
really does not exist or it does not exist in a certain container.

https://fedorahosted.org/freeipa/ticket/5950
---
 ipaserver/plugins/vault.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/ipaserver/plugins/vault.py b/ipaserver/plugins/vault.py
index 5c4c096..820ed66 100644
--- a/ipaserver/plugins/vault.py
+++ b/ipaserver/plugins/vault.py
@@ -755,6 +755,28 @@ def get_container_attribute(self, entry, options):
         elif entry.dn.endswith(DN(('cn', 'users'), container_dn)):
             entry['username'] = entry.dn[1]['cn']
 
+    def handle_not_found(self, *keys, **kwargs):
+        container_dn = self.get_dn(*keys, **kwargs)
+        parent_container = container_dn[1]['cn']
+        if parent_container != 'shared':
+            # get the container type and strip the ending 's'
+            container_type = container_dn[2]['cn'][:-1]
+        else:
+            container_type = 'shared'
+
+        self.object_not_found_msg = _('%(pkey)s: %(oname)s not found')
+        if container_type in ('service, user'):
+            self.object_not_found_msg = (
+                self.object_not_found_msg +
+                (" in %(cn)s %(cont_type)s vault container")
+                % {'cn': parent_container, 'cont_type': container_type}
+            )
+        else:
+            self.object_not_found_msg = (
+                self.object_not_found_msg + (" in shared vault container.")
+            )
+        super(vault, self).handle_not_found(*keys, **kwargs)
+
 
 @register()
 class vault_add_internal(LDAPCreate):
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to