
    {#                     ~    d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	Zdd
Z G d de      Zy)z<Client for interaction with Gateway CRUD on API Gateway API.    )absolute_import)division)unicode_literalsN)
list_pager)apis)iam_utilc                 2    t        j                  d| |      S )N
apigateway)no_http)r   GetClientInstance)versionr   s     .lib/googlecloudsdk/api_lib/api_gateway/base.pyr   r      s    			gw	GG    c                 .    t        j                  d|       S )Nr
   )r   GetMessagesModule)r   s    r   r   r   "   s    			g	66r   c                   8    e Zd ZdZd	dZd Zd Zd
dZd Zd Z	y)
BaseClientzBase for building API Clients.Nc                 J   |xs
 t               | _        | j                  j                  | _        t	        | j                  |d       | _        t	        | j                  |dz   d       | _        t	        | j                  |dz   d       | _        t	        | j                  |dz   d       | _        t	        | j                  |dz   d       | _	        t	        | j                  |dz   d       | _
        t	        | j                  |dz   d       | _        t	        | j                  |dz   d       | _        y )N
GetRequestCreateRequestListRequestPatchRequestDeleteRequestGetIamPolicyRequestSetIamPolicyRequest)r   clientMESSAGES_MODULEmessagesgetattrserviceget_requestcreate_requestlist_requestpatch_requestdelete_requestget_iam_policy_requestset_iam_policy_request)selfr   message_baseservice_names       r   __init__zBaseClient.__init__)   s   /-/DKKK//DM4;;d;DL t}}l\.I4PD!$--"."@"&(D   ,} < $&D !!-!>!%'D "$--"."@"&(D
 #*$--*69N*N*.#0D #*$--*69N*N*.#0Dr   c                 L    d }t        | dt        j                  ||              y)z0Defines basic get function on an assigned class.c                 x    | j                  |j                               }| j                  j                  |      S )zGets an object.

      Args:
        self: The self of the class this is set on.
        object_ref: Resource, resource reference for object to get.

      Returns:
        The object requested.
      name)r!   RelativeNamer    Getr(   
object_refreqs      r   r1   z!BaseClient.DefineGet.<locals>.GetG   s5     *"9"9";<c\\c""r   r1   Nsetattrtypes
MethodType)r(   r1   s     r   	DefineGetzBaseClient.DefineGetE   s"    # D%))#t45r   c                 L    d }t        | dt        j                  ||              y)z3Defines basic delete function on an assigned class.c                 x    | j                  |j                               }| j                  j                  |      S )zDeletes a given object given an object name.

      Args:
        self: The self of the class this is set on.
        object_ref: Resource, resource reference for object to delete.

      Returns:
        Long running operation.
      r.   )r%   r0   r    Deleter2   s      r   r<   z'BaseClient.DefineDelete.<locals>.DeleteZ   s5     Z%<%<%>?c\\  %%r   r<   Nr5   )r(   r<   s     r   DefineDeletezBaseClient.DefineDeleteX   s"    & D(E,,VT:;r   c                 \    	 	 dfd	}t        | dt        j                  ||              y)a
  Defines the List functionality on the calling class.

    Args:
      field_name: The name of the field on the list response to list
      is_operations: Operations have a slightly altered message structure, set
                     to true in operations client
    Nc                     r| j                  ||      }n| j                  |||      }t        j                  | j                  ||d|      S )a  Lists the objects under a given parent.

      Args:
        self: the self object function will be bound to.
        parent_name: Resource name of the parent to list under.
        filters: Filters to be applied to results (optional).
        limit: Limit to the number of results per page (optional).
        page_size: the number of results per page (optional).
        sort_by: Instructions about how to sort the results (optional).

      Returns:
        List Pager.
      )filterr/   )r@   parentorderBypageSize)limitbatch_size_attribute
batch_sizefield)r#   r   YieldFromListr    )	r(   parent_namefiltersrD   	page_sizesort_byr4   
field_nameis_operationss	          r   Listz#BaseClient.DefineList.<locals>.Lists   sf     
w[A w{(/   1 %%
,,
) r   rO   )NNNNr5   )r(   rM   rN   rO   s    `` r   
DefineListzBaseClient.DefineListk   s-     EI> D&%**467r   c                 T    dfd	}t        | dt        j                  ||              y)zDefines the Update functionality on the calling class.

    Args:
      update_field_name: the field on the patch_request to assign updated object
                         to
    Nc                     | j                  |j                  |      }t        ||       | j                  j	                  |      S )a  Updates an object.

      Args:
        self: The self of the class this is set on.
        updating_object: Object which is being updated.
        update_mask: A string saying which fields have been updated.

      Returns:
        Long running operation.
      )r/   
updateMask)r$   r/   r6   r    Patch)r(   updating_objectupdate_maskr4   update_field_names       r   Updatez'BaseClient.DefineUpdate.<locals>.Update   sG     O$8$8*5  7cc$o6\\$$r   rX   Nr5   )r(   rW   rX   s    ` r   DefineUpdatezBaseClient.DefineUpdate   s#    %$ D(E,,VT:;r   c                 &   d }d
d}d }d }t        | dt        j                  ||              t        | dt        j                  ||              t        | dt        j                  ||              t        | d	t        j                  ||              y)z:Defines all of the IAM functionality on the calling class.c                 x    | j                  |j                               }| j                  j                  |      S )zGets an IAM Policy on an object.

      Args:
        self: The self of the class this is set on.
        object_ref: Resource, reference for object IAM policy belongs to.

      Returns:
        The IAM policy.
      )resource)r&   r0   r    GetIamPolicyr2   s      r   r^   z9BaseClient.DefineIamPolicyFunctions.<locals>.GetIamPolicy   s5     ''1H1H1J'Kc\\&&s++r   Nc                     | j                   j                  ||      }| j                  ||j                               }| j                  j                  |      S )a<  Sets an IAM Policy on an object.

      Args:
        self: The self of the class this is set on.
        object_ref: Resource, reference for object IAM policy belongs to.
        policy: the policy to be set.
        update_mask: fields being update on the IAM policy.

      Returns:
        The IAM policy.
      )policyrS   )apigatewaySetIamPolicyRequestr]   )r   ApigatewaySetIamPolicyRequestr'   r0   r    SetIamPolicy)r(   r3   r`   rV   policy_requestr4   s         r   rc   z9BaseClient.DefineIamPolicyFunctions.<locals>.SetIamPolicy   sa     }}BB  C "n ''(6**, ( .c \\&&s++r   c                     | j                  |      }t        j                  | j                  j                  |||       | j                  ||d      S )aR  Adds an IAM role to a member on an object.

      Args:
        self: The self of the class this is set on.
        object_ref: Resource, reference for object IAM policy belongs to.
        member: the member the binding is being added to.
        role: the role which to bind to the member.

      Returns:
        The IAM policy.
      bindings,etag)r^   r   AddBindingToIamPolicyr   ApigatewayBindingrc   r(   r3   memberroler`   s        r   AddIamPolicyBindingz@BaseClient.DefineIamPolicyFunctions.<locals>.AddIamPolicyBinding   sJ       ,f$$T]]%D%Df%+T3z6?CCr   c                 x    | j                  |      }t        j                  |||       | j                  ||d      S )aV  Adds an IAM role for a member on an object.

      Args:
        self: The self of the class this is set on
        object_ref: Resource, reference for object IAM policy belongs to
        member: the member the binding is removed for
        role: the role which is being removed from the member

      Returns:
        The IAM policy
      rf   )r^   r   RemoveBindingFromIamPolicyrc   ri   s        r   RemoveIamPolicyBindingzCBaseClient.DefineIamPolicyFunctions.<locals>.RemoveIamPolicyBinding   s;       ,f))&&$?z6?CCr   r^   rc   rl   ro   rY   r5   )r(   r^   rc   rl   ro   s        r   DefineIamPolicyFunctionsz#BaseClient.DefineIamPolicyFunctions   s    ,,(D"D" D.%"2"2<"FGD.%"2"2<"FGD')9)9:M:>*@ AD*E,<,<-& 'r   )NNN)F)
__name__
__module____qualname____doc__r+   r9   r=   rP   rZ   rp    r   r   r   r   &   s%    &086&<&'8R<6K'r   r   )v1F)rv   )rt   
__future__r   r   r   r7   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.iamr   r   r   objectr   ru   r   r   <module>r|      s9     C &  '  ' , 3H7T' T'r   