
    3                         S r SSKrSSKrSSKrSSKrSr Sr Sr SrSr	 " S S	\
5      r " S
 S\R                  R                  5      rg)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                       \ rS rSrSrSrg)InvalidOperationExceptionM   z1Raised when trying to use Policy class as a dict. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       &lib/third_party/google/api_core/iam.pyr   r   M   s    ;r   r   c                      \ rS rSrSr\4r \4r \	4r
 SS jrS rS rS rS rS	 rS
 rS r\S 5       r\R*                  S 5       r\S 5       r\R*                  S 5       r\S 5       r\R*                  S 5       r\S 5       r\R*                  S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\ S 5       r!S r"Sr#g)PolicyS   a  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                 *    Xl         X l        / U l        g N)etagversion	_bindings)selfr   r   s      r   __init__Policy.__init__r   s    	r   c                 H    U R                  5         S U R                   5       $ )Nc              3   B   #    U  H  oS    (       d  M  US   v   M     g7f)membersroleNr   ).0bindings     r   	<genexpr>"Policy.__iter__.<locals>.<genexpr>z   s     T~GAS~s   )__check_version__r   r   s    r   __iter__Policy.__iter__w   s     Tt~~TTr   c                 f    U R                  5         [        [        U R                  5       5      5      $ r   )r"   lenlistr$   r#   s    r   __len__Policy.__len__|   s$     4())r   c                     U R                  5         U R                   H  nUS   U:X  d  M  US   s  $    U[        5       S.nU R                  R                  U5        US   $ Nr   r   r   r   )r"   r   setappend)r   keybnew_bindings       r   __getitem__Policy.__getitem__   s]     AyC|#    #su5k*9%%r   c                     U R                  5         [        U5      nU R                   H  nUS   U:X  d  M  X#S'     g    U R                  R                  XS.5        g r,   )r"   r.   r   r/   )r   r0   valuer   s       r   __setitem__Policy.__setitem__   sS     E
~~Gv#%%*	" & 	s=>r   c                     U R                  5         U R                   H)  nUS   U:X  d  M  U R                  R                  U5          g    [        U5      e)Nr   )r"   r   removeKeyError)r   r0   r1   s      r   __delitem__Policy.__delitem__   sI     AyC%%a(   smr   c                     U R                   SL=(       a    U R                   S:  nU(       d  U R                  5       (       a  [        [        5      eg)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"   Policy.__check_version__   s@    D0ET\\A5ED5577+,<== 8r   c                 R    U R                    H  nUR                  S5      c  M    g   g)N	conditionTF)r   get)r   r1   s     r   r@   Policy._contains_conditions   s'    Auu[!-   r   c                     U R                   $ )a=  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   bindingsPolicy.bindings   s    d ~~r   c                     Xl         g r   rI   )r   rJ   s     r   rJ   rK      s    !r   c                     [        5       nU R                   H-  nU R                  US5       H  nUR                  U5        M     M/     [	        U5      $ )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_ROLESrF   add	frozensetr   resultr   members       r   ownersPolicy.owners   sI     %%D((4,

6" - &   r   c                 z    [         R                  " [        R                  S[        5      [
        5        X[        '   g)zUpdate owners.

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

DEPRECATED:  use `policy.bindings` to access bindings instead.
rT   N)warningswarn_ASSIGNMENT_DEPRECATED_MSGformat
OWNER_ROLEDeprecationWarningr   r6   s     r   rT   rU      s-     	&--h
CEW	
 !Zr   c                     [        5       nU R                   H-  nU R                  US5       H  nUR                  U5        M     M/     [	        U5      $ )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_ROLESrF   rO   rP   rQ   s       r   editorsPolicy.editors   I     &&D((4,

6" - '   r   c                 z    [         R                  " [        R                  S[        5      [
        5        X[        '   g)zUpdate editors.

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

DEPRECATED:  use `policy.bindings` to modify bindings instead.
r`   N)rW   rX   rY   rZ   EDITOR_ROLEr\   r]   s     r   r`   ra     -     	&--iE	
 "[r   c                     [        5       nU R                   H-  nU R                  US5       H  nUR                  U5        M     M/     [	        U5      $ )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_ROLESrF   rO   rP   rQ   s       r   viewersPolicy.viewers  rb   r   c                 z    [         R                  " [        R                  S[        5      [
        5        X[        '   g)zUpdate viewers.

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

DEPRECATED:  use `policy.bindings` to modify bindings instead.
rh   N)rW   rX   rY   rZ   VIEWER_ROLEr\   r]   s     r   rh   ri   (  re   r   c                     SU < 3$ )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   userPolicy.user6  s     "##r   c                     SU < 3$ )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   rm   s    r   service_accountPolicy.service_accountB  s     ',--r   c                     SU < 3$ )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   rm   s    r   groupPolicy.groupO  s     #$$r   c                     SU < 3$ )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   rx   Policy.domain[  s     %&&r   c                      g)zoFactory method for a member representing all users.

Returns:
    str: A member string representing all users.
allUsersr   r   r   r   	all_usersPolicy.all_usersg  s     r   c                      g)zFactory method for a member representing all authenticated users.

Returns:
    str: A member string representing all authenticated users.
allAuthenticatedUsersr   r   r   r   authenticated_usersPolicy.authenticated_usersp  s     'r   c                     UR                  S5      nUR                  S5      nU " X25      nUR                  S/ 5      Ul        UR                   H!  n[        UR                  SS5      5      US'   M#     U$ )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   rJ   r   r   )rF   rJ   r.   )clsresourcer   r   policyr   s         r   from_api_reprPolicy.from_api_repry  sk     ,,y)||F#T#",,z26G!$W[[B%?!@GI ' r   c                    0 nU R                   b  U R                   US'   U R                  b  U R                  US'   U R                  (       a  [        U R                  5      S:  a  / nU R                   H[  nUR	                  S5      nU(       d  M  US   [        U5      S.nUR	                  S5      nU(       a  XeS'   UR                  U5        M]     U(       a"  [        R                  " S5      n[        X'S9US	'   U$ )
zhRender a JSON policy resource.

Returns:
    dict: a resource to be passed to the ``setIamPolicy`` API.
r   r   r   r   r   r-   rE   )r0   rJ   )	r   r   r   r'   rF   sortedr/   operator
itemgetter)r   r   rJ   r   r   r2   rE   r0   s           r   to_api_reprPolicy.to_api_repr  s     99 #yyHV<<#"&,,HY>>c$..1A5H>>!++i07+26?vg"WK 'K 8I 3<K0OOK0 * ))&1'-h'@$r   )r   r   r   )NN)$r   r   r	   r
   r   r[   rN   rd   r_   rk   rg   r   r$   r)   r3   r7   r<   r"   r@   propertyrJ   setterrT   r`   rh   staticmethodro   rr   ru   rx   r|   r   classmethodr   r   r   r   r   r   r   r   S   s   * =L5 NM6 NM6
U
*

&?> 1 1f __" " ! ! ]]
! 
! ! ! ^^" " ! ! ^^" " 	$ 	$ 
. 
. 	% 	% 	' 	'   ' '  &r   r   )r   collectionscollections.abcr   rW   r[   rd   rk   rY   rA   	Exceptionr   abcMutableMappingr   r   r   r   <module>r      si   &P     
 4 7 7c [ 		 	X[__++ Xr   