Python oslo_context.context.is_admin() Examples
The following are 21
code examples of oslo_context.context.is_admin().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_context.context
, or try the search function
.
Example #1
Source File: context.py From zun with Apache License 2.0 | 6 votes |
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
Example #2
Source File: context.py From karbor with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: context.py From designate with Apache License 2.0 | 6 votes |
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
Example #4
Source File: context.py From masakari with Apache License 2.0 | 6 votes |
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
Example #5
Source File: context.py From karbor with Apache License 2.0 | 5 votes |
def get_admin_context(read_deleted="no"): return RequestContext(user_id=None, project_id=None, is_admin=True, read_deleted=read_deleted, overwrite=False)
Example #6
Source File: context.py From karbor with Apache License 2.0 | 5 votes |
def elevated(self, read_deleted=None, overwrite=False): """Return a version of this context with admin flag set.""" context = self.deepcopy() 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
Example #7
Source File: context.py From karbor with Apache License 2.0 | 5 votes |
def to_policy_values(self): policy = super(RequestContext, self).to_policy_values() policy['is_admin'] = self.is_admin return policy
Example #8
Source File: context.py From cyborg with Apache License 2.0 | 5 votes |
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
Example #9
Source File: context.py From cyborg with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: context.py From cyborg with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: context.py From cyborg with Apache License 2.0 | 5 votes |
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
Example #12
Source File: context.py From masakari with Apache License 2.0 | 5 votes |
def get_admin_context(read_deleted="no"): return RequestContext(user_id=None, project_id=None, is_admin=True, read_deleted=read_deleted, overwrite=False)
Example #13
Source File: context.py From masakari with Apache License 2.0 | 5 votes |
def to_policy_values(self): policy = super(RequestContext, self).to_policy_values() policy['is_admin'] = self.is_admin return policy
Example #14
Source File: context.py From masakari with Apache License 2.0 | 5 votes |
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
Example #15
Source File: context.py From designate with Apache License 2.0 | 5 votes |
def get_admin_context(cls, **kwargs): # TODO(kiall): Remove Me kwargs['is_admin'] = True kwargs['roles'] = ['admin'] return cls(None, **kwargs)
Example #16
Source File: context.py From zun with Apache License 2.0 | 5 votes |
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
Example #17
Source File: context.py From zun with Apache License 2.0 | 5 votes |
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
Example #18
Source File: context.py From zun with Apache License 2.0 | 5 votes |
def to_policy_values(self): policy = super(RequestContext, self).to_policy_values() policy['is_admin'] = self.is_admin return policy
Example #19
Source File: context.py From cyborg with Apache License 2.0 | 4 votes |
def __init__(self, user_id=None, project_id=None, is_admin=None, read_deleted="no", remote_address=None, timestamp=None, quota_class=None, service_catalog=None, user_auth_plugin=None, **kwargs): """:param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that *only* deleted records are visible. :param overwrite: Set to False to ensure that the greenthread local copy of the index is not overwritten. :param instance_lock_checked: This is not used and will be removed in a future release. :param user_auth_plugin: The auth plugin for the current request's authentication data. """ if user_id: kwargs['user_id'] = user_id if project_id: kwargs['project_id'] = project_id super(RequestContext, self).__init__(is_admin=is_admin, **kwargs) self.read_deleted = read_deleted self.remote_address = remote_address if not timestamp: timestamp = timeutils.utcnow() if isinstance(timestamp, six.string_types): timestamp = timeutils.parse_strtime(timestamp) self.timestamp = timestamp if service_catalog: # Only include required parts of service_catalog self.service_catalog = [s for s in service_catalog if s.get('type') in ('image')] else: # if list is empty or none self.service_catalog = [] self.user_auth_plugin = user_auth_plugin # if self.is_admin is None: # self.is_admin = policy.check_is_admin(self)
Example #20
Source File: context.py From karbor with Apache License 2.0 | 4 votes |
def __init__(self, user_id, project_id, is_admin=None, read_deleted="no", roles=None, project_name=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, service_catalog=None, domain=None, user_domain=None, project_domain=None, auth_token_info=None): """Initialize RequestContext. :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that *only* deleted records are visible. :param overwrite: Set to False to ensure that the greenthread local copy of the index is not overwritten. """ super(RequestContext, self).__init__(auth_token=auth_token, user=user_id, tenant=project_id, domain=domain, user_domain=user_domain, project_domain=project_domain, is_admin=is_admin, request_id=request_id, overwrite=overwrite) self.roles = roles or [] self.project_name = project_name self.read_deleted = read_deleted self.remote_address = remote_address if not timestamp: timestamp = timeutils.utcnow() elif isinstance(timestamp, six.string_types): timestamp = timeutils.parse_isotime(timestamp) self.timestamp = timestamp self.quota_class = quota_class self._auth_token_info = auth_token_info if service_catalog: # Only include required parts of service_catalog self.service_catalog = [s for s in service_catalog if s.get('type') in ('identity', 'compute', 'object-store', 'image', 'volume', 'volumev2', 'network', 'volumev3', 'orchestration', 'share', 'sharev2', 'database')] else: # if list is empty or none self.service_catalog = [] # We need to have RequestContext attributes defined # when policy.check_is_admin invokes request logging # to make it loggable. if self.is_admin is None: self.is_admin = policy.check_is_admin(self) elif self.is_admin and 'admin' not in self.roles: self.roles.append('admin')
Example #21
Source File: context.py From zun with Apache License 2.0 | 4 votes |
def __init__(self, auth_token=None, domain_id=None, domain_name=None, user_name=None, user_id=None, user_domain_name=None, user_domain_id=None, project_name=None, project_id=None, roles=None, is_admin=None, read_only=False, show_deleted=False, request_id=None, trust_id=None, auth_token_info=None, all_projects=False, password=None, timestamp=None, **kwargs): """Stores several additional request parameters: :param domain_id: The ID of the domain. :param domain_name: The name of the domain. :param user_domain_id: The ID of the domain to authenticate a user against. :param user_domain_name: The name of the domain to authenticate a user against. """ super(RequestContext, self).__init__(auth_token=auth_token, user_id=user_name, project_id=project_name, is_admin=is_admin, read_only=read_only, show_deleted=show_deleted, request_id=request_id, roles=roles) self.user_name = user_name self.user_id = user_id self.project_name = project_name self.project_id = project_id self.domain_id = domain_id self.domain_name = domain_name self.user_domain_id = user_domain_id self.user_domain_name = user_domain_name self.auth_token_info = auth_token_info self.trust_id = trust_id self.all_projects = all_projects self.password = password if is_admin is None: self.is_admin = policy.check_is_admin(self) else: self.is_admin = is_admin if not timestamp: timestamp = timeutils.utcnow() if isinstance(timestamp, str): timestamp = timeutils.parse_strtime(timestamp) self.timestamp = timestamp