
    j	i3                         d Z ddlZddlZddlZddlZdZ	 dZ	 dZ	 dZdZ	 G d d	e
          Z G d
 dej        j                  ZdS )a6  Non-API-specific IAM policy definitions

For allowed roles / permissions, see:
https://cloud.google.com/iam/docs/understanding-roles

Example usage:

.. code-block:: python

   # ``get_iam_policy`` returns a :class:'~google.api_core.iam.Policy`.
   policy = resource.get_iam_policy(requested_policy_version=3)

   phred = "user:phred@example.com"
   admin_group = "group:admins@groups.example.com"
   account = "serviceAccount:account-1234@accounts.example.com"

   policy.version = 3
   policy.bindings = [
       {
           "role": "roles/owner",
           "members": {phred, admin_group, account}
       },
       {
           "role": "roles/editor",
           "members": {"allAuthenticatedUsers"}
       },
       {
           "role": "roles/viewer",
           "members": {"allUsers"}
           "condition": {
               "title": "request_time",
               "description": "Requests made before 2021-01-01T00:00:00Z",
               "expression": "request.time < timestamp("2021-01-01T00:00:00Z")"
           }
       }
   ]

   resource.set_iam_policy(policy)
    Nzroles/ownerzroles/editorzroles/viewerz_Assigning to '{}' is deprecated. Use the `policy.bindings` property to modify bindings instead.zWDict access is not supported on policies with version > 1 or with conditional bindings.c                       e Zd ZdZdS )InvalidOperationExceptionz1Raised when trying to use Policy class as a dict.N)__name__
__module____qualname____doc__     K/srv/django_bis/venv311/lib/python3.11/site-packages/google/api_core/iam.pyr   r   M   s        ;;Dr
   r   c                      e Zd ZdZefZ	 efZ	 efZ		 ddZ
d Zd Zd Zd Zd Zd	 Zd
 Zed             Zej        d             Zed             Zej        d             Zed             Zej        d             Zed             Zej        d             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Z d Z!dS )Policya1  IAM Policy

    Args:
        etag (Optional[str]): ETag used to identify a unique of the policy
        version (Optional[int]): The syntax schema version of the policy.

    Note:
        Using conditions in bindings requires the policy's version to be set
        to `3` or greater, depending on the versions that are currently supported.

        Accessing the policy using dict operations will raise InvalidOperationException
        when the policy's version is set to 3.

        Use the policy.bindings getter/setter to retrieve and modify the policy's bindings.

    See:
        IAM Policy https://cloud.google.com/iam/reference/rest/v1/Policy
        Policy versions https://cloud.google.com/iam/docs/policies#versions
        Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
    Nc                 0    || _         || _        g | _        d S N)etagversion	_bindings)selfr   r   s      r   __init__zPolicy.__init__r   s    	r
   c                 L    |                                   d | j        D             S )Nc              3   6   K   | ]}|d          
|d         V  dS )membersroleNr	   ).0bindings     r   	<genexpr>z"Policy.__iter__.<locals>.<genexpr>z   s0      TTGASTTTTTTTr
   )__check_version__r   r   s    r   __iter__zPolicy.__iter__w   s*       TTt~TTTTr
   c                     |                                   t          t          |                                                     S r   )r   lenlistr   r   s    r   __len__zPolicy.__len__|   s2       4(()))r
   c                     |                                   | j        D ]}|d         |k    r
|d         c S |t                      d}| j                            |           |d         S Nr   r   r   r   )r   r   setappend)r   keybnew_bindings       r   __getitem__zPolicy.__getitem__   s}        	$ 	$AyC|###  
  #suu55k***9%%r
   c                     |                                   t          |          }| j        D ]}|d         |k    r||d<    d S | j                            ||d           d S r$   )r   r&   r   r'   )r   r(   valuer   s       r   __setitem__zPolicy.__setitem__   s{       E

~ 	 	Gv#%%%*	" & 	su==>>>>>r
   c                     |                                   | j        D ]+}|d         |k    r| j                            |            d S ,t          |          )Nr   )r   r   removeKeyError)r   r(   r)   s      r   __delitem__zPolicy.__delitem__   sd        	 	AyC%%a(((   smmr
   c                     | j         duo
| j         dk    }|s|                                 rt          t                    dS )z[Raise InvalidOperationException if version is greater than 1 or policy contains conditions.N   )r   _contains_conditionsr   _DICT_ACCESS_MSG)r   raise_versions     r   r   zPolicy.__check_version__   sN    D0ET\A5E 	>D5577 	>+,<===	> 	>r
   c                 J    | j         D ]}|                    d           dS dS )N	conditionTF)r   get)r   r)   s     r   r5   zPolicy._contains_conditions   s6     	 	Auu[!!-tt .ur
   c                     | j         S )aE  The policy's list of bindings.

        A binding is specified by a dictionary with keys:

        * role (str): Role that is assigned to `members`.

        * members (:obj:`set` of str): Specifies the identities associated to this binding.

        * condition (:obj:`dict` of str:str): Specifies a condition under which this binding will apply.

          * title (str): Title for the condition.

          * description (:obj:str, optional): Description of the condition.

          * expression: A CEL expression.

        Type:
           :obj:`list` of :obj:`dict`

        See:
           Policy versions https://cloud.google.com/iam/docs/policies#versions
           Conditions overview https://cloud.google.com/iam/docs/conditions-overview.

        Example:

        .. code-block:: python

           USER = "user:phred@example.com"
           ADMIN_GROUP = "group:admins@groups.example.com"
           SERVICE_ACCOUNT = "serviceAccount:account-1234@accounts.example.com"
           CONDITION = {
               "title": "request_time",
               "description": "Requests made before 2021-01-01T00:00:00Z", # Optional
               "expression": "request.time < timestamp("2021-01-01T00:00:00Z")"
           }

           # Set policy's version to 3 before setting bindings containing conditions.
           policy.version = 3

           policy.bindings = [
               {
                   "role": "roles/viewer",
                   "members": {USER, ADMIN_GROUP, SERVICE_ACCOUNT},
                   "condition": CONDITION
               },
               ...
           ]
        r   r   s    r   bindingszPolicy.bindings   s    d ~r
   c                     || _         d S r   r<   )r   r=   s     r   r=   zPolicy.bindings   s    !r
   c                     t                      }| j        D ]0}|                     |d          D ]}|                    |           1t	          |          S )zLegacy access to owner role.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to access bindings instead.
        r	   )r&   _OWNER_ROLESr:   add	frozensetr   resultr   members       r   ownerszPolicy.owners   sd     % 	# 	#D((4,, # #

6""""#   r
   c                     t          j        t                              dt                    t
                     || t          <   dS )zUpdate owners.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to access bindings instead.
        rF   N)warningswarn_ASSIGNMENT_DEPRECATED_MSGformat
OWNER_ROLEDeprecationWarningr   r-   s     r   rF   zPolicy.owners   s@     	&--h
CCEW	
 	
 	
 !Zr
   c                     t                      }| j        D ]0}|                     |d          D ]}|                    |           1t	          |          S )zLegacy access to editor role.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to access bindings instead.
        r	   )r&   _EDITOR_ROLESr:   rA   rB   rC   s       r   editorszPolicy.editors   d     & 	# 	#D((4,, # #

6""""#   r
   c                     t          j        t                              dt                    t
                     || t          <   dS )zUpdate editors.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to modify bindings instead.
        rQ   N)rH   rI   rJ   rK   EDITOR_ROLErM   rN   s     r   rQ   zPolicy.editors  @     	&--iEE	
 	
 	
 "[r
   c                     t                      }| j        D ]0}|                     |d          D ]}|                    |           1t	          |          S )zLegacy access to viewer role.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to modify bindings instead.
        r	   )r&   _VIEWER_ROLESr:   rA   rB   rC   s       r   viewerszPolicy.viewers  rR   r
   c                     t          j        t                              dt                    t
                     || t          <   dS )zUpdate viewers.

        Raise InvalidOperationException if version is greater than 1 or policy contains conditions.

        DEPRECATED:  use `policy.bindings` to modify bindings instead.
        rX   N)rH   rI   rJ   rK   VIEWER_ROLErM   rN   s     r   rX   zPolicy.viewers(  rU   r
   c                     d| S )zFactory method for a user member.

        Args:
            email (str): E-mail for this particular user.

        Returns:
            str: A member string corresponding to the given user.
        zuser:r	   emails    r   userzPolicy.user6  s      "E##r
   c                     d| S )zFactory method for a service account member.

        Args:
            email (str): E-mail for this particular service account.

        Returns:
            str: A member string corresponding to the given service account.

        zserviceAccount:r	   r\   s    r   service_accountzPolicy.service_accountB  s      ',e--r
   c                     d| S )zFactory method for a group member.

        Args:
            email (str): An id or e-mail for this particular group.

        Returns:
            str: A member string corresponding to the given group.
        zgroup:r	   r\   s    r   groupzPolicy.groupO  s      #U$$r
   c                     d| S )zFactory method for a domain member.

        Args:
            domain (str): The domain for this member.

        Returns:
            str: A member string corresponding to the given domain.
        zdomain:r	   )domains    r   rd   zPolicy.domain[  s      %f&&r
   c                      dS )zFactory method for a member representing all users.

        Returns:
            str: A member string representing all users.
        allUsersr	   r	   r
   r   	all_userszPolicy.all_usersg  s	     zr
   c                      dS )zFactory method for a member representing all authenticated users.

        Returns:
            str: A member string representing all authenticated users.
        allAuthenticatedUsersr	   r	   r
   r   authenticated_userszPolicy.authenticated_usersp  s
     '&r
   c                    |                     d          }|                     d          } | ||          }|                     dg           |_        |j        D ](}t          |                     dd                    |d<   )|S )zFactory: create a policy from a JSON resource.

        Args:
            resource (dict): policy resource returned by ``getIamPolicy`` API.

        Returns:
            :class:`Policy`: the parsed policy
        r   r   r=   r   r	   )r:   r=   r&   )clsresourcer   r   policyr   s         r   from_api_reprzPolicy.from_api_repry  s     ,,y))||F##T7##",,z266 	A 	AG!$W[[B%?%?!@!@GIr
   c                    i }| j         
| j         |d<   | j        
| j        |d<   | j        rt          | j                  dk    rg }| j        D ]b}|                    d          }|rI|d         t          |          d}|                    d          }|r||d<   |                    |           c|r(t          j        d          }t          ||	          |d
<   |S )zRender a JSON policy resource.

        Returns:
            dict: a resource to be passed to the ``setIamPolicy`` API.
        Nr   r   r   r   r   r%   r9   )r(   r=   )	r   r   r   r    r:   sortedr'   operator
itemgetter)r   rm   r=   r   r   r*   r9   r(   s           r   to_api_reprzPolicy.to_api_repr  s    9 #yHV<#"&,HY> 	Ac$.11A55H> 1 1!++i00 1+26?vg"W"WK 'K 8 8I  =3<K0OOK000 A)&11'-hC'@'@'@$r
   )NN)"r   r   r   r   rL   r@   rT   rP   rZ   rW   r   r   r"   r+   r.   r2   r   r5   propertyr=   setterrF   rQ   rX   staticmethodr^   r`   rb   rd   rg   rj   classmethodro   rt   r	   r
   r   r   r   S   sk        * =L5 NM6 NM6   
U U U
* * *

& 
& 
&? ? ?  > > >   1 1 X1f _" " _" ! ! X! ]
! 
! ]
! ! ! X! ^" " ^" ! ! X! ^" " ^" 	$ 	$ \	$ 
. 
. \
. 	% 	% \	% 	' 	' \	'   \ ' ' \'   [&    r
   r   )r   collectionscollections.abcrr   rH   rL   rT   rZ   rJ   r6   	Exceptionr   abcMutableMappingr   r	   r
   r   <module>r~      s   & &P           
 4 7 7c [ 	 	 	 	 		 	 	 	X X X X X[_+ X X X X Xr
   