
    g3                         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y)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y)InvalidOperationExceptionz1Raised when trying to use Policy class as a dict.N)__name__
__module____qualname____doc__     P/var/www/django_project/virt/lib/python3.12/site-packages/google/api_core/iam.pyr   r   M   s    ;r
   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!y)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                 .    || _         || _        g | _        y N)etagversion	_bindings)selfr   r   s      r   __init__zPolicy.__init__r   s    	r
   c                 H    | j                          d | j                  D        S )Nc              3   2   K   | ]  }|d    s	|d     yw)membersroleNr	   ).0bindings     r   	<genexpr>z"Policy.__iter__.<locals>.<genexpr>z   s     TGASTs   

)__check_version__r   r   s    r   __iter__zPolicy.__iter__w   s     Tt~~TTr
   c                 f    | j                          t        t        | j                                     S r   )r   lenlistr   r   s    r   __len__zPolicy.__len__|   s$     4())r
   c                     | j                          | j                  D ]  }|d   |k(  s|d   c S  |t               d}| j                  j                  |       |d   S Nr   r   r   r   )r   r   setappend)r   keybnew_bindings       r   __getitem__zPolicy.__getitem__   sb      	$AyC|#	$  #su5k*9%%r
   c                     | j                          t        |      }| j                  D ]  }|d   |k(  s||d<    y  | j                  j                  ||d       y r$   )r   r&   r   r'   )r   r(   valuer   s       r   __setitem__zPolicy.__setitem__   s\     E
~~ 	Gv#%%*	"	 	su=>r
   c                     | j                          | j                  D ]'  }|d   |k(  s| j                  j                  |        y  t        |      )Nr   )r   r   removeKeyError)r   r(   r)   s      r   __delitem__zPolicy.__delitem__   sN      	AyC%%a(	 smr
   c                     | j                   duxr | j                   dkD  }|s| j                         rt        t              y)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__   s=    D0ET\\A5ED557+,<== 8r
   c                 L    | j                   D ]  }|j                  d       y y)N	conditionTF)r   get)r   r)   s     r   r5   zPolicy._contains_conditions   s,     	Auu[!-	 r
   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                     || _         y r   r<   )r   r=   s     r   r=   zPolicy.bindings   s	    !r
   c                     t               }| j                  D ]*  }| j                  |d      D ]  }|j                  |        , t	        |      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   sS     %% 	#D((4, #

6"#	#   r
   c                 z    t        j                  t        j                  dt              t
               || t        <   y)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
CEW	
 !Zr
   c                     t               }| j                  D ]*  }| j                  |d      D ]  }|j                  |        , t	        |      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   S     && 	#D((4, #

6"#	#   r
   c                 z    t        j                  t        j                  dt              t
               || t        <   y)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	
 "[r
   c                     t               }| j                  D ]*  }| j                  |d      D ]  }|j                  |        , t	        |      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                 z    t        j                  t        j                  dt              t
               || t        <   y)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     "##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     ',--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     #$$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     %&&r
   c                       y)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     r
   c                       y)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                     |j                  d      }|j                  d      } | ||      }|j                  dg       |_        |j                  D ]   }t        |j                  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  st     ,,y)||F#T7#",,z26 	AG!$W[[B%?!@GI	A r
   c                    i }| j                   | j                   |d<   | j                  | j                  |d<   | j                  rt        | j                        dkD  rg }| j                  D ]P  }|j	                  d      }|s|d   t        |      d}|j	                  d      }|r||d<   |j                  |       R |r%t        j                  d      }t        ||      |d	<   |S )
zRender a JSON policy resource.

        Returns:
            dict: a resource to be passed to the ``setIamPolicy`` API.
        r   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     99 #yyHV<<#"&,,HY>>c$..1A5H>> 1!++i0+26?vg"WK 'K 8I 3<K0OOK0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   s   * =L5 NM6 NM6
U
*

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