
    &                         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j&                        Zy)z(Utilities for Eventarc MessageBuses API.    )absolute_import)division)unicode_literals)
list_pager)base)common)common_publishing)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__     4lib/googlecloudsdk/api_lib/eventarc/message_buses.pyr   r      s    Br   r   c                 x    t         j                  j                  | j                  d      }|j	                         S )Nz(eventarc.projects.locations.messageBuses)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcemessage_busess     r   GetMessageBusURIr   "   s8    $$66mm J 7 - 
			!!r   c                   |     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d Zd Zd Zed        Z xZS )MessageBusClientV1zGMessageBus Client for interaction with v1 of Eventarc MessageBuses 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 )Nzmessage bus)superr    __init__r   API_NAMEAPI_VERSION_1r
   GetClientInstanceMESSAGES_MODULE	_messagesprojects_locations_messageBuses_servicer	   _publishing_messages_publishing_service)selfclientpublishing_client	__class__s      r   r#   zMessageBusClientV1.__init__,   s    	
d,--}
 ##FOOV5I5IJF++DN::DM ..""$5$C$C !2 A AD0PPDr   c                     | j                   j                  |j                         j                         ||j	                         |      }| j
                  j                  |      S )a_  Creates a new MessageBus.

    Args:
      message_bus_ref: Resource, the MessageBus to create.
      message_bus_message: MessageBus, the messageBus message that holds
        messageBus' name, crypto key name, etc.
      dry_run: If set, the changes will not be committed, only validated

    Returns:
      A long-running operation for create.
    )parent
messageBusmessageBusIdvalidateOnly)r(   2EventarcProjectsLocationsMessageBusesCreateRequestParentRelativeNameNamer*   Create)r-   message_bus_refmessage_bus_messagedry_run
create_reqs        r   r:   zMessageBusClientV1.Create?   s_     	II"))+88:*(--/ 	 	J 	
  ==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets the requested MessageBus.

    Args:
      message_bus_ref: Resource, the MessageBus to get.

    Returns:
      The MessageBus message.
    r   )r(   /EventarcProjectsLocationsMessageBusesGetRequestr8   r*   Get)r-   r;   get_reqs      r   rB   zMessageBusClientV1.GetU   sA     nnLL))+ M G ==W%%r   c                     | j                   j                  |j                         |      }t        j                  | j
                  |d||d      S )av  List available messageBuses in location.

    Args:
      location_ref: Resource, the location to list MessageBuses 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 MessageBuses in the location.
    r2   pageSizemessageBusesrF   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r(   0EventarcProjectsLocationsMessageBusesListRequestr8   r   YieldFromListr*   )r-   location_refrK   	page_sizelist_reqs        r   ListzMessageBusClientV1.Listc   sW     ~~NN((*Y O H ##' r   c                     | j                   j                  |j                         ||      }| j                  j	                  |      S )am  Updates the specified MessageBus.

    Args:
      message_bus_ref: Resource, the MessageBus to update.
      message_bus_message: MessageBus, the messageBus message that holds
        messageBus' name, crypto key name, etc.
      update_mask: str, a comma-separated list of MessageBus fields to update.

    Returns:
      A long-running operation for update.
    )r   r3   
updateMask)r(   1EventarcProjectsLocationsMessageBusesPatchRequestr8   r*   Patch)r-   r;   r<   update_mask	patch_reqs        r   rW   zMessageBusClientV1.Patch{   sJ     	HH --/*" 	I 	
  ==y))r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes the specified MessageBus.

    Args:
      message_bus_ref: Resource, the MessageBus to delete.

    Returns:
      A long-running operation for delete.
    r@   )r(   2EventarcProjectsLocationsMessageBusesDeleteRequestr8   r*   Delete)r-   r;   
delete_reqs      r   r\   zMessageBusClientV1.Delete   sD     	II --/ 	J 	
 
 ==
++r   c	                     | j                   j                  |j                         | j                   j                  | j	                  |||||      ||            }	| j
                  j                  |	       y)a  Publish a Cloud Event to a MessageBus.

    Args:
      message_bus_ref: Resource, the message bus to publish to.
      json_message: str, the json string to publish.
      avro_message: byte, the avro payload to publish.
      event_id: str, the id of the event.
      event_type: str, the type of the event.
      event_source: str, the source of the event.
      event_data: str, the data of the event.
      event_attributes: dict, the attributes of the event.
    )protoMessageavroMessagejsonMessage)r3   -googleCloudEventarcPublishingV1PublishRequestN)r+   =EventarcpublishingProjectsLocationsMessageBusesPublishRequestr8   -GoogleCloudEventarcPublishingV1PublishRequest_BuildCloudEventProtoMessager,   Publish)
r-   r;   json_messageavro_messageevent_id
event_typeevent_source
event_dataevent_attributespublish_reqs
             r   rf   zMessageBusClientV1.Publish   s~    0 ++ii"//16:6O6O6}6}::*lJ@P %$ 7~ 7
 j 	K 	$$[1r   c           	          | j                   j                  |j                         |      }t        j                  | j
                  d|d||d      S )z@List available enrollments attached to the specified messageBus.rE   ListEnrollmentsenrollmentsrF   )rH   methodrI   rJ   rK   rL   rM   )r(   ;EventarcProjectsLocationsMessageBusesListEnrollmentsRequestr8   r   rO   r*   )r-   r;   rK   rQ   rR   s        r   rp   z"MessageBusClientV1.ListEnrollments   sX    ~~YY++-	 Z H ## ' r   c                     d }|?| j                   j                  | j                   j                  j                  |            }| j                   j                  |j	                         |||      S )N)logSeverity)r   loggingConfigcryptoKeyNamelabels)r(   LoggingConfigLogSeverityValueValuesEnum
MessageBusr8   )r-   r;   logging_configcrypto_key_namerx   logging_config_enums         r   BuildMessageBusz"MessageBusClientV1.BuildMessageBus   sx     ! NN88nn22MM 9 
 >>$$))+)%	 %  r   c                     g }|r|j                  d       |s|r|j                  d       |r|j                  d       |st        d      dj                  |      S )a  Builds an update mask for updating a MessageBus.

    Args:
      logging_config: bool, whether to update the logging config.
      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.
    rv   rw   rx   z*Must specify at least one field to update.,)appendr   join)r-   r|   
crypto_keyclear_crypto_keyrx   rX   s         r   BuildUpdateMaskz"MessageBusClientV1.BuildUpdateMask   s]    $ K)%)""#OPP88K  r   c                 B    | j                   j                  j                  S )zReturns the labels value class.)r(   r{   LabelsValuer-   s    r   LabelsValueClassz#MessageBusClientV1.LabelsValueClass  s    >>$$000r   c           
      t    ||||y | j                   j                  |||d|| j                  |            S )Nz1.0)idtypesourcespecVersiontextData
attributes)r+   )GoogleCloudEventarcPublishingV1CloudEvent_BuildCloudEventAttributes)r-   ri   rj   rk   rl   rm   s         r   re   z/MessageBusClientV1._BuildCloudEventProtoMessage  s\     	$$NN223CD O  r   c                 4   |y | j                   j                  j                  |j                         D cg c]P  \  }}| j                   j                  j                  j	                  || j                   j                  |            R c}}      S c c}}w )N)ceString)keyvalue)additionalProperties)r+   r   AttributesValueitemsAdditionalPropertyAGoogleCloudEventarcPublishingV1CloudEventCloudEventAttributeValue)r-   rm   r   r   s       r   r   z-MessageBusClientV1._BuildCloudEventAttributes  s    $$NN^^ /446
 7
U %%OO__rr//qq" r  s  7
 _ 
 

s   AB
c                      y)Nzmessage-busesr   r   s    r   _resource_label_pluralz)MessageBusClientV1._resource_label_plural*  s    r   )F)r   r   r   r   r#   r:   rB   rS   rW   r\   rf   rp   r   r   r   re   r   propertyr   __classcell__)r0   s   @r   r    r    )   s]    OQ&,,&0**, $2L"!<1&  r   r    N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   r	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.corer   r   Errorr   r   EventarcClientBaser    r   r   r   <module>r      sU    / &  ' ' 0 2 = , * )CZ-- C"C00 Cr   