from .. import logger
from ..services.ceph_service import CephService
from ..services.rgw_client import RgwClient
+from ..rest_client import RequestException
@ApiController('rgw')
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.
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)}
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))
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