示例#1
0
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug("Rest.route.decorator.handler, kwargs={kwargs}"
                          .format(kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                kwargs.pop("tenant_id")
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','))
                context.set_ctx(ctx)

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
示例#2
0
 def test_is_auth_capable_for_user_ctx(self):
     existing_ctx = context.ctx()
     try:
         ctx = context.Context('test_user', 'tenant_1', 'test_auth_token',
                               {"network": "aURL"}, remote_semaphore='123')
         self.assertTrue(ctx.is_auth_capable())
     finally:
         context.set_ctx(existing_ctx)
示例#3
0
 def setUp(self):
     super(ContextTest, self).setUp()
     self.useFixture(fixtures.FakeLogger('sahara'))
     ctx = context.Context('test_user',
                           'tenant_1',
                           'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
示例#4
0
文件: base.py 项目: xinw1012/sahara
    def setup_context(self, username="******", tenant_id="tenant_1",
                      auth_token="test_auth_token", tenant_name='test_tenant',
                      service_catalog=None, **kwargs):
        self.addCleanup(context.set_ctx,
                        context.ctx() if context.has_ctx() else None)

        context.set_ctx(context.Context(
            username=username, tenant_id=tenant_id,
            auth_token=auth_token, service_catalog=service_catalog or {},
            tenant_name=tenant_name, **kwargs))
示例#5
0
文件: api.py 项目: yonglehou/sahara
            def handler(**kwargs):
                context.set_ctx(None)

                LOG.debug(
                    "Rest.route.decorator.handler, kwargs={kwargs}".format(
                        kwargs=kwargs))

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                req_id = flask.request.environ.get(oslo_req_id.ENV_REQUEST_ID)
                auth_plugin = flask.request.environ.get('keystone.token_auth')
                ctx = context.Context(
                    flask.request.headers['X-User-Id'],
                    flask.request.headers['X-Tenant-Id'],
                    flask.request.headers['X-Auth-Token'],
                    flask.request.headers['X-Service-Catalog'],
                    flask.request.headers['X-User-Name'],
                    flask.request.headers['X-Tenant-Name'],
                    flask.request.headers['X-Roles'].split(','),
                    auth_plugin=auth_plugin,
                    request_id=req_id)
                context.set_ctx(ctx)
                if flask.request.method in ['POST', 'PUT', 'PATCH']:
                    kwargs['data'] = request_data()

                try:
                    return func(**kwargs)
                except ex.Forbidden as e:
                    return access_denied(e)
                except ex.SaharaException as e:
                    return bad_request(e)
                except Exception as e:
                    return internal_error(500, 'Internal Server Error', e)
示例#6
0
 def wrapped(self, ctx, *args, **kwargs):
     context.set_ctx(context.Context(**ctx))
     return func(self, *args, **kwargs)
示例#7
0
 def setUp(self):
     super(TopologyTestCase, self).setUp()
     context.set_ctx(context.Context(None, None, None, None))
示例#8
0
 def run_method(ctx, **kwargs):
     context.set_ctx(context.Context(**ctx))
     try:
         return method(**kwargs)
     finally:
         context.set_ctx(None)
示例#9
0
 def setUp(self):
     ctx = context.Context('test_user',
                           'tenant_1',
                           'test_auth_token', {},
                           remote_semaphore='123')
     context.set_ctx(ctx)
示例#10
0
 def setUp(self):
     context.set_ctx(context.Context(None, None, None, None))