
                             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	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.    )absolute_import)division)unicode_literals)
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)r2   channel_refchannel_messagedry_run
create_reqs        r   r?   ChannelClientV1.Create<   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)r2   r@   
delete_reqs      r   rH   ChannelClientV1.DeleteO   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.
rF   )r-   +EventarcProjectsLocationsChannelsGetRequestr=   r/   Get)r2   r@   get_reqs      r   rM   ChannelClientV1.Get\   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.
)r8   pageSizer    rQ   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r-   ,EventarcProjectsLocationsChannelsListRequestr=   r   YieldFromListr/   )r2   location_refrU   	page_sizelist_reqs        r   ListChannelClientV1.Listi   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)r2   r@   rA   update_mask	patch_reqs        r   rb   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   TransformEventsForPublishingr0   3GoogleCloudEventarcPublishingV1PublishEventsRequestEventsValueListEntry?EventarcpublishingProjectsLocationsChannelsPublishEventsRequestr=   r1   PublishEvents)r2   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=   )r2   r@   provider_refcrypto_key_namerw   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.
ru   rw   z*Must specify at least one field to update.,)appendr   join)r2   
crypto_keyclear_crypto_keyrw   rc   s        r   BuildUpdateMaskChannelClientV1.BuildUpdateMask   sZ     K))""#OPP88K  r   c                 B    U R                   R                  R                  $ )N)r-   rx   LabelsValue)r2   s    r   LabelsValueClsChannelClientV1.LabelsValueCls   s    >>!!---r   )r-   r0   r1   r/   )F)r   r   r   r   r   r(   r?   rH   rM   r]   rb   rr   r{   r   r   r   __classcell__)r5   s   @r   r#   r#   (   s>    HM",&,&),*$80
!4. .r   r#   N)r   
__future__r   r   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      sP    + &  ' ' 2 = C , * )CZ-- Ce.( e.r   