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


Python context.project_id方法代碼示例

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


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

示例1: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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 project_id [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: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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

示例4: from_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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) 
開發者ID:openstack,項目名稱:karbor,代碼行數:23,代碼來源:context.py

示例5: can

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def can(self, action, target=None, fatal=True, might_not_exist=False):
        """Verifies that the given action is valid on the target in this context.

        :param action: string representing the action to be checked.
        :param target: dictionary representing the object of the action
            for object creation this should be a dictionary representing the
            location of the object e.g. ``{'project_id': context.project_id}``.
            If None, then this default target will be considered:
            {'project_id': self.project_id, 'user_id': self.user_id}
        :param fatal: if False, will return False when an
            exception.NotAuthorized occurs.
        :param might_not_exist: If True the policy check is skipped (and the
            function returns True) if the specified policy does not exist.
            Defaults to false.

        :raises zun.common.exception.NotAuthorized: if verification fails and
            fatal is True.

        :return: returns a non-False value (not necessarily "True") if
            authorized and False if not authorized and fatal is False.
        """
        if target is None:
            target = {'project_id': self.project_id,
                      'user_id': self.user_id}

        try:
            return policy.authorize(self, action, target,
                                    might_not_exist=might_not_exist)
        except exception.NotAuthorized:
            if fatal:
                raise
            return False 
開發者ID:openstack,項目名稱:zun,代碼行數:34,代碼來源:context.py

示例6: is_user_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def is_user_context(context):
    """Indicates if the request context is a normal user."""
    if not context:
        return False
    if context.is_os_admin:
        return False
    if not context.user_id or not context.project_id:
        return False
    return True 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:11,代碼來源:context.py

示例7: can

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def can(self, action, target=None, fatal=True):
        """Verifies that the given action is valid on the target in this context.

        :param action: string representing the action to be checked.
        :param target: dictionary representing the object of the action
            for object creation this should be a dictionary representing the
            location of the object e.g. ``{'project_id': context.project_id}``.
            If None, then this default target will be considered:
            {'project_id': self.project_id, 'user_id': self.user_id}
        :param fatal: if False, will return False when an exception.Forbidden
           occurs.

        :raises masakari.exception.Forbidden: if verification fails and fatal
            is True.

        :return: returns a non-False value (not necessarily "True") if
            authorized and False if not authorized and fatal is False.
        """
        if target is None:
            target = {'project_id': self.project_id,
                      'user_id': self.user_id}
        try:
            return policy.authorize(self, action, target)
        except exception.Forbidden:
            if fatal:
                raise
            return False 
開發者ID:openstack,項目名稱:masakari,代碼行數:29,代碼來源:context.py

示例8: get_admin_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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) 
開發者ID:openstack,項目名稱:masakari,代碼行數:8,代碼來源:context.py

示例9: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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 
開發者ID:openstack,項目名稱:cyborg,代碼行數:29,代碼來源:context.py

示例10: from_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def from_dict(cls, values):
        return super(RequestContext, cls).from_dict(
            values,
            user_id=values.get('user_id'),
            project_id=values.get('project_id'),
            # TODO(sdague): oslo.context has show_deleted, if
            # possible, we should migrate to that in the future so we
            # don't need to be different here.
            read_deleted=values.get('read_deleted', 'no'),
            remote_address=values.get('remote_address'),
            timestamp=values.get('timestamp'),
            quota_class=values.get('quota_class'),
            service_catalog=values.get('service_catalog'),
        ) 
開發者ID:openstack,項目名稱:cyborg,代碼行數:16,代碼來源:context.py

示例11: get_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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) 
開發者ID:openstack,項目名稱:cyborg,代碼行數:12,代碼來源:context.py

示例12: get_admin_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [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) 
開發者ID:openstack,項目名稱:cyborg,代碼行數:14,代碼來源:context.py

示例13: authorize_project_context

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def authorize_project_context(context, project_id):
    """Ensures a request has permission to access the given project."""
    if is_user_context(context):
        if not context.project_id:
            raise exception.Forbidden()
        elif context.project_id != project_id:
            raise exception.Forbidden() 
開發者ID:openstack,項目名稱:cyborg,代碼行數:9,代碼來源:context.py

示例14: to_dict

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def to_dict(self):
        result = super(RequestContext, self).to_dict()
        result['user_id'] = self.user_id
        result['project_id'] = self.project_id
        result['project_name'] = self.project_name
        result['domain'] = self.domain
        result['read_deleted'] = self.read_deleted
        result['roles'] = self.roles
        result['remote_address'] = self.remote_address
        result['timestamp'] = self.timestamp.isoformat()
        result['quota_class'] = self.quota_class
        result['service_catalog'] = self.service_catalog
        result['request_id'] = self.request_id
        result['auth_token_info'] = self._auth_token_info
        return result 
開發者ID:openstack,項目名稱:karbor,代碼行數:17,代碼來源:context.py

示例15: can

# 需要導入模塊: from oslo_context import context [as 別名]
# 或者: from oslo_context.context import project_id [as 別名]
def can(self, action, target_obj=None, fatal=True):
        """Verifies that the given action is valid on the target in this context.

        :param action: string representing the action to be checked.
        :param target: dictionary representing the object of the action
            for object creation this should be a dictionary representing the
            location of the object e.g. ``{'project_id': context.project_id}``.
            If None, then this default target will be considered:
            {'project_id': self.project_id, 'user_id': self.user_id}
        :param: target_obj: dictionary representing the object which will be
            used to update target.
        :param fatal: if False, will return False when an
            exception.NotAuthorized occurs.

        :raises nova.exception.Forbidden: if verification fails and fatal is
            True.

        :return: returns a non-False value (not necessarily "True") if
            authorized and False if not authorized and fatal is False.
        """
        target = {'project_id': self.project_id,
                  'user_id': self.user_id}
        if isinstance(target_obj, objects_base.KarborObject):
            # Turn object into dict so target.update can work
            target.update(
                target_obj.obj_to_primitive()['karbor_object.data'] or {})
        else:
            target.update(target_obj or {})

        try:
            return policy.authorize(self, action, target)
        except exception.NotAuthorized:
            if fatal:
                raise
            return False 
開發者ID:openstack,項目名稱:karbor,代碼行數:37,代碼來源:context.py


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