Skip to content

Commit

Permalink
mgr/dashboard: Be more selective when catching exceptions.
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
votdev committed Apr 27, 2018
1 parent e1d344b commit 87ff98c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/pybind/mgr/dashboard/controllers/rgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .. import logger
from ..services.ceph_service import CephService
from ..services.rgw_client import RgwClient
from ..rest_client import RequestException


@ApiController('rgw')
Expand Down Expand Up @@ -79,7 +80,7 @@ def __call__(self, path, **params):
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.
Expand All @@ -93,5 +94,10 @@ def __call__(self, path, **params):
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)}
10 changes: 5 additions & 5 deletions src/pybind/mgr/dashboard/services/rgw_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def instance(userid):
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))

Expand Down Expand Up @@ -188,11 +188,11 @@ def _admin_get_user_keys(self, admin_path, userid, request=None):
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

Expand Down

0 comments on commit 87ff98c

Please sign in to comment.