]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Be more selective when catching exceptions. 21351/head
authorVolker Theile <vtheile@suse.com>
Fri, 27 Apr 2018 11:39:07 +0000 (13:39 +0200)
committerVolker Theile <vtheile@suse.com>
Fri, 27 Apr 2018 13:59:57 +0000 (15:59 +0200)
- Do some minor improvements in the RGW client
- Do not catch ALL exceptions to do not block the current exception handler that prints the stack trace in the log file
- Throw RequestException istead of Exception when user does not have the required keys

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/controllers/rgw.py
src/pybind/mgr/dashboard/services/rgw_client.py

index 05420473980ae04f0197f1f79e9f6ebfa00c2da4..249df76addf71b234f060434e14589d2f4a42e1c 100644 (file)
@@ -8,6 +8,7 @@ from . import ApiController, BaseController, RESTController, AuthRequired
 from .. import logger
 from ..services.ceph_service import CephService
 from ..services.rgw_client import RgwClient
+from ..rest_client import RequestException
 
 
 @ApiController('rgw')
@@ -79,7 +80,7 @@ class RgwProxy(BaseController):
                 data = cherrypy.request.body.read()
 
             return rgw_client.proxy(method, path, params, data)
-        except Exception as e:  # pylint: disable=broad-except
+        except RequestException as e:
             # Always use status code 500 and NOT the status that may delivered
             # by the exception. That's because we do not want to forward e.g.
             # 401 or 404 that may trigger unwanted actions in the UI.
@@ -93,5 +94,10 @@ class RgwProxy(BaseController):
 class RgwBucket(RESTController):
 
     def create(self, bucket, uid):
-        rgw_client = RgwClient.instance(uid)
-        return rgw_client.create_bucket(bucket)
+        try:
+            rgw_client = RgwClient.instance(uid)
+            return rgw_client.create_bucket(bucket)
+        except RequestException as e:
+            cherrypy.response.headers['Content-Type'] = 'application/json'
+            cherrypy.response.status = 500
+            return {'detail': str(e)}
index 0089e9f006f673bf5252a39ef9213f51233d3b6b..e34fb75edce800d6386b2179993add260573361d 100644 (file)
@@ -118,7 +118,7 @@ class RgwClient(RestClient):
             logger.info("Creating new connection for user: %s", userid)
             keys = RgwClient.admin_instance().get_user_keys(userid)
             if not keys:
-                raise Exception(
+                raise RequestException(
                     "User '{}' does not have any keys configured.".format(
                         userid))
 
@@ -188,11 +188,11 @@ class RgwClient(RestClient):
         colon_idx = userid.find(':')
         user = userid if colon_idx == -1 else userid[:colon_idx]
         response = request({'uid': user})
-        for keys in response['keys']:
-            if keys['user'] == userid:
+        for key in response['keys']:
+            if key['user'] == userid:
                 return {
-                    'access_key': keys['access_key'],
-                    'secret_key': keys['secret_key']
+                    'access_key': key['access_key'],
+                    'secret_key': key['secret_key']
                 }
         return None