
    
                     Z    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  G d de	      Z
y	)
z%API helpers for interacting with IAM.    )absolute_import)division)unicode_literals)apis)iam_utilc                   0    e Zd ZdZddZd Zd Zd Zd Zy)	Clientz"A client for interacting with IAM.Nc                 l    t        j                  |      | _        t        j                  |      | _        y N)r   GetClientInstanceclientGetMessagesModulemessages)selfapi_versions     4lib/googlecloudsdk/api_lib/container/binauthz/iam.py__init__zClient.__init__   s&    ((5DK**;7DM    c                     | j                   j                  j                  | j                  j	                  |j                         t        j                              S )z.Gets the IamPolicy associated with a resource.)resourceoptions_requestedPolicyVersion)r   projects_policyGetIamPolicyr   4BinaryauthorizationProjectsPolicyGetIamPolicyRequestRelativeNamer   !MAX_LIBRARY_IAM_SUPPORTED_VERSION)r   any_refs     r   Getz
Client.Get    sL    ;;&&33JJ))++3.. 	K 	01 1r   c                     t         j                  |_        | j                  j                  j                  | j                  j                  |j                         | j                  j                  |                  S )a=  Sets a resource's IamPolicy to the one provided.

    If 'policy' has no etag specified, this will BLINDLY OVERWRITE the IAM
    policy!

    Args:
        any_ref: A resources.Resource naming the resource.
        policy: A protorpc.Message instance of an IamPolicy object.

    Returns:
        The IAM Policy.
    )policy)r   setIamPolicyRequest)
r   r   versionr   r   SetIamPolicyr   4BinaryauthorizationProjectsPolicySetIamPolicyRequestr   SetIamPolicyRequest)r   r   r    s      r   Setz
Client.Set(   sm     ??FN;;&&33JJ))+ $ A A !B !  	K 	
 r   c                     | j                  |      }t        j                  | j                  j                  |||       | j                  ||      S )z@Does an atomic Read-Modify-Write, adding the member to the role.)r   r   AddBindingToIamPolicyr   Bindingr&   r   r   memberroler    s        r   
AddBindingzClient.AddBinding=   s?    XXgF""4==#8#8&&$O88GV$$r   c                 v    | j                  |      }t        j                  |||       | j                  ||      S )zDDoes an atomic Read-Modify-Write, removing the member from the role.)r   r   RemoveBindingFromIamPolicyr&   r*   s        r   RemoveBindingzClient.RemoveBindingC   s3    XXgF''=88GV$$r   r   )	__name__
__module____qualname____doc__r   r   r&   r-   r0    r   r   r	   r	      s    *81*%%r   r	   N)r4   
__future__r   r   r   )googlecloudsdk.api_lib.container.binauthzr   googlecloudsdk.command_lib.iamr   objectr	   r5   r   r   <module>r:      s%    , &  ' : 3.%V .%r   