當前位置: 首頁>>代碼示例>>Python>>正文


Python context.RequestContext方法代碼示例

本文整理匯總了Python中oslo_context.context.RequestContext方法的典型用法代碼示例。如果您正苦於以下問題:Python context.RequestContext方法的具體用法?Python context.RequestContext怎麽用?Python context.RequestContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_context.context的用法示例。


在下文中一共展示了context.RequestContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def to_dict(self):
        value = super(RequestContext, self).to_dict()
        value.update({'auth_token': self.auth_token,
                      'domain_id': self.domain_id,
                      'domain_name': self.domain_name,
                      'user_domain_id': self.user_domain_id,
                      'user_domain_name': self.user_domain_name,
                      'user_name': self.user_name,
                      'user_id': self.user_id,
                      'project_name': self.project_name,
                      'project_id': self.project_id,
                      'is_admin': self.is_admin,
                      'read_only': self.read_only,
                      'roles': self.roles,
                      'show_deleted': self.show_deleted,
                      'request_id': self.request_id,
                      'trust_id': self.trust_id,
                      'auth_token_info': self.auth_token_info,
                      'password': self.password,
                      'all_projects': self.all_projects,
                      'timestamp': timeutils.strtime(self.timestamp) if
                      hasattr(self, 'timestamp') else None
                      })
        return value 
開發者ID:openstack,項目名稱:zun,代碼行數:26,代碼來源:context.py

示例2: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def to_dict(self):
        values = super(RequestContext, self).to_dict()
        # FIXME(dims): defensive hasattr() checks need to be
        # removed once we figure out why we are seeing stack
        # traces
        values.update({
            'user_id': getattr(self, 'user_id', None),
            'project_id': getattr(self, 'project_id', None),
            'is_admin': getattr(self, 'is_admin', None),
            'remote_address': getattr(self, 'remote_address', None),
            'timestamp': self.timestamp.strftime(
                timeutils.PERFECT_TIME_FORMAT) if hasattr(
                self, 'timestamp') else None,
            'request_id': getattr(self, 'request_id', None),
            'quota_class': getattr(self, 'quota_class', None),
            'user_name': getattr(self, 'user_name', None),
            'service_catalog': getattr(self, 'service_catalog', None),
            'project_name': getattr(self, 'project_name', None),
            'is_os_admin': getattr(self, 'is_os_admin', None),
            'api_version': getattr(self, 'api_version', None),
        })
        return values 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:24,代碼來源:context.py

示例3: get_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def get_context(self):
        username = CONF.identity.username
        password = CONF.identity.password
        project_name = CONF.identity.project_name
        auth_url = CONF.identity.auth_url
        user_domain_name = CONF.identity.user_domain_name
        project_domain_name = CONF.identity.project_domain_name

        auth = identity.V3Password(auth_url=auth_url,
                                   username=username,
                                   password=password,
                                   project_name=project_name,
                                   user_domain_name=user_domain_name,
                                   project_domain_name=project_domain_name)
        sess = session.Session(auth=auth)

        return context.RequestContext(auth_token=auth.get_token(sess),
                                      tenant=auth.get_project_id(sess)) 
開發者ID:openstack,項目名稱:castellan,代碼行數:20,代碼來源:test_barbican_key_manager.py

示例4: test_token_credential_config_override_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_token_credential_config_override_context(self):
        ctxt_token_value = '00000000000000000000000000000000'
        ctxt = context.RequestContext(auth_token=ctxt_token_value)

        conf_token_value = 'ec9799cd921e4e0a8ab6111c08ebf065'

        self.config_fixture.config(
            auth_type='token',
            token=conf_token_value,
            group='key_manager'
        )

        token_context = utils.credential_factory(conf=CONF, context=ctxt)
        token_context_class = token_context.__class__.__name__

        self.assertEqual('Token', token_context_class)
        self.assertEqual(conf_token_value, token_context.token) 
開發者ID:openstack,項目名稱:castellan,代碼行數:19,代碼來源:test_utils.py

示例5: _get_secret_data

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def _get_secret_data(cert_manager, project_id, secret_ref, for_delete=False):
    """Get the secret from the certificate manager and upload it to the amp.

    :returns: The secret data.
    """
    context = oslo_context.RequestContext(project_id=project_id)
    try:
        secret_data = cert_manager.get_secret(context, secret_ref)
    except Exception as e:
        LOG.warning('Unable to retrieve certificate: %s due to %s.',
                    secret_ref, str(e))
        if for_delete:
            secret_data = None
        else:
            raise exceptions.CertificateRetrievalException(ref=secret_ref)
    return secret_data 
開發者ID:openstack,項目名稱:octavia,代碼行數:18,代碼來源:utils.py

示例6: _process_secret

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def _process_secret(self, listener, secret_ref, amphora=None, obj_id=None):
        """Get the secret from the cert manager and upload it to the amp.

        :returns: The filename of the secret in the amp.
        """
        if not secret_ref:
            return None
        context = oslo_context.RequestContext(project_id=listener.project_id)
        secret = self.cert_manager.get_secret(context, secret_ref)
        try:
            secret = secret.encode('utf-8')
        except AttributeError:
            pass
        md5 = hashlib.md5(secret).hexdigest()  # nosec
        id = hashlib.sha1(secret).hexdigest()  # nosec
        name = '{id}.pem'.format(id=id)

        if amphora and obj_id:
            self._upload_cert(
                amphora, obj_id, pem=secret, md5=md5, name=name)
        return name 
開發者ID:openstack,項目名稱:octavia,代碼行數:23,代碼來源:rest_api_driver.py

示例7: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def to_dict(self):
        value = super(RequestContext, self).to_dict()
        value.update({'auth_token': self.auth_token,
                      'auth_url': self.auth_url,
                      'domain_id': self.domain_id,
                      'domain_name': self.domain_name,
                      'user_domain_id': self.user_domain_id,
                      'user_domain_name': self.user_domain_name,
                      'user_name': self.user_name,
                      'user_id': self.user_id,
                      'project_name': self.project_name,
                      'project_id': self.project_id,
                      'is_admin': self.is_admin,
                      'read_only': self.read_only,
                      'roles': self.roles,
                      'show_deleted': self.show_deleted,
                      'request_id': self.request_id,
                      'trust_id': self.trust_id,
                      'auth_token_info': self.auth_token_info,
                      'password': self.password,
                      'all_tenants': self.all_tenants})
        return value 
開發者ID:openstack,項目名稱:magnum,代碼行數:24,代碼來源:context.py

示例8: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def to_dict(self):
        values = super(RequestContext, self).to_dict()
        # FIXME: defensive hasattr() checks need to be
        # removed once we figure out why we are seeing stack
        # traces
        values.update({
            'user_id': getattr(self, 'user_id', None),
            'project_id': getattr(self, 'project_id', None),
            'is_admin': getattr(self, 'is_admin', None),
            'read_deleted': getattr(self, 'read_deleted', 'no'),
            'remote_address': getattr(self, 'remote_address', None),
            'timestamp': utils.strtime(self.timestamp) if hasattr(
                self, 'timestamp') else None,
            'request_id': getattr(self, 'request_id', None),
            'user_name': getattr(self, 'user_name', None),
            'service_catalog': getattr(self, 'service_catalog', None),
            'project_name': getattr(self, 'project_name', None)
        })
        return values 
開發者ID:openstack,項目名稱:masakari,代碼行數:21,代碼來源:context.py

示例9: before

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def before(self, state):
        user_id = state.request.headers.get('X-User-Id')
        user_id = state.request.headers.get('X-User', user_id)
        user_name = state.request.headers.get('X-User-Name', '')
        tenant_id = state.request.headers.get('X-Project-Id')
        auth_token = state.request.headers.get('X-Auth-Token')
        # TODO(DANY) use roles
        # roles = pecan.request.headers.get('X-Roles', '').split(',')
        # roles = [r.strip() for r in roles]
        ctx = context.RequestContext(auth_token=auth_token, user=user_id,
                                     # roles=roles,
                                     tenant=tenant_id,
                                     is_admin=(user_name == 'admin'))

        # Inject the context...
        state.request.context = ctx.to_dict() 
開發者ID:openstack,項目名稱:vitrage,代碼行數:18,代碼來源:hooks.py

示例10: test_from_dict_unknown_keys

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_from_dict_unknown_keys(self):
        dct = {
            "auth_token": "token1",
            "user": "user1",
            "read_only": True,
            "roles": "role1,role2,role3",  # future review provides this
            "color": "red",
            "unknown": ""
        }
        ctx = context.RequestContext.from_dict(dct)
        self.assertEqual("token1", ctx.auth_token)
        self.assertEqual("user1", ctx.user_id)
        self.assertIsNone(ctx.project_id)
        self.assertFalse(ctx.is_admin)
        self.assertTrue(ctx.read_only)
        self.assertRaises(KeyError, lambda: ctx.__dict__['color']) 
開發者ID:openstack,項目名稱:oslo.context,代碼行數:18,代碼來源:test_context.py

示例11: test_from_dict_overrides

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_from_dict_overrides(self):
        dct = {
            "auth_token": "token1",
            "user": "user1",
            "read_only": True,
            "roles": "role1,role2,role3",
            "color": "red",
            "unknown": ""
        }
        ctx = context.RequestContext.from_dict(dct,
                                               user="user2",
                                               project_name="project1")
        self.assertEqual("token1", ctx.auth_token)
        self.assertEqual("user2", ctx.user)
        self.assertEqual("project1", ctx.project_name)
        self.assertIsNone(ctx.tenant)
        self.assertFalse(ctx.is_admin)
        self.assertTrue(ctx.read_only) 
開發者ID:openstack,項目名稱:oslo.context,代碼行數:20,代碼來源:test_context.py

示例12: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def to_dict(self):
        values = super(RequestContext, self).to_dict()
        # FIXME(dims): defensive hasattr() checks need to be
        # removed once we figure out why we are seeing stack
        # traces
        values.update({
            'user_id': getattr(self, 'user_id', None),
            'user_name': getattr(self, 'user_name', None),
            'project_id': getattr(self, 'project_id', None),
            'project_name': getattr(self, 'project_name', None),
            'domain_id': getattr(self, 'domain_id', None),
            'domain_name': getattr(self, 'domain_name', None),
            'auth_token_info': getattr(self, 'auth_token_info', None),
            'is_admin': getattr(self, 'is_admin', None),
            'timestamp': self.timestamp.isoformat() if hasattr(
                self, 'timestamp') else None,
            'request_id': getattr(self, 'request_id', None),
        })
        return values 
開發者ID:openstack,項目名稱:watcher,代碼行數:21,代碼來源:context.py

示例13: test_session_reader_nested_in_connection_reader

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_session_reader_nested_in_connection_reader(self):
        context = oslo_context.RequestContext()

        @enginefacade.reader.connection
        def go1(context):
            context.connection.execute("test1")
            go2(context)

        @enginefacade.reader
        def go2(context):
            context.session.execute("test2")
        go1(context)

        with self._assert_engines() as engines:
            with self._assert_reader_connection(engines) as connection:
                connection.execute("test1")
                with self._assert_makers(engines) as makers:
                    with self._assert_reader_session(
                            makers, connection) as session:
                        session.execute("test2") 
開發者ID:openstack,項目名稱:oslo.db,代碼行數:22,代碼來源:test_enginefacade.py

示例14: test_connection_reader_nested_in_session_reader

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_connection_reader_nested_in_session_reader(self):
        context = oslo_context.RequestContext()

        @enginefacade.reader
        def go1(context):
            context.session.execute("test1")
            go2(context)

        @enginefacade.reader.connection
        def go2(context):
            context.connection.execute("test2")

        go1(context)

        with self._assert_engines() as engines:
            with self._assert_makers(engines) as makers:
                with self._assert_reader_session(makers) as session:
                    session.execute("test1")
                    with self._assert_reader_connection(
                            engines, session) as connection:
                        connection.execute("test2") 
開發者ID:openstack,項目名稱:oslo.db,代碼行數:23,代碼來源:test_enginefacade.py

示例15: test_reader_nested_in_writer_ok

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import RequestContext [as 別名]
def test_reader_nested_in_writer_ok(self):
        context = oslo_context.RequestContext()

        @enginefacade.writer
        def go1(context):
            context.session.execute("test1")
            go2(context)

        @enginefacade.reader
        def go2(context):
            context.session.execute("test2")

        go1(context)
        with self._assert_engines() as engines:
            with self._assert_makers(engines) as makers:
                with self._assert_writer_session(makers) as session:
                    session.execute("test1")
                    session.execute("test2") 
開發者ID:openstack,項目名稱:oslo.db,代碼行數:20,代碼來源:test_enginefacade.py


注:本文中的oslo_context.context.RequestContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。