U
    $FZh(  ã                   @   s`   d Z ddlmZ ddlm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d
S )zµConfigure HMAC keys that can be used to authenticate requests to Google Cloud Storage.

See [HMAC keys documentation](https://cloud.google.com/storage/docs/authentication/hmackeys)
é    )ÚNotFound)Ú_rfc3339_nanos_to_datetime)Úcreate_trace_span)Ú_DEFAULT_TIMEOUT)ÚDEFAULT_RETRY)ÚDEFAULT_RETRY_IF_ETAG_IN_JSONc                   @   sü   e Zd ZdZdZdZdZeefZd)dd„Zdd	„ Z	d
d„ Z
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZeefd!d"„Zeefd#d$„Zeefd%d&„Zeefd'd(„ZdS )*ÚHMACKeyMetadataa   Metadata about an HMAC service account key withn Cloud Storage.

    :type client: :class:`~google.cloud.stoage.client.Client`
    :param client: client associated with the key metadata.

    :type access_id: str
    :param access_id: (Optional) Unique ID of an existing key.

    :type project_id: str
    :param project_id: (Optional) Project ID of an existing key.
        Defaults to client's project.

    :type user_project: str
    :param user_project: (Optional) This parameter is currently ignored.
    ZACTIVEZINACTIVEZDELETEDNc                 C   s:   || _ i | _|d k	r|| jd< |d k	r0|| jd< || _d S )NÚaccessIdÚ	projectId)Ú_clientÚ_propertiesÚ_user_project)ÚselfÚclientÚ	access_idZ
project_idÚuser_project© r   úd/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/google/cloud/storage/hmac_key.pyÚ__init__:   s    

zHMACKeyMetadata.__init__c                 C   s(   t || jƒstS | j|jko&| j|jkS ©N)Ú
isinstanceÚ	__class__ÚNotImplementedr   r   )r   Úotherr   r   r   Ú__eq__F   s    zHMACKeyMetadata.__eq__c                 C   s   t | jƒt | jƒ S r   )Úhashr   r   ©r   r   r   r   Ú__hash__L   s    zHMACKeyMetadata.__hash__c                 C   s   | j  d¡S )z|Access ID of the key.

        :rtype: str or None
        :returns: unique identifier of the key within a project.
        r	   ©r   Úgetr   r   r   r   r   O   s    zHMACKeyMetadata.access_idc                 C   s   | j  d¡S )z•ETag identifying the version of the key metadata.

        :rtype: str or None
        :returns: ETag for the version of the key's metadata.
        Úetagr   r   r   r   r   r    X   s    zHMACKeyMetadata.etagc                 C   s   | j  d¡S )zID of the key, including the Project ID and the Access ID.

        :rtype: str or None
        :returns: ID of the key.
        Úidr   r   r   r   r   r!   a   s    zHMACKeyMetadata.idc                 C   s   | j  d¡S )zzProject ID associated with the key.

        :rtype: str or None
        :returns: project identfier for the key.
        r
   r   r   r   r   r   Úprojectj   s    zHMACKeyMetadata.projectc                 C   s   | j  d¡S )z­Service account e-mail address associated with the key.

        :rtype: str or None
        :returns: e-mail address for the service account which created the key.
        ZserviceAccountEmailr   r   r   r   r   Úservice_account_emails   s    z%HMACKeyMetadata.service_account_emailc                 C   s   | j  d¡S )zÂGet / set key's state.

        One of:
            - ``ACTIVE``
            - ``INACTIVE``
            - ``DELETED``

        :rtype: str or None
        :returns: key's current state.
        Ústater   r   r   r   r   r$   |   s    zHMACKeyMetadata.statec                 C   s   || j d< d S )Nr$   )r   ©r   Úvaluer   r   r   r$   Š   s    c                 C   s    | j  d¡}|dk	rt|ƒS dS )á3  Retrieve the timestamp at which the HMAC key was created.

        :rtype: :class:`datetime.datetime` or ``NoneType``
        :returns: Datetime object parsed from RFC3339 valid timestamp, or
                  ``None`` if the bucket's resource has not been loaded
                  from the server.
        ZtimeCreatedN©r   r   r   r%   r   r   r   Útime_createdŽ   s    	zHMACKeyMetadata.time_createdc                 C   s    | j  d¡}|dk	rt|ƒS dS )r'   ÚupdatedNr(   r%   r   r   r   r*   ›   s    	zHMACKeyMetadata.updatedc                 C   s:   | j dkrtdƒ‚| j}|dkr(| jj}d|› d| j › S )z%Resource path for the metadata's key.NzNo 'access_id' set.z
/projects/z
/hmacKeys/)r   Ú
ValueErrorr"   r   )r   r"   r   r   r   Úpath¨   s    
zHMACKeyMetadata.pathc                 C   s   | j S )z—Project ID to be billed for API requests made via this bucket.

        This property is currently ignored by the server.

        :rtype: str
        )r   r   r   r   r   r   µ   s    zHMACKeyMetadata.user_projectc              	   C   s|   t ddh z2i }| jdk	r&| j|d< | jj| j|||d W n  tk
r^   Y W 5 Q R £ dS X W 5 Q R £ dS W 5 Q R X dS )a#  Determine whether or not the key for this metadata exists.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`

        :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`

        :rtype: bool
        :returns: True if the key exists in Cloud Storage.
        zStorage.HmacKey.exists©ÚnameNÚuserProject©Zquery_paramsÚtimeoutÚretryFT)r   r   r   Ú_get_resourcer,   r   ©r   r1   r2   Ú	qs_paramsr   r   r   Úexists¿   s    

ü
zHMACKeyMetadata.existsc              	   C   sJ   t dd6 i }| jdk	r$| j|d< | jj| j|||d| _W 5 Q R X dS )a4  Reload properties from Cloud Storage.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`

        :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`

        :raises :class:`~google.api_core.exceptions.NotFound`:
            if the key does not exist on the back-end.
        zStorage.HmacKey.reloadr-   Nr/   r0   )r   r   r   r3   r,   r   r4   r   r   r   Úreloadà   s    

üzHMACKeyMetadata.reloadc              	   C   sV   t ddB i }| jdk	r$| j|d< d| ji}| jj| j||||d| _W 5 Q R X dS )a9  Save writable properties to Cloud Storage.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`

        :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`

        :raises :class:`~google.api_core.exceptions.NotFound`:
            if the key does not exist on the back-end.
        zStorage.HmacKey.updater-   Nr/   r$   r0   )r   r   r$   r   Z_put_resourcer,   r   )r   r1   r2   r5   Úpayloadr   r   r   Úupdateü   s    


ûzHMACKeyMetadata.updatec              	   C   sH   t dd4 i }| jdk	r$| j|d< | jj| j|||d W 5 Q R X dS )a1  Delete the key from Cloud Storage.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`

        :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`

        :raises :class:`~google.api_core.exceptions.NotFound`:
            if the key does not exist on the back-end.
        zStorage.HmacKey.deleter-   Nr/   r0   )r   r   r   Z_delete_resourcer,   r4   r   r   r   Údelete  s    

üzHMACKeyMetadata.delete)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZACTIVE_STATEZINACTIVE_STATEZDELETED_STATEZ_SETTABLE_STATESr   r   r   Úpropertyr   r    r!   r"   r#   r$   Úsetterr)   r*   r,   r   r   r   r6   r7   r   r9   r:   r   r   r   r   r      sD   











	!r   N)r>   Zgoogle.cloud.exceptionsr   Zgoogle.cloud._helpersr   Z+google.cloud.storage._opentelemetry_tracingr   Zgoogle.cloud.storage.constantsr   Zgoogle.cloud.storage.retryr   r   Úobjectr   r   r   r   r   Ú<module>   s   