예제 #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))