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

PR body:
"""
Added more information to the NotFound error that may occur during
execution of vault-show. 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
"""

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 cbf9d4313b17d44ea2302bef249a3bb0a217c581 Mon Sep 17 00:00:00 2001
From: Stanislav Laznicka <slazn...@redhat.com>
Date: Wed, 21 Sep 2016 13:41:45 +0200
Subject: [PATCH] Improved vault-show error message

Added more information to the NotFound error that may occur during
execution of vault-show. 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 | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/ipaserver/plugins/vault.py b/ipaserver/plugins/vault.py
index 5c4c096..3d0eb2f 100644
--- a/ipaserver/plugins/vault.py
+++ b/ipaserver/plugins/vault.py
@@ -947,6 +947,27 @@ def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
 
         return dn
 
+    def execute(self, *keys, **options):
+        try:
+            return super(vault_show, self).execute(*keys, **options)
+        except errors.NotFound as e:
+            self.log.debug(str(e))
+            container_dn = self.obj.get_dn(*keys, **options)[1]['cn']
+            if options.get('service'):
+                container_type = 'service'
+            else:
+                container_type = 'shared' if options.get('shared') else 'user'
+            if container_type in ('user', 'service'):
+                err_str = _("Couldn't find '%(cn)s' in %(type)s container "
+                            "'%(cont)s'."
+                            ) % {'cn': keys[0], 'type': container_type,
+                                 'cont': container_dn}
+            else:
+                err_str = _("Couldn't find '%(cn)s' in %(type)s container."
+                            ) % {'cn': keys[0], 'type': container_type}
+
+            raise errors.NotFound(reason=err_str)
+
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
         self.obj.get_container_attribute(entry_attrs, options)
         return dn
-- 
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