def test_ctx_from_headers(self): self.context = self.patch(context, 'BlazarContext') catalog = jsonutils.dump_as_bytes({'nova': 'catalog'}) self.fake_headers[u'X-Service-Catalog'] = catalog api_context.ctx_from_headers(self.fake_headers) self.context.assert_called_once_with(user_id=u'1', roles=[u'user_name0', u'user_name1'], project_name=u'project_name', auth_token=u'111-111-111', service_catalog={ u'nova': u'catalog'}, project_id=u'1', user_name=u'user_name')
def test_ctx_from_headers(self): self.fake_headers['X-Service-Catalog'] = self.catalog req = webob.Request.blank('/v2/leases') req.headers = self.fake_headers api_context.ctx_from_headers(req.headers) self.context.assert_called_once_with( user_id=uuidsentinel.user_id, roles=['user_name0', 'user_name1'], project_name='project_name', auth_token='111-111-111', service_catalog={'nova': 'catalog'}, project_id=uuidsentinel.project_id, user_name='user_name')
def test_ctx_from_headers(self): self.fake_headers['X-Service-Catalog'] = self.catalog environ_base = { 'openstack.request_id': 'req-' + uuidsentinel.reqid, 'openstack.global_request_id': 'req-' + uuidsentinel.globalreqid } req = wrappers.Request.from_values('/v1/leases', headers=self.fake_headers, environ_base=environ_base) api_context.ctx_from_headers(req.headers) self.context.assert_called_once_with( user_id=uuidsentinel.user_id, roles=['user_name0', 'user_name1'], project_name='project_name', auth_token='111-111-111', service_catalog={'nova': 'catalog'}, project_id=uuidsentinel.project_id, user_name='user_name', request_id='req-' + uuidsentinel.reqid, global_request_id='req-' + uuidsentinel.globalreqid)
def handler(**kwargs): LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs) _init_resp_type(file_upload) # update status code if status: flask.request.status_code = status if flask.request.method in ['POST', 'PUT']: kwargs['data'] = request_data() if flask.request.endpoint in self.routes_with_query_support: params = {k: v for k, v in get_request_args().items()} kwargs['query'] = params with context.ctx_from_headers(flask.request.headers): try: return func(flask.request, **kwargs) except ex.BlazarException as e: return bad_request(e) except messaging.RemoteError as e: # Get the exception from enforcement, manager and # common exceptions cls = getattr(enforcement_exceptions, e.exc_type, getattr(ex, e.exc_type, None)) cls = cls or getattr(manager_exceptions, e.exc_type, getattr(ex, e.exc_type, None)) cls = cls or getattr(opst_exceptions, e.exc_type, getattr(ex, e.exc_type, None)) if cls is not None: return render_error_message( cls.code, e.value, cls.code) else: # Get the exception from db exceptions and hide # the message because could contain table/column # information cls = getattr(db_exceptions, e.exc_type, None) if cls is not None: return render_error_message( cls.code, '{0}: A database error occurred'.format( cls.__name__), cls.code) else: # We obfuscate all Exceptions # but Blazar ones for # security reasons err = 'Internal Server Error' return internal_error(500, err, e) except Exception as e: return internal_error(500, 'Internal Server Error', e)
def before(self, state): state.request.context = context.ctx_from_headers(state.request.headers) state.request.context.__enter__()