cloud_resource_manager.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:forseti-security 作者: GoogleCloudPlatform 项目源码 文件源码
def get_projects(self, resource_name, parent_id=None, parent_type=None,
                     **filterargs):
        """Get all the projects the authenticated account has access to.

        If no parent is passed in, then all projects the caller has visibility
        to are returned. This is significantly less efficient then listing by
        parent.

        Args:
            resource_name (str): The resource type.
            parent_id (str): The id of the organization or folder parent object.
            parent_type (str): Either folder or organization.
            **filterargs (dict): Extra project filter args.

        Yields:
            dict: The projects.list() response.
            https://cloud.google.com/resource-manager/reference/rest/v1/projects/list#response-body

        Raises:
            ApiExecutionError: An error has occurred when executing the API.
        """
        filters = []

        for key, value in filterargs.items():
            filters.append('{}:{}'.format(key, value))

        if parent_id:
            filters.append('parent.id:{}'.format(parent_id))
        if parent_type:
            filters.append('parent.type:{}'.format(parent_type))

        try:
            for response in self.repository.projects.list(
                    filter=' '.join(filters)):
                yield response
        except (errors.HttpError, HttpLib2Error) as e:
            raise api_errors.ApiExecutionError(resource_name, e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号