本文整理汇总了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
示例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
示例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))
示例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)
示例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
示例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
示例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
示例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
示例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()
示例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'])
示例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)
示例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
示例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")
示例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")
示例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")