
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSK
Jr   " S	 S
\R                  5      rS r " S S\5      rg)z$Utilities for Eventarc Channels API.    )
list_pager)common)common_publishing)EventarcClientBase)apis)
exceptions)	resourcesc                       \ rS rSrSrSrg)NoFieldsSpecifiedError   z:Error when no fields were specified for a Patch operation. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       /lib/googlecloudsdk/api_lib/eventarc/channels.pyr   r      s    Br   r   c                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )Nz$eventarc.projects.locations.channels)
collection)r	   REGISTRYParseRelativeNamenameSelfLink)resourcechannelss     r   GetChannelURIr      s7    11mm F 2 H(				r   c                   f   ^  \ rS rSrSrU 4S jrSS jrS rS rS r	S r
S	 rS
 rS rS rSrU =r$ )ChannelClientV1%   z@Channel Client for interaction with v1 of Eventarc Channels API.c                   > [         [        U ]  [        R                  [        R
                  S5        [        R                  " [        R                  [        R
                  5      nUR                  U l	        UR                  U l        [        R                  " [        R                  [        R
                  5      nUR                  U l        UR                  U l        g )Nchannel)superr    __init__r   API_NAMEAPI_VERSION_1r   GetClientInstanceMESSAGES_MODULE	_messagesprojects_locations_channels_servicer   _publishing_messages_publishing_service)selfclientpublishing_client	__class__s      r   r%   ChannelClientV1.__init__(   s    	/4)&//6;O;O*35 ##FOOV5I5IJF++DN66DM ../@/I/I/@/N/NP !2 A AD0LLDr   c                     U R                   R                  UR                  5       R                  5       UUR	                  5       US9nU R
                  R                  U5      $ )a!  Creates a new Channel.

Args:
  channel_ref: Resource, the Channel to create.
  channel_message: Channel, the channel message that holds channel's name,
    provider, etc.
  dry_run: If set, the changes will not be commited, only validated

Returns:
  A long-running operation for create.
)parentr#   	channelIdvalidateOnly)r*   .EventarcProjectsLocationsChannelsCreateRequestParentRelativeNameNamer,   Create)r/   channel_refchannel_messagedry_run
create_reqs        r   r<   ChannelClientV1.Create9   s\     NN!!#002""$	 O J
 ==
++r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zDeletes the specified Channel.

Args:
  channel_ref: Resource, the Channel to delete.

Returns:
  A long-running operation for delete.
r   )r*   .EventarcProjectsLocationsChannelsDeleteRequestr:   r,   Delete)r/   r=   
delete_reqs      r   rE   ChannelClientV1.DeleteL   s?     NN%%' O )J==
++r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zqGets the requested Channel.

Args:
  channel_ref: Resource, the Channel to get.

Returns:
  The Channel message.
rC   )r*   +EventarcProjectsLocationsChannelsGetRequestr:   r,   Get)r/   r=   get_reqs      r   rJ   ChannelClientV1.GetY   s?     nnHH%%' I )G==W%%r   c           	          U R                   R                  UR                  5       US9n[        R                  " U R
                  USUUSS9$ )aJ  List available channels in location.

Args:
  location_ref: Resource, the location to list Channels in.
  limit: int or None, the total number of results to return.
  page_size: int, the number of entries in each batch (affects requests
    made, but not the yielded results).

Returns:
  A generator of Channels in the location.
)r5   pageSizer   rN   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r*   ,EventarcProjectsLocationsChannelsListRequestr:   r   YieldFromListr,   )r/   location_refrR   	page_sizelist_reqs        r   ListChannelClientV1.Listf   sV     ~~JJ((*Y K @H##') )r   c                     U R                   R                  UR                  5       UUS9nU R                  R	                  U5      $ )a-  Updates the specified Channel.

Args:
  channel_ref: Resource, the Channel to update.
  channel_message: Channel, the channel message that holds channel's name,
    provider, etc.
  update_mask: str, a comma-separated list of Channel fields to update.

Returns:
  A long-running operation for update.
)r   r#   
updateMask)r*   -EventarcProjectsLocationsChannelsPatchRequestr:   r,   Patch)r/   r=   r>   update_mask	patch_reqs        r   r_   ChannelClientV1.Patch|   sG     LL%%' M  I ==y))r   c                 (   [         R                  " U R                  R                  R                  U5      nU R                  R                  U/S9nU R                  R                  UR                  5       US9nU R                  R                  U5        g)zPublish to a Channel.

Args:
  channel_ref: Resource, the channel to publish to.
  cloud_event: A CloudEvent representation to be passed as the request body.
)events)r#   3googleCloudEventarcPublishingV1PublishEventsRequestN)	r   TransformEventsForPublishingr-   3GoogleCloudEventarcPublishingV1PublishEventsRequestEventsValueListEntry?EventarcpublishingProjectsLocationsChannelsPublishEventsRequestr:   r.   PublishEvents)r/   r=   cloud_eventevents_value_list_entrypublish_events_requestpublish_reqs         r   PublishChannelClientV1.Publish   s     0LL!!	<	<		{,
 "66jj'( k *++kk((*<R l K 	**;7r   c                     U R                   R                  UR                  5       UUc  UUS9$ UR                  5       US9$ )N)r   cryptoKeyNameproviderlabels)r*   Channelr:   )r/   r=   provider_refcrypto_key_namert   s        r   BuildChannelChannelClientV1.BuildChannel   s[    >>!!%%'%  " 
 
 &2%>%>%@ " 
 
r   c                     / nU(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U(       d  [        S5      eSR                  U5      $ )a=  Builds an update mask for updating a channel.

Args:
  crypto_key: bool, whether to update the crypto key.
  clear_crypto_key: bool, whether to clear the crypto key.
  labels: bool, whether to update the labels.

Returns:
  The update mask as a string.

Raises:
  NoFieldsSpecifiedError: No fields are being updated.
rr   rt   z*Must specify at least one field to update.,)appendr   join)r/   
crypto_keyclear_crypto_keyrt   r`   s        r   BuildUpdateMaskChannelClientV1.BuildUpdateMask   sZ     K))""#OPP88K  r   c                 B    U R                   R                  R                  $ )N)r*   ru   LabelsValue)r/   s    r   LabelsValueClsChannelClientV1.LabelsValueCls   s    >>!!---r   )r*   r-   r.   r,   )F)r   r   r   r   r   r%   r<   rE   rJ   rZ   r_   ro   rx   r   r   r   __classcell__)r2   s   @r   r    r    %   s>    HM",&,&),*$80
!4. .r   r    N)r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   $googlecloudsdk.api_lib.eventarc.baser   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r	   Errorr   r   r    r   r   r   <module>r      sI    + ( 2 = C , * )CZ-- Ce.( e.r   