
                             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 Z G d de      Zy)z/Utilities for Eventarc channel connections API.    )absolute_import)division)unicode_literals)
list_pager)common)common_publishing)EventarcClientBase)apis)	resourcesc                 x    t         j                  j                  | j                  d      }|j	                         S )Nz.eventarc.projects.locations.channelConnections)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcechannel_connectionss     :lib/googlecloudsdk/api_lib/eventarc/channel_connections.pyGetChannelConnectionsURIr      s:    !**<<mmA = C 
	%	%	''    c                   F     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
 xZS )	ChannelConnectionClientV1z/Channel connections client for Eventarc API V1.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 )NzChannel Connection)superr   __init__r   API_NAMEAPI_VERSION_1r
   GetClientInstanceMESSAGES_MODULE	_messages%projects_locations_channelConnections_servicer   _publishing_messages_publishing_service)selfclientpublishing_client	__class__s      r   r   z"ChannelConnectionClientV1.__init__'   s    	
#
&*>*>-/ ##FOOV5I5IJF++DN@@DM ../@/I/I/@/N/NP 1 A AD0VVDr   c                     | j                   j                  |j                         j                         ||j	                               }| j
                  j                  |      S )aH  Creates a new Channel Connection.

    Args:
      channel_connection_ref: Resource, the Channel connection to create.
      channel_connection_message: Channel connection, the channel connection
        message that holds channel's reference, activation token, etc.

    Returns:
      A long-running operation for create.
    )parentchannelConnectionchannelConnectionId)r    8EventarcProjectsLocationsChannelConnectionsCreateRequestParentRelativeNameNamer"   Create)r%   channel_connection_refchannel_connection_message
create_reqs       r   r1   z ChannelConnectionClientV1.Create7   sY     XX%,,.;;=42779 Y ;J ==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes the specified Channel Connection.

    Args:
      channel_connection_ref: Resource, the Channel Connection to delete.

    Returns:
      A long-running operation for delete.
    r   )r    8EventarcProjectsLocationsChannelConnectionsDeleteRequestr/   r"   Delete)r%   r2   
delete_reqs      r   r8   z ChannelConnectionClientV1.DeleteH   s?     XX#002 Y 4J==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets the requested Channel Connection.

    Args:
      channel_connection_ref: Resource, the Channel Connection to get.

    Returns:
      The Channel Connection message.
    r6   )r    5EventarcProjectsLocationsChannelConnectionsGetRequestr/   r"   Get)r%   r2   get_reqs      r   r<   zChannelConnectionClientV1.GetU   s?     nnRR#002 S 4G==W%%r   c                     | j                   j                  |j                         |      }t        j                  | j
                  |d||d      S )a  List available channel connections in location.

    Args:
      location_ref: Resource, the location to list Channel Connections 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 Channel Connections in the location.
    )r*   pageSizechannelConnectionsr?   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r    6EventarcProjectsLocationsChannelConnectionsListRequestr/   r   YieldFromListr"   )r%   location_refrD   	page_sizelist_reqs        r   ListzChannelConnectionClientV1.Listb   sV     ~~TT((*Y U @H##"') )r   c                 2   t        j                  | j                  j                  j                  |      }| j                  j                  |g      }| j                  j                  |j                         |      }| j                  j                  |       y)zPublish to a Channel Conenction.

    Args:
      channel_connection_ref: Resource, the channel connection to publish from.
      cloud_event: A CloudEvent representation to be passed as the request body.
    )events)r+   DgoogleCloudEventarcPublishingV1PublishChannelConnectionEventsRequestN)	r   TransformEventsForPublishingr#   DGoogleCloudEventarcPublishingV1PublishChannelConnectionEventsRequestEventsValueListEntryIEventarcpublishingProjectsLocationsChannelConnectionsPublishEventsRequestr/   r$   PublishEvents)r%   r2   cloud_eventevents_value_list_entrypublish_events_requestpublish_reqs         r   Publishz!ChannelConnectionClientV1.Publishx   s     0LL!!	M	M		{,
 "66{{'( |  ++uu0==?Mc v K
 	**;7r   c           
      \   d }|v| j                   j                  j                  |j                         D cg c]6  \  }}| j                   j                  j                  j	                  ||      8 c}}      }| j                   j                  |j                         |||      S c c}}w )N)keyvalue)additionalProperties)r   channelactivationTokenlabels)r    ChannelConnectionLabelsValueitemsAdditionalPropertyr/   )r%   r2   r^   activation_tokenr`   channel_connection_labelsr[   r\   s           r   BuildChannelConnectionz0ChannelConnectionClientV1.BuildChannelConnection   s     $"&.."B"B"N"N !' 
 !/*#u	 nn..::MM N  !/  #O # >>++#002((	 , 
 
 s   ;B(
)__name__
__module____qualname____doc__r   r1   r8   r<   rL   rY   rg   __classcell__)r(   s   @r   r   r   $   s*    7W ,",&),80
r   r   N)rk   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   $googlecloudsdk.api_lib.eventarc.baser	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.corer   r   r    r   r   <module>rt      s9    6 &  ' ' 2 = C , )(~
 2 ~
r   