a
    !fQ                     @   sX   d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 G dd deZG dd	 d	eZ
d
S )z7A Client for interacting with the Resource Manager API.    )Client)Iterator)
ConnectionProjectc                   @   s0   e Zd ZdZeZd	ddZdd Zd
ddZdS )r   a  Client to bundle configuration needed for API requests.

    See
    https://cloud.google.com/resource-manager/reference/rest/
    for more information on this API.

    Automatically get credentials::

        >>> from gcloud import resource_manager
        >>> client = resource_manager.Client()

    :type credentials: :class:`oauth2client.client.OAuth2Credentials` or
                       :class:`NoneType`
    :param credentials: The OAuth2 Credentials to use for the connection
                        owned by this client. If not passed (and if no ``http``
                        object is passed), falls back to the default inferred
                        from the environment.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: An optional HTTP object to make requests. If not passed, an
                 ``http`` object is created that is bound to the
                 ``credentials`` for the current object.
    Nc                 C   s   t || ||dS )a  Creates a :class:`.Project` bound to the current client.

        Use :meth:`Project.reload()         <gcloud.resource_manager.project.Project.reload>` to retrieve
        project metadata after creating a :class:`.Project` instance.

        .. note:

            This does not make an API call.

        :type project_id: str
        :param project_id: The ID for this project.

        :type name: string
        :param name: The display name of the project.

        :type labels: dict
        :param labels: A list of labels associated with the project.

        :rtype: :class:`.Project`
        :returns: A new instance of a :class:`.Project` **without**
                  any metadata loaded.
        )
project_idclientnamelabelsr   )selfr   r	   r
    r   _/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/resource_manager/client.pynew_project3   s    zClient.new_projectc                 C   s   |  |}|  |S )a  Fetch an existing project and it's relevant metadata by ID.

        .. note::

            If the project does not exist, this will raise a
            :class:`NotFound <gcloud.exceptions.NotFound>` error.

        :type project_id: str
        :param project_id: The ID for this project.

        :rtype: :class:`.Project`
        :returns: A :class:`.Project` with metadata fetched from the API.
        )r   reload)r   r   projectr   r   r   fetch_projectN   s    
zClient.fetch_projectc                 C   s0   i }|dur||d< |dur$||d< t | |dS )a  List the projects visible to this client.

        Example::

            >>> from gcloud import resource_manager
            >>> client = resource_manager.Client()
            >>> for project in client.list_projects():
            ...     print project.project_id

        List all projects with label ``'environment'`` set to ``'prod'``
        (filtering by labels)::

            >>> from gcloud import resource_manager
            >>> client = resource_manager.Client()
            >>> env_filter = {'labels.environment': 'prod'}
            >>> for project in client.list_projects(env_filter):
            ...     print project.project_id

        See:
        https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/list

        Complete filtering example::

            >>> project_filter = {  # Return projects with...
            ...     'name': 'My Project',  # name set to 'My Project'.
            ...     'id': 'my-project-id',  # id set to 'my-project-id'.
            ...     'labels.stage': 'prod',  # the label 'stage' set to 'prod'
            ...     'labels.color': '*'  # a label 'color' set to anything.
            ... }
            >>> client.list_projects(project_filter)

        :type filter_params: dict
        :param filter_params: (Optional) A dictionary of filter options where
                              each key is a property to filter on, and each
                              value is the (case-insensitive) value to check
                              (or the glob ``*`` to check for existence of the
                              property). See the example above for more
                              details.

        :type page_size: int
        :param page_size: (Optional) Maximum number of projects to return in a
                          single page. If not passed, defaults to a value set
                          by the API.

        :rtype: :class:`_ProjectIterator`
        :returns: A project iterator. The iterator will make multiple API
                  requests if you continue iterating and there are more
                  pages of results. Each item returned will be a.
                  :class:`.Project`.
        NZpageSizefilter)extra_params)_ProjectIterator)r   Zfilter_paramsZ	page_sizer   r   r   r   list_projects`   s    3zClient.list_projects)NN)NN)	__name__
__module____qualname____doc__r   Z_connection_classr   r   r   r   r   r   r   r      s
   
r   c                       s*   e Zd ZdZd fdd	Zdd Z  ZS )r   a  An iterator over a list of Project resources.

    You shouldn't have to use this directly, but instead should use the
    helper methods on :class:`gcloud.resource_manager.client.Client`
    objects.

    :type client: :class:`gcloud.resource_manager.client.Client`
    :param client: The client to use for making connections.

    :type extra_params: dict
    :param extra_params: (Optional) Extra query string parameters for
                         the API call.
    Nc                    s   t t| j|d|d d S )Nz	/projects)r   pathr   )superr   __init__)r   r   r   	__class__r   r   r      s    z_ProjectIterator.__init__c                 c   s,   | dg D ]}tj|| jd}|V  qdS )zYield :class:`.Project` items from response.

        :type response: dict
        :param response: The JSON API response for a page of projects.
        Zprojects)r   N)getr   Zfrom_api_reprr   )r   responseresourceitemr   r   r   get_items_from_response   s    z(_ProjectIterator.get_items_from_response)N)r   r   r   r   r   r#   __classcell__r   r   r   r   r      s   r   N)r   Zgcloud.clientr   Z
BaseClientZgcloud.iteratorr   Z"gcloud.resource_manager.connectionr   Zgcloud.resource_manager.projectr   r   r   r   r   r   <module>   s    