
                             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 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j"                        Zd Z G d de      Zy)z$Utilities for Eventarc Channels API.    )absolute_import)division)unicode_literals)
list_pager)common)common_publishing)EventarcClientBase)apis)
exceptions)	resourcesc                       e Zd ZdZy)NoFieldsSpecifiedErrorz:Error when no fields were specified for a Patch operation.N)__name__
__module____qualname____doc__     /lib/googlecloudsdk/api_lib/eventarc/channels.pyr   r      s    Br   r   c                 x    t         j                  j                  | j                  d      }|j	                         S )Nz$eventarc.projects.locations.channels)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcechannelss     r   GetChannelURIr   "   s7    11mm F 2 H(				r   c                   Z     e Zd ZdZ fdZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )ChannelClientV1z@Channel Client for interaction with v1 of Eventarc Channels API.c                    t         t        |   t        j                  t        j
                  d       t        j                  t        j                  t        j
                        }|j                  | _	        |j                  | _        t        j                  t        j                  t        j
                        }|j                  | _        |j                  | _        y )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$   z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                     | j                   j                  |j                         j                         ||j	                         |      }| j
                  j                  |      S )aA  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:   zChannelClientV1.Create<   s\     NN!!#002""$	 O J
 ==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes the specified Channel.

    Args:
      channel_ref: Resource, the Channel to delete.

    Returns:
      A long-running operation for delete.
    r   )r)   .EventarcProjectsLocationsChannelsDeleteRequestr8   r+   Delete)r.   r;   
delete_reqs      r   rB   zChannelClientV1.DeleteO   s?     NN%%' O )J==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets the requested Channel.

    Args:
      channel_ref: Resource, the Channel to get.

    Returns:
      The Channel message.
    r@   )r)   +EventarcProjectsLocationsChannelsGetRequestr8   r+   Get)r.   r;   get_reqs      r   rF   zChannelClientV1.Get\   s?     nnHH%%' I )G==W%%r   c                     | j                   j                  |j                         |      }t        j                  | j
                  |d||d      S )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.
    )r3   pageSizer   rI   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r)   ,EventarcProjectsLocationsChannelsListRequestr8   r   YieldFromListr+   )r.   location_refrM   	page_sizelist_reqs        r   ListzChannelClientV1.Listi   sV     ~~JJ((*Y K @H##') )r   c                     | j                   j                  |j                         ||      }| j                  j	                  |      S )aM  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)   -EventarcProjectsLocationsChannelsPatchRequestr8   r+   Patch)r.   r;   r<   update_mask	patch_reqs        r   rY   zChannelClientV1.Patch   sG     LL%%' M  I ==y))r   c                 2   t        j                  | j                  j                  j                  |      }| j                  j                  |g      }| j                  j                  |j                         |      }| j                  j                  |       y)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?EventarcpublishingProjectsLocationsChannelsPublishEventsRequestr8   r-   PublishEvents)r.   r;   cloud_eventevents_value_list_entrypublish_events_requestpublish_reqs         r   PublishzChannelClientV1.Publish   s     0LL!!	<	<		{,
 "66jj'( k *++kk((*<R l K 	**;7r   c                     | j                   j                  |j                         ||||      S |j                         |      S )N)r   cryptoKeyNameproviderlabels)r)   Channelr8   )r.   r;   provider_refcrypto_key_namerl   s        r   BuildChannelzChannelClientV1.BuildChannel   s[    >>!!%%'%  " 
 
 &2%>%>%@ " 
 
r   c                     g }|r|j                  d       |r|j                  d       |r|j                  d       |st        d      dj                  |      S )aa  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.
    rj   rl   z*Must specify at least one field to update.,)appendr   join)r.   
crypto_keyclear_crypto_keyrl   rZ   s        r   BuildUpdateMaskzChannelClientV1.BuildUpdateMask   sZ     K))""#OPP88K  r   c                 B    | j                   j                  j                  S )N)r)   rm   LabelsValue)r.   s    r   LabelsValueClszChannelClientV1.LabelsValueCls   s    >>!!---r   )F)r   r   r   r   r$   r:   rB   rF   rU   rY   rh   rp   rw   rz   __classcell__)r1   s   @r   r    r    (   s9    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   