def test_ctx_from_headers(self): 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'], tenant_name=u'tenant_name', auth_token=u'111-111-111', service_catalog=u'catalog', tenant_id=u'1', user_name=u'user_name')
def test_ctx_from_headers(self): self.context = self.patch(context, 'ClimateContext') catalog = json.dumps({'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.context = self.patch(context, 'ClimateContext') catalog = json.dumps({'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 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() with context.ctx_from_headers(flask.request.headers): try: return func(**kwargs) except ex.ClimateException as e: return bad_request(e) except rpc_common.RemoteError as e: try: # NOTE(sbauza): All Manager Exceptions should be # defined in climate.manager.exceptions cls = getattr(manager_exceptions, e.exc_type) except AttributeError: # We obfuscate all Exceptions but Climate ones for # security reasons return internal_error(500, 'Internal Server Error', e) return render_error_message(cls.code, e.value, cls.code) except Exception as e: return internal_error(500, 'Internal Server Error', e)
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() with context.ctx_from_headers(flask.request.headers): try: return func(**kwargs) except ex.ClimateException as e: return bad_request(e) except messaging.RemoteError as e: # Get the exception from manager and common exceptions cls = getattr(manager_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 Climate 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 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() with context.ctx_from_headers(flask.request.headers): try: return func(**kwargs) except ex.ClimateException as e: return bad_request(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__()
def test_ctx_from_headers_with_admin(self): self.patch(policy, 'enforce').return_value = True ctx = api_context.ctx_from_headers(self.fake_headers) self.assertEqual(True, ctx.is_admin)