当前位置: 首页>>代码示例>>Python>>正文


Python request_id.ENV_REQUEST_ID属性代码示例

本文整理汇总了Python中oslo_middleware.request_id.ENV_REQUEST_ID属性的典型用法代码示例。如果您正苦于以下问题:Python request_id.ENV_REQUEST_ID属性的具体用法?Python request_id.ENV_REQUEST_ID怎么用?Python request_id.ENV_REQUEST_ID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在oslo_middleware.request_id的用法示例。


在下文中一共展示了request_id.ENV_REQUEST_ID属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: before

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def before(self, state):
        headers = state.request.headers
        user_name = headers.get('X-User-Name')
        user_id = headers.get('X-User-Id')
        project = headers.get('X-Project-Name')
        project_id = headers.get('X-Project-Id')
        domain_id = headers.get('X-User-Domain-Id')
        domain_name = headers.get('X-User-Domain-Name')
        auth_token = headers.get('X-Auth-Token')
        roles = headers.get('X-Roles', '').split(',')
        auth_token_info = state.request.environ.get('keystone.token_info')
        req_id = state.request.environ.get(request_id.ENV_REQUEST_ID)

        state.request.context = context.make_context(
            auth_token=auth_token,
            auth_token_info=auth_token_info,
            request_id=req_id,
            user_name=user_name,
            user_id=user_id,
            project_name=project,
            project_id=project_id,
            domain_id=domain_id,
            domain_name=domain_name,
            roles=roles) 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:hooks.py

示例2: test_compat_headers

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def test_compat_headers(self):
        """Test that compat headers are set

        Compat headers might exist on a super class to support
        previous API contracts. This ensures that you can set that to
        a list of headers and those values are the same as the
        request_id.

        """
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.ENV_REQUEST_ID]

        app = AltHeader(application)
        req = webob.Request.blank('/test')
        res = req.get_response(app)

        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)

        self.assertEqual(res.headers.get("x-compute-req-id"), res_req_id)
        self.assertEqual(res.headers.get("x-silly-id"), res_req_id) 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:23,代码来源:test_request_id.py

示例3: test_context_middleware_with_requestid

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def test_context_middleware_with_requestid(self):
        avr = vr.APIVersionRequest('1.0')
        middleware = context.ContextMiddleware(None)
        request = webob.Request.blank('/clusters', headers=self.headers,
                                      environ=self.environ)
        req_id = 'req-5a63f0d7-1b69-447b-b621-4ea87cc7186d'
        request.environ[request_id.ENV_REQUEST_ID] = req_id
        request.version_request = avr
        if self.expected_exception:
            self.assertRaises(
                self.expected_exception, middleware.process_request, request)
        else:
            self.assertIsNone(middleware.process_request(request))
            ctx = request.context.to_dict()
            for k, v in self.context_dict.items():
                self.assertEqual(v, ctx[k], 'Key %s values do not match' % k)
            self.assertEqual(
                ctx.get('request_id'), req_id,
                'Key request_id values do not match') 
开发者ID:openstack,项目名称:senlin,代码行数:21,代码来源:test_context.py

示例4: make_context

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def make_context(self, request, *args, **kwargs):
        req_id = request.environ.get(request_id.ENV_REQUEST_ID)
        kwargs.setdefault('request_id', req_id)

        ctxt = context.DesignateContext(*args, **kwargs)

        try:
            self._extract_sudo(ctxt, request)
            self._extract_all_projects(ctxt, request)
            self._extract_edit_managed_records(ctxt, request)
            self._extract_dns_hide_counts(ctxt, request)
            self._extract_client_addr(ctxt, request)
        finally:
            request.environ['context'] = ctxt
        return ctxt 
开发者ID:openstack,项目名称:designate,代码行数:17,代码来源:middleware.py

示例5: __call__

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def __call__(self, req):
        user_id = req.headers.get('X_USER', 'admin')
        user_id = req.headers.get('X_USER_ID', user_id)

        project_name = req.headers.get('X_TENANT_NAME')
        user_name = req.headers.get('X_USER_NAME')

        req_id = req.environ.get(request_id.ENV_REQUEST_ID)

        remote_address = req.remote_addr
        if CONF.use_forwarded_for:
            remote_address = req.headers.get('X-Forwarded-For', remote_address)

        service_catalog = None
        if req.headers.get('X_SERVICE_CATALOG') is not None:
            try:
                catalog_header = req.headers.get('X_SERVICE_CATALOG')
                service_catalog = jsonutils.loads(catalog_header)
            except ValueError:
                raise webob.exc.HTTPInternalServerError(
                    _('Invalid service catalog json.'))

        ctx = context.RequestContext(user_id,
                                     user_name=user_name,
                                     project_name=project_name,
                                     remote_address=remote_address,
                                     service_catalog=service_catalog,
                                     request_id=req_id,
                                     is_admin=True)

        req.environ['masakari.context'] = ctx
        return self.application 
开发者ID:openstack,项目名称:masakari,代码行数:34,代码来源:auth.py

示例6: test_request_id_extracted_from_env

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def test_request_id_extracted_from_env(self):
        req_id = 'dummy-request-id'
        self.request.headers['X_PROJECT_ID'] = 'testtenantid'
        self.request.headers['X_USER_ID'] = 'testuserid'
        self.request.environ[request_id.ENV_REQUEST_ID] = req_id
        self.request.get_response(self.middleware)
        self.assertEqual(req_id, self.context.request_id) 
开发者ID:openstack,项目名称:masakari,代码行数:9,代码来源:test_auth.py

示例7: test_generate_request_id

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def test_generate_request_id(self):
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.ENV_REQUEST_ID]

        app = request_id.RequestId(application)
        req = webob.Request.blank('/test')
        res = req.get_response(app)
        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
        if isinstance(res_req_id, bytes):
            res_req_id = res_req_id.decode('utf-8')
        self.assertThat(res_req_id, matchers.StartsWith('req-'))
        # request-id in request environ is returned as response body
        self.assertEqual(res.body.decode('utf-8'), res_req_id) 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:16,代码来源:test_request_id.py

示例8: __call__

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def __call__(self, req):
        user = req.headers.get('X_USER')
        user = req.headers.get('X_USER_ID', user)
        if user is None:
            LOG.debug("Neither X_USER_ID nor X_USER found in request")
            return webob.exc.HTTPUnauthorized()

        # get the roles
        roles = [r.strip() for r in req.headers.get('X_ROLE', '').split(',')]
        if 'X_TENANT_ID' in req.headers:
            # This is the new header since Keystone went to ID/Name
            tenant = req.headers['X_TENANT_ID']
        else:
            # This is for legacy compatibility
            tenant = req.headers['X_TENANT']

        project_name = req.headers.get('X_TENANT_NAME')
        project_domain_name = req.headers.get('X-Project-Domain-Name')
        user_domain_name = req.headers.get('X-User-Domain-Name')

        req_id = req.environ.get(request_id.ENV_REQUEST_ID)
        # TODO(alexpilotti): Check why it's not str
        if isinstance(req_id, bytes):
            req_id = req_id.decode()

        # Get the auth token
        auth_token = req.headers.get('X_AUTH_TOKEN')

        # Build a context, including the auth_token...
        remote_address = req.remote_addr

        service_catalog = None
        if req.headers.get('X_SERVICE_CATALOG') is not None:
            try:
                catalog_header = req.headers.get('X_SERVICE_CATALOG')
                service_catalog = jsonutils.loads(catalog_header)
            except ValueError:
                raise webob.exc.HTTPInternalServerError(
                    explanation=_('Invalid service catalog json.'))

        ctx = context.RequestContext(user,
                                     tenant,
                                     project_name=project_name,
                                     project_domain=project_domain_name,
                                     user_domain=user_domain_name,
                                     roles=roles,
                                     auth_token=auth_token,
                                     remote_address=remote_address,
                                     service_catalog=service_catalog,
                                     request_id=req_id)

        req.environ['vdibroker.context'] = ctx
        return self.application 
开发者ID:cloudbase,项目名称:vdi-broker,代码行数:55,代码来源:auth.py

示例9: __call__

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def __call__(self, req):
        user = req.headers.get('X_USER')
        user = req.headers.get('X_USER_ID', user)
        if user is None:
            LOG.debug("Neither X_USER_ID nor X_USER found in request")
            return webob.exc.HTTPUnauthorized()

        # get the roles
        roles = [r.strip() for r in req.headers.get('X_ROLE', '').split(',')]
        if 'X_TENANT_ID' in req.headers:
            # This is the new header since Keystone went to ID/Name
            tenant = req.headers['X_TENANT_ID']
        else:
            # This is for legacy compatibility
            tenant = req.headers['X_TENANT']

        project_name = req.headers.get('X_TENANT_NAME')
        project_domain_name = req.headers.get('X-Project-Domain-Name')
        user_domain_name = req.headers.get('X-User-Domain-Name')

        req_id = req.environ.get(request_id.ENV_REQUEST_ID)
        # TODO(alexpilotti): Check why it's not str
        if isinstance(req_id, bytes):
            req_id = req_id.decode()

        # Get the auth token
        auth_token = req.headers.get('X_AUTH_TOKEN')

        # Build a context, including the auth_token...
        remote_address = req.remote_addr

        service_catalog = None
        if req.headers.get('X_SERVICE_CATALOG') is not None:
            try:
                catalog_header = req.headers.get('X_SERVICE_CATALOG')
                service_catalog = jsonutils.loads(catalog_header)
            except ValueError:
                raise webob.exc.HTTPInternalServerError(
                    explanation=_('Invalid service catalog json.'))

        ctx = context.RequestContext(user,
                                     tenant,
                                     project_name=project_name,
                                     project_domain_name=project_domain_name,
                                     user_domain_name=user_domain_name,
                                     roles=roles,
                                     auth_token=auth_token,
                                     remote_address=remote_address,
                                     service_catalog=service_catalog,
                                     request_id=req_id)

        req.environ['coriolis.context'] = ctx
        return self.application 
开发者ID:cloudbase,项目名称:coriolis,代码行数:55,代码来源:auth.py

示例10: __call__

# 需要导入模块: from oslo_middleware import request_id [as 别名]
# 或者: from oslo_middleware.request_id import ENV_REQUEST_ID [as 别名]
def __call__(self, req):
        headers = req.headers
        environ = req.environ

        user_id = headers.get('X_USER_ID') or headers.get('X_USER')
        if user_id is None:
            LOG.debug("Neither X_USER_ID nor X_USER found in request")
            return webob.exc.HTTPUnauthorized()
        # get the roles
        roles = [r.strip() for r in headers.get('X_ROLE', '').split(',')]
        if 'X_TENANT_ID' in headers:
            # This is the new header since Keystone went to ID/Name
            project_id = headers['X_TENANT_ID']
        else:
            # This is for legacy compatibility
            project_id = headers['X_TENANT']

        project_name = headers.get('X_TENANT_NAME')

        req_id = environ.get(request_id.ENV_REQUEST_ID)

        # Get the auth token
        auth_token = headers.get('X_AUTH_TOKEN',
                                 headers.get('X_STORAGE_TOKEN'))

        # Build a context, including the auth_token...
        remote_address = req.remote_addr

        auth_token_info = environ.get('keystone.token_info')

        service_catalog = None
        if headers.get('X_SERVICE_CATALOG') is not None:
            try:
                catalog_header = headers.get('X_SERVICE_CATALOG')
                service_catalog = jsonutils.loads(catalog_header)
            except ValueError:
                raise webob.exc.HTTPInternalServerError(
                    explanation=_('Invalid service catalog json.'))

        if CONF.use_forwarded_for:
            remote_address = headers.get('X-Forwarded-For', remote_address)
        ctx = context.RequestContext(user_id,
                                     project_id,
                                     project_name=project_name,
                                     roles=roles,
                                     auth_token=auth_token,
                                     remote_address=remote_address,
                                     service_catalog=service_catalog,
                                     request_id=req_id,
                                     auth_token_info=auth_token_info)

        environ['karbor.context'] = ctx
        return self.application 
开发者ID:openstack,项目名称:karbor,代码行数:55,代码来源:auth.py


注:本文中的oslo_middleware.request_id.ENV_REQUEST_ID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。