a
    !f[)                     @   s$   d Z ddlmZ G dd deZdS )zAUtility for managing projects via the Cloud Resource Manager API.    )NotFoundc                   @   s   e Zd ZdZdddZdd Zedd Zd	d
 Ze	dd Z
e	dd Zdd ZdddZd ddZd!ddZd"ddZd#ddZd$ddZdS )%Projecta  Projects are containers for your work on Google Cloud Platform.

    .. note::

        A :class:`Project` can also be created via
        :meth:`Client.new_project()         <gcloud.resource_manager.client.Client.new_project>`

    To manage labels on a :class:`Project`::

        >>> from gcloud import resource_manager
        >>> client = resource_manager.Client()
        >>> project = client.new_project('purple-spaceship-123')
        >>> project.labels = {'color': 'purple'}
        >>> project.labels['environment'] = 'production'
        >>> project.update()

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

    :type project_id: string
    :param project_id: The globally unique ID of the project.

    :type client: :class:`gcloud.resource_manager.client.Client`
    :param client: The Client used with 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.
    Nc                 C   s,   || _ || _|| _d | _|pi | _d | _d S )N)_client
project_idnamenumberlabelsstatus)selfr   clientr   r    r   `/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/resource_manager/project.py__init__6   s    
zProject.__init__c                 C   s   d| j | jf S )Nz<Project: %r (%r)>)r   r   r
   r   r   r   __repr__>   s    zProject.__repr__c                 C   s   | |d |d}| | |S )a  Factory:  construct a project given its API representation.

        :type resource: dict
        :param resource: project resource representation returned from the API

        :type client: :class:`gcloud.resource_manager.client.Client`
        :param client: The Client used with this project.

        :rtype: :class:`gcloud.resource_manager.project.Project`
        :returns: The project created.
        	projectId)r   r   )set_properties_from_api_repr)clsresourcer   projectr   r   r   from_api_reprA   s    
zProject.from_api_reprc                 C   s2   | d| _|d | _| di | _|d | _dS )z7Update specific properties from its API representation.r   ZprojectNumberr   ZlifecycleStateN)getr   r   r   r	   )r
   r   r   r   r   r   R   s    
z$Project.set_properties_from_api_reprc                 C   s   | j stdd| j  S )z?Fully-qualified name (ie, ``'projects/purple-spaceship-123'``).zMissing project ID.zprojects/%s)r   
ValueErrorr   r   r   r   	full_nameY   s    zProject.full_namec                 C   s
   d| j  S )z?URL for the project (ie, ``'/projects/purple-spaceship-123'``).z/%s)r   r   r   r   r   path`   s    zProject.pathc                 C   s   |du r| j }|S )a  Check client or verify over-ride.

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current project.

        :rtype: :class:`gcloud.resource_manager.client.Client`
        :returns: The client passed in or the currently bound client.
        N)r   r
   r   r   r   r   _require_cliente   s    zProject._require_clientc                 C   s>   |  |}| j| j| jd}|jjdd|d}| j|d dS )a  API call:  create the project via a ``POST`` request.

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

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.
        )r   r   r   POSTz	/projectsmethodr   datar   N)r   r   r   r   
connectionapi_requestr   r
   r   r    respr   r   r   createt   s    

zProject.createc                 C   s,   |  |}|jjd| jd}| j|d dS )aG  API call:  reload the project via a ``GET`` request.

        This method will reload the newest metadata for the project. If you've
        created a new :class:`Project` instance via
        :meth:`Client.new_project()         <gcloud.resource_manager.client.Client.new_project>`,
        this method will retrieve project metadata.

        .. warning::

            This will overwrite any local changes you've made and not saved
            via :meth:`update`.

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

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.
        GETr   r   r!   N)r   r"   r#   r   r   )r
   r   r%   r   r   r   reload   s    
zProject.reloadc                 C   s>   |  |}z|jjd| jd W n ty4   Y dS 0 dS dS )a  API call:  test the existence of a project via a ``GET`` request.

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

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.

        :rtype: bool
        :returns: Boolean indicating existence of the project.
        r'   r(   FTN)r   r"   r#   r   r   r   r   r   r   exists   s    
zProject.existsc                 C   s:   |  |}| j| jd}|jjd| j|d}| | dS )a  API call:  update the project via a ``PUT`` request.

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

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.
        )r   r   PUTr   N)r   r   r   r"   r#   r   r   r$   r   r   r   update   s    
zProject.updateFc                 C   s,   |  |}|jjd| jd |r(|   dS )aF  API call:  delete the project via a ``DELETE`` request.

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

        This actually changes the status (``lifecycleState``) from ``ACTIVE``
        to ``DELETE_REQUESTED``.
        Later (it's not specified when), the project will move into the
        ``DELETE_IN_PROGRESS`` state, which means the deleting has actually
        begun.

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.

        :type reload_data: bool
        :param reload_data: Whether to reload the project with the latest
                            state. If you want to get the updated status,
                            you'll want this set to :data:`True` as the DELETE
                            method doesn't send back the updated project.
                            Default: :data:`False`.
        DELETEr(   Nr   r"   r#   r   r)   r
   r   Zreload_datar   r   r   delete   s    
zProject.deletec                 C   s0   |  |}|jjd| jd d |r,|   dS )a>  API call:  undelete the project via a ``POST`` request.

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

        This actually changes the project status (``lifecycleState``) from
        ``DELETE_REQUESTED`` to ``ACTIVE``.
        If the project has already reached a status of ``DELETE_IN_PROGRESS``,
        this request will fail and the project cannot be restored.

        :type client: :class:`gcloud.resource_manager.client.Client` or
                      :data:`NoneType <types.NoneType>`
        :param client: the client to use.  If not passed, falls back to
                       the client stored on the current project.

        :type reload_data: bool
        :param reload_data: Whether to reload the project with the latest
                            state. If you want to get the updated status,
                            you'll want this set to :data:`True` as the DELETE
                            method doesn't send back the updated project.
                            Default: :data:`False`.
        r   z	:undeleter(   Nr.   r/   r   r   r   undelete   s    
zProject.undelete)NN)N)N)N)N)NF)NF)__name__
__module____qualname____doc__r   r   classmethodr   r   propertyr   r   r   r&   r)   r*   r,   r0   r1   r   r   r   r   r      s"    








r   N)r5   Zgcloud.exceptionsr   objectr   r   r   r   r   <module>   s   