o
    tBhV                     @   sp   d Z ddlmZ ddlmZ G dd deZG dd deZG dd	 d	eZG d
d deZ	G dd deZ
dS )aI	  Manipulate access control lists that Cloud Storage provides.

:class:`google.cloud.storage.bucket.Bucket` has a getting method that creates
an ACL object under the hood, and you can interact with that using
:func:`google.cloud.storage.bucket.Bucket.acl`:

.. literalinclude:: snippets.py
    :start-after: [START client_bucket_acl]
    :end-before: [END client_bucket_acl]
    :dedent: 4


Adding and removing permissions can be done with the following methods
(in increasing order of granularity):

- :func:`ACL.all`
  corresponds to access for all users.
- :func:`ACL.all_authenticated` corresponds
  to access for all users that are signed into a Google account.
- :func:`ACL.domain` corresponds to access on a
  per Google Apps domain (ie, ``example.com``).
- :func:`ACL.group` corresponds to access on a
  per group basis (either by ID or e-mail address).
- :func:`ACL.user` corresponds to access on a
  per user basis (either by ID or e-mail address).

And you are able to ``grant`` and ``revoke`` the following roles:

- **Reading**:
  :func:`_ACLEntity.grant_read` and :func:`_ACLEntity.revoke_read`
- **Writing**:
  :func:`_ACLEntity.grant_write` and :func:`_ACLEntity.revoke_write`
- **Owning**:
  :func:`_ACLEntity.grant_owner` and :func:`_ACLEntity.revoke_owner`

You can use any of these like any other factory method (these happen to
be :class:`_ACLEntity` factories):

.. literalinclude:: snippets.py
   :start-after: [START acl_user_settings]
   :end-before: [END acl_user_settings]
   :dedent: 4

After that, you can save any changes you make with the
:func:`google.cloud.storage.acl.ACL.save` method:

.. literalinclude:: snippets.py
   :start-after: [START acl_save]
   :end-before: [END acl_save]
   :dedent: 4

You can alternatively save any existing :class:`google.cloud.storage.acl.ACL`
object (whether it was created by a factory method or not) from a
:class:`google.cloud.storage.bucket.Bucket`:

.. literalinclude:: snippets.py
   :start-after: [START acl_save_bucket]
   :end-before: [END acl_save_bucket]
   :dedent: 4

To get the list of ``entity`` and ``role`` for each unique pair, the
:class:`ACL` class is iterable:

.. literalinclude:: snippets.py
   :start-after: [START acl_print]
   :end-before: [END acl_print]
   :dedent: 4

This list of tuples can be used as the ``entity`` and ``role`` fields
when sending metadata for ACLs to the API.
    )_DEFAULT_TIMEOUT)DEFAULT_RETRYc                   @   s~   e Zd ZdZdZdZdZdddZdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )
_ACLEntitya  Class representing a set of roles for an entity.

    This is a helper class that you likely won't ever construct
    outside of using the factor methods on the :class:`ACL` object.

    :type entity_type: str
    :param entity_type: The type of entity (ie, 'group' or 'user').

    :type identifier: str
    :param identifier: (Optional) The ID or e-mail of the entity. For the special
                       entity types (like 'allUsers').
    READERWRITEROWNERNc                 C   s   || _ tg | _|| _d S N)
identifiersetrolestype)selfentity_typer	    r   o/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/google/cloud/storage/acl.py__init__m   s   

z_ACLEntity.__init__c                 C   s   | j st| jS dj| dS )Nz{acl.type}-{acl.identifier})acl)r	   strr   formatr   r   r   r   __str__r   s   
z_ACLEntity.__str__c                 C   s   dj | d| jdS )Nz<ACL Entity: {acl} ({roles})>z, )r   r   )r   joinr   r   r   r   r   __repr__x   s   z_ACLEntity.__repr__c                 C   s   | j S )zGet the list of roles permitted by this entity.

        :rtype: list of strings
        :returns: The list of roles associated with this entity.
        )r   r   r   r   r   	get_roles}   s   z_ACLEntity.get_rolesc                 C   s   | j | dS )zoAdd a role to the entity.

        :type role: str
        :param role: The role to add to the entity.
        N)r   addr   roler   r   r   grant   s   z_ACLEntity.grantc                 C   s   || j v r| j | dS dS )zyRemove a role from the entity.

        :type role: str
        :param role: The role to remove from the entity.
        N)r   remover   r   r   r   revoke   s   
z_ACLEntity.revokec                 C      |  tj dS )z(Grant read access to the current entity.N)r   r   READER_ROLEr   r   r   r   
grant_read      z_ACLEntity.grant_readc                 C   r    )z)Grant write access to the current entity.N)r   r   WRITER_ROLEr   r   r   r   grant_write   r#   z_ACLEntity.grant_writec                 C   r    )z)Grant owner access to the current entity.N)r   r   
OWNER_ROLEr   r   r   r   grant_owner   r#   z_ACLEntity.grant_ownerc                 C   r    )z+Revoke read access from the current entity.N)r   r   r!   r   r   r   r   revoke_read   r#   z_ACLEntity.revoke_readc                 C   r    )z,Revoke write access from the current entity.N)r   r   r$   r   r   r   r   revoke_write   r#   z_ACLEntity.revoke_writec                 C   r    )z,Revoke owner access from the current entity.N)r   r   r&   r   r   r   r   revoke_owner   r#   z_ACLEntity.revoke_ownerr   )__name__
__module____qualname____doc__r!   r$   r&   r   r   r   r   r   r   r"   r%   r'   r(   r)   r*   r   r   r   r   r   [   s"    
	r   c                   @   s4  e Zd ZdZdZdZdddddd	d
Zeg dZ	 dZ	dZ
dZdZdZdd ZefddZedd Zdd Zdd Zdd Zdd Zd<ddZdd Zd<d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Ze d.d/ Z
d0d1 Z!dee"fd2d3Z#efd4d5Z$ddefd6d7Z%defd8d9Z&defd:d;Z'dS )=ACLz7Container class representing a list of access controls.r   predefinedAclprojectPrivate
publicReadpublicReadWriteauthenticatedReadbucketOwnerReadbucketOwnerFullControl)zproject-privatezpublic-readzpublic-read-writezauthenticated-readzbucket-owner-readzbucket-owner-full-control)privater1   r2   r3   r4   r5   r6   FNc                 C   s
   i | _ d S r   )entitiesr   r   r   r   r      s   
zACL.__init__c                 C   s   | j s| j|d dS dS )zLoad if not already loaded.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`
        timeoutN)loadedreload)r   r:   r   r   r   _ensure_loaded   s   zACL._ensure_loadedc                 C   s.   | j ||}|r|| jvrtd|f |S )a:  Ensures predefined is in list of predefined json values

        :type predefined: str
        :param predefined: name of a predefined acl

        :type predefined: str
        :param predefined: validated JSON name of predefined acl

        :raises: :exc: `ValueError`: If predefined is not a valid acl
        zInvalid predefined ACL: %s)PREDEFINED_XML_ACLSgetPREDEFINED_JSON_ACLS
ValueError)cls
predefinedr   r   r   validate_predefined   s   zACL.validate_predefinedc                 C   s   | j   d| _dS )z@Remove all entities from the ACL, and clear the ``loaded`` flag.FN)r8   clearr;   r   r   r   r   reset   s   

z	ACL.resetc                 c   s@    |    | j D ]}| D ]}|rt||dV  qq
d S )N)entityr   )r=   r8   valuesr   r   )r   rG   r   r   r   r   __iter__   s   zACL.__iter__c                 C   s~   |d }|d }|dkr|   }n|dkr|  }nd|v r-|dd\}}| j||d}t|ts8td| || |S )	a  Build an _ACLEntity object from a dictionary of data.

        An entity is a mutable object that represents a list of roles
        belonging to either a user or group or the special types for all
        users and all authenticated users.

        :type entity_dict: dict
        :param entity_dict: Dictionary full of data from an ACL lookup.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity constructed from the dictionary.
        rG   r   allUsersallAuthenticatedUsers-   r   r	   zInvalid dictionary: %s)allall_authenticatedsplitrG   
isinstancer   rA   r   )r   entity_dictrG   r   r   r	   r   r   r   entity_from_dict  s   



zACL.entity_from_dictc                 C   s   |    t|| jv S )a  Returns whether or not this ACL has any entries for an entity.

        :type entity: :class:`_ACLEntity`
        :param entity: The entity to check for existence in this ACL.

        :rtype: bool
        :returns: True of the entity exists in the ACL.
        )r=   r   r8   r   rG   r   r   r   
has_entity#  s   	zACL.has_entityc                 C   s   |    | jt||S )a  Gets an entity object from the ACL.

        :type entity: :class:`_ACLEntity` or string
        :param entity: The entity to get lookup in the ACL.

        :type default: anything
        :param default: This value will be returned if the entity
                        doesn't exist.

        :rtype: :class:`_ACLEntity`
        :returns: The corresponding entity or the value provided
                  to ``default``.
        )r=   r8   r?   r   )r   rG   defaultr   r   r   
get_entity/  s   zACL.get_entityc                 C   s   |    || jt|< dS )zAdd an entity to the ACL.

        :type entity: :class:`_ACLEntity`
        :param entity: The entity to add to this ACL.
        N)r=   r8   r   rU   r   r   r   
add_entity@  s   zACL.add_entityc                 C   s2   t ||d}| |r| |}|S | | |S )a  Factory method for creating an Entity.

        If an entity with the same type and identifier already exists,
        this will return a reference to that entity.  If not, it will
        create a new one and add it to the list of known entities for
        this ACL.

        :type entity_type: str
        :param entity_type: The type of entity to create
                            (ie, ``user``, ``group``, etc)

        :type identifier: str
        :param identifier: The ID of the entity (if applicable).
                           This can be either an ID or an e-mail address.

        :rtype: :class:`_ACLEntity`
        :returns: A new Entity or a reference to an existing identical entity.
        rN   )r   rV   rX   rY   )r   r   r	   rG   r   r   r   rG   I  s   


z
ACL.entityc                 C      | j d|dS )zFactory method for a user Entity.

        :type identifier: str
        :param identifier: An id or e-mail for this particular user.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity corresponding to this user.
        userr	   rG   r   r	   r   r   r   r[   c     	zACL.userc                 C   rZ   )zFactory method for a group Entity.

        :type identifier: str
        :param identifier: An id or e-mail for this particular group.

        :rtype: :class:`_ACLEntity`
        :returns: An Entity corresponding to this group.
        groupr\   r]   r^   r   r   r   r`   n  r_   z	ACL.groupc                 C   rZ   )zFactory method for a domain Entity.

        :type domain: str
        :param domain: The domain for this entity.

        :rtype: :class:`_ACLEntity`
        :returns: An entity corresponding to this domain.
        domainr\   r]   )r   ra   r   r   r   ra   y  r_   z
ACL.domainc                 C   
   |  dS )zFactory method for an Entity representing all users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all users.
        rJ   r]   r   r   r   r   rO        
zACL.allc                 C   rb   )zFactory method for an Entity representing all authenticated users.

        :rtype: :class:`_ACLEntity`
        :returns: An entity representing all authenticated users.
        rK   r]   r   r   r   r   rP     rc   zACL.all_authenticatedc                 C   s   |    t| j S )zGet a list of all Entity objects.

        :rtype: list of :class:`_ACLEntity` objects
        :returns: A list of all Entity objects.
        )r=   listr8   rH   r   r   r   r   get_entities  s   zACL.get_entitiesc                 C   s   t )z&Abstract getter for the object client.)NotImplementedErrorr   r   r   r   client  s   z
ACL.clientc                 C   s   |du r| j }|S )a  Check client or verify over-ride.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current ACL.

        :rtype: :class:`google.cloud.storage.client.Client`
        :returns: The client passed in or the currently bound client.
        N)rg   )r   rg   r   r   r   _require_client  s   zACL._require_clientc                 C   sp   | j }| |}i }| jdur| j|d< | j  |j||||d}d| _|ddD ]
}| | 	| q+dS )a  Reload the ACL data from Cloud Storage.

        If :attr:`user_project` is set, bills the API request to that project.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.
        :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: :class:`~google.api_core.retry.Retry`
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`
        NuserProjectquery_paramsr:   retryTitemsr   )
reload_pathrh   user_projectr8   rE   _get_resourcer;   r?   rY   rT   )r   rg   r:   rl   pathrk   foundentryr   r   r   r<     s   



z
ACL.reloadc           	      C   s   |  |}ddi}|durg }||| j< | jdur| j|d< | j}|j|| jt|i||dd}| j  |	| jdD ]
}| 
| | q<d| _dS )a#  Helper for :meth:`save` and :meth:`save_predefined`.

        :type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
        :param acl: The ACL object to save.  If left blank, this will save
                    current entries.

        :type predefined: str
        :param predefined: An identifier for a predefined ACL.  Must be one of the
            keys in :attr:`PREDEFINED_JSON_ACLS` If passed, `acl` must be None.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :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: :class:`~google.api_core.retry.Retry`
        :param retry:
            (Optional) How to retry the RPC. See: :ref:`configuring_retries`
        
projectionfullNri   rj   r   T)rh   _PREDEFINED_QUERY_PARAMro   	save_path_patch_resource_URL_PATH_ELEMrd   r8   rE   r?   rY   rT   r;   )	r   r   rC   rg   r:   rk   rq   resultrs   r   r   r   _save  s&   





z	ACL._savec                 C   s6   |du r
| }|j }nd}|r| j|d||d dS dS )a  Save this ACL for the current bucket.

        If :attr:`user_project` is set, bills the API request to that project.

        :type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
        :param acl: The ACL object to save.  If left blank, this will save
                    current entries.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`
        NTr9   )r;   r{   )r   r   rg   r:   save_to_backendr   r   r   save  s   zACL.savec                 C   s    |  |}| jd|||d dS )a  Save this ACL for the current bucket using a predefined ACL.

        If :attr:`user_project` is set, bills the API request to that project.

        :type predefined: str
        :param predefined: An identifier for a predefined ACL.  Must be one
                           of the keys in :attr:`PREDEFINED_JSON_ACLS`
                           or :attr:`PREDEFINED_XML_ACLS` (which will be
                           aliased to the corresponding JSON name).
                           If passed, `acl` must be None.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`
        Nr9   )rD   r{   )r   rC   rg   r:   r   r   r   save_predefined$  s   
zACL.save_predefinedc                 C   s   | j g ||d dS )a+  Remove all ACL entries.

        If :attr:`user_project` is set, bills the API request to that project.

        Note that this won't actually remove *ALL* the rules, but it
        will remove all the non-default rules.  In short, you'll still
        have access to a bucket that you created even after you clear
        ACL rules with this method.

        :type client: :class:`~google.cloud.storage.client.Client` or
                      ``NoneType``
        :param client: (Optional) The client to use.  If not passed, falls back
                       to the ``client`` stored on the ACL's parent.

        :type timeout: float or tuple
        :param timeout:
            (Optional) The amount of time, in seconds, to wait
            for the server response.  See: :ref:`configuring_timeouts`
        )rg   r:   N)r}   )r   rg   r:   r   r   r   rE   =  s   z	ACL.clearr   )(r+   r,   r-   r.   ry   rv   r>   	frozensetr@   r;   rg   rn   rw   ro   r   r   r=   classmethodrD   rF   rI   rT   rV   rX   rY   rG   r[   r`   ra   rO   rP   re   propertyrh   r   r<   r{   r}   r~   rE   r   r   r   r   r/      sZ    

 

		
#4r/   c                       P   e Zd ZdZ fddZedd Zedd Zedd	 Zed
d Z	  Z
S )	BucketACLzAn ACL specifically for a bucket.

    :type bucket: :class:`google.cloud.storage.bucket.Bucket`
    :param bucket: The bucket to which this ACL relates.
    c                       t t|   || _d S r   )superr   r   bucket)r   r   	__class__r   r   r   [     
zBucketACL.__init__c                 C      | j jS )z&The client bound to this ACL's bucket.)r   rg   r   r   r   r   rg   _     zBucketACL.clientc                 C   s   d| j j| jf S )3Compute the path for GET API requests for this ACL.z%s/%s)r   rq   ry   r   r   r   r   rn   d  s   zBucketACL.reload_pathc                 C   r   z5Compute the path for PATCH API requests for this ACL.)r   rq   r   r   r   r   rw   i  r   zBucketACL.save_pathc                 C   r   z?Compute the user project charged for API requests for this ACL.)r   ro   r   r   r   r   ro   n  r   zBucketACL.user_projectr+   r,   r-   r.   r   r   rg   rn   rw   ro   __classcell__r   r   r   r   r   T      


r   c                   @   s   e Zd ZdZdZdZdS )DefaultObjectACLz9A class representing the default object ACL for a bucket.defaultObjectAclpredefinedDefaultObjectAclN)r+   r,   r-   r.   ry   rv   r   r   r   r   r   t  s    r   c                       r   )	ObjectACLzAn ACL specifically for a Cloud Storage object / blob.

    :type blob: :class:`google.cloud.storage.blob.Blob`
    :param blob: The blob that this ACL corresponds to.
    c                    r   r   )r   r   r   blob)r   r   r   r   r   r     r   zObjectACL.__init__c                 C   r   )z$The client bound to this ACL's blob.)r   rg   r   r   r   r   rg     r   zObjectACL.clientc                 C   s   d| j j S )r   z%s/aclr   rq   r   r   r   r   rn     s   zObjectACL.reload_pathc                 C   r   r   r   r   r   r   r   rw     r   zObjectACL.save_pathc                 C   r   r   )r   ro   r   r   r   r   ro     r   zObjectACL.user_projectr   r   r   r   r   r   {  r   r   N)r.   google.cloud.storage.constantsr   google.cloud.storage.retryr   objectr   r/   r   r   r   r   r   r   r   <module>   s   HT   ( 