本文整理汇总了Python中oslo_context.context.is_admin方法的典型用法代码示例。如果您正苦于以下问题:Python context.is_admin方法的具体用法?Python context.is_admin怎么用?Python context.is_admin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_context.context
的用法示例。
在下文中一共展示了context.is_admin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_dict
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [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: elevated
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def elevated(self, show_deleted=None, all_tenants=False,
edit_managed_records=False):
"""Return a version of this context with admin flag set.
Optionally set all_tenants and edit_managed_records
"""
context = self.deepcopy()
context.is_admin = True
# NOTE(kiall): Ugly - required to match http://tinyurl.com/o3y8qmw
context.roles.append('admin')
if show_deleted is not None:
context.show_deleted = show_deleted
if all_tenants:
context.all_tenants = True
if edit_managed_records:
context.edit_managed_records = True
return context
示例3: to_dict
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [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
示例4: from_dict
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def from_dict(cls, values):
allowed_keys = [
'user_id',
'project_id',
'project_name',
'domain',
'read_deleted',
'remote_address',
'timestamp',
'quota_class',
'service_catalog',
'request_id',
'is_admin',
'roles',
'auth_token',
'user_domain',
'project_domain',
'auth_token_info'
]
kwargs = {k: values[k] for k in values if k in allowed_keys}
return cls(**kwargs)
示例5: to_policy_values
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def to_policy_values(self):
policy = super(RequestContext, self).to_policy_values()
policy['is_admin'] = self.is_admin
return policy
示例6: elevated
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def elevated(self):
"""Return a version of this context with admin flag set."""
context = copy.copy(self)
# context.roles must be deepcopied to leave original roles
# without changes
context.roles = copy.deepcopy(self.roles)
context.is_admin = True
if 'admin' not in context.roles:
context.roles.append('admin')
return context
示例7: get_admin_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def get_admin_context(show_deleted=False, all_projects=False):
"""Create an administrator context.
:param show_deleted: if True, will show deleted items when query db
"""
context = RequestContext(user_id=None,
project=None,
is_admin=True,
show_deleted=show_deleted,
all_projects=all_projects)
return context
示例8: get_admin_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def get_admin_context(cls, **kwargs):
# TODO(kiall): Remove Me
kwargs['is_admin'] = True
kwargs['roles'] = ['admin']
return cls(None, **kwargs)
示例9: elevated
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def elevated(self, read_deleted=None):
"""Return a version of this context with admin flag set."""
context = copy.copy(self)
# context.roles must be deepcopied to leave original roles
# without changes
context.roles = copy.deepcopy(self.roles)
context.is_admin = True
if 'admin' not in context.roles:
context.roles.append('admin')
if read_deleted is not None:
context.read_deleted = read_deleted
return context
示例10: get_admin_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def get_admin_context(read_deleted="no"):
return RequestContext(user_id=None,
project_id=None,
is_admin=True,
read_deleted=read_deleted,
overwrite=False)
示例11: to_dict
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [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),
'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),
'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),
})
# NOTE(tonyb): This can be removed once we're certain to have a
# RequestContext contains 'is_admin_project', We can only get away with
# this because we "know" the default value of 'is_admin_project' which
# is very fragile.
values.update({
'is_admin_project': getattr(self, 'is_admin_project', True),
})
return values
示例12: get_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def get_context():
"""A helper method to get a blank context.
Note that overwrite is False here so this context will not update the
greenthread-local stored context that is used when logging.
"""
return RequestContext(user_id=None,
project_id=None,
is_admin=False,
overwrite=False)
示例13: get_admin_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def get_admin_context(read_deleted="no"):
# NOTE(alaski): This method should only be used when an admin context is
# necessary for the entirety of the context lifetime. If that's not the
# case please use get_context(), or create the RequestContext manually, and
# use context.elevated() where necessary. Some periodic tasks may use
# get_admin_context so that their database calls are not filtered on
# project_id.
return RequestContext(user_id=None,
project_id=None,
is_admin=True,
read_deleted=read_deleted,
overwrite=False)
示例14: is_user_context
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def is_user_context(context):
"""Indicates if the request context is a normal user."""
if not context:
return False
if context.is_admin:
return False
if not context.user_id or not context.project_id:
return False
return True
示例15: to_policy_values
# 需要导入模块: from oslo_context import context [as 别名]
# 或者: from oslo_context.context import is_admin [as 别名]
def to_policy_values(self):
policy = super(RequestContext, self).to_policy_values()
policy['is_admin'] = self.is_admin
return policy