
    N>                         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KJr  SSKJr  Sr " S S\R,                  5      rS rS r " S S\
5      r " S S\5      rg)z$Utilities for Eventarc Triggers API.    )absolute_import)division)unicode_literals)
list_pager)common)EventarcClientBase)apis)types)
exceptions)	resources)iso_duration)times   c                       \ 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/triggers.pyr   r   "   s    Br   r   c                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )Nz$eventarc.projects.locations.triggers)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcetriggers     r   GetTriggerURIr$   &   s7    00mm F 1 H'				r   c                 >   [         R                  " U 5      (       d  g[        R                  " U5      n[        R
                  " [        S9n[        R                  " X#5      n[        R                  " 5       U:  a  g[        R                  " US[        R                  S9$ )a  Computes the time by which the trigger will become active.

Args:
  event_type: str, the trigger's event type.
  update_time: str, the time when the trigger was last modified.

Returns:
  The active time as a string, or None if the trigger is already active.
N)minutesz%H:%M:%S)fmttzinfo)r
   IsAuditLogTyper   ParseDateTimer   DurationMAX_ACTIVE_DELAY_MINUTESGetDateTimePlusDurationNowFormatDateTimeLOCAL)
event_typeupdate_time	update_dtdelay	active_dts        r   TriggerActiveTimer6   ,   ss     
		j	)	)!!+.)


(@
A%++I=)
YY[I			iZ	LLr   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
_BaseTriggersClientA   zBase Triggers Client.c                    > [         [        U ]  [        R                  SS5        [
        R                  " [        R                  S5      nUR                  U l        UR                  U l
        UR                  U l        g )Nv1r#   )superr8   __init__r   API_NAMEr	   GetClientInstanceMESSAGES_MODULE	_messagesprojects_locations_triggers_serviceprojects_locations_operations_operation_service)selfclient	__class__s     r   r=   _BaseTriggersClient.__init__D   sY    	
t-footYO##FOOT:F++DN66DM$BBDr   c                     U R                   R                  UR                  5       R                  5       UUR	                  5       S9nU R
                  R                  U5      $ )a  Creates a new Trigger.

Args:
  trigger_ref: Resource, the Trigger to create.
  trigger_message: Trigger, the trigger message that holds trigger's
    event_filters, service account, destination, transport, etc.

Returns:
  A long-running operation for create.
)parentr#   	triggerId)rA   .EventarcProjectsLocationsTriggersCreateRequestParentRelativeNameNamerC   Create)rF   trigger_reftrigger_message
create_reqs       r   rQ   _BaseTriggersClient.CreateK   sY     NN!!#002""$ O &J ==
++r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )z{Deletes a Trigger.

Args:
  trigger_ref: Resource, the Trigger to delete.

Returns:
  A long-running operation for delete.
r    )rA   .EventarcProjectsLocationsTriggersDeleteRequestrO   rC   Delete)rF   rR   
delete_reqs      r   rY   _BaseTriggersClient.Delete\   s?     NN%%' O )J==
++r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zeGets a Trigger.

Args:
  trigger_ref: Resource, the Trigger to get.

Returns:
  The Trigger message.
rW   )rA   +EventarcProjectsLocationsTriggersGetRequestrO   rC   Get)rF   rR   get_reqs      r   r^   _BaseTriggersClient.Geti   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$ )aI  Lists Triggers in a given location.

Args:
  location_ref: Resource, the location to list Triggers 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 Triggers in the location.
)rK   pageSizetriggersrb   )field
batch_sizelimitbatch_size_attribute)rA   ,EventarcProjectsLocationsTriggersListRequestrO   r   YieldFromListrC   )rF   location_refrf   	page_sizelist_reqs        r   List_BaseTriggersClient.Listv   sV     ~~JJ((*Y K @H##') )r   c                     U R                   R                  UR                  5       UUS9nU R                  R	                  U5      $ )aI  Updates a Trigger.

Args:
  trigger_ref: Resource, the Trigger to update.
  trigger_message: Trigger, the trigger message that holds trigger's
    event_filters, service account, destination, transport, etc.
  update_mask: str, a comma-separated list of Trigger fields to update.

Returns:
  A long-running operation for update.
)r    r#   
updateMask)rA   -EventarcProjectsLocationsTriggersPatchRequestrO   rC   Patch)rF   rR   rS   update_mask	patch_reqs        r   rr   _BaseTriggersClient.Patch   sG     LL%%' M  I ==y))r   )rA   rE   rC   )r   r   r   r   r   r=   rQ   rY   r^   rm   rr   r   __classcell__)rH   s   @r   r8   r8   A   s*    C,",&),* *r   r8   c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)TriggersClientV1   z3Client for Triggers service in the Eventarc GA API.c
                 >   Uc  / O;UR                  5        V
Vs/ s H  u  pU R                  R                  XS9PM      snn
nUbB  UR                  5        H.  u  pUR                  U R                  R                  XSS95        M0     U(       a  UR	                  5       OSnU R                  R                  US9nU R                  R                  US9nU(       a  UR	                  5       OSnU R                  R                  UR	                  5       UUUUUUU	S9$ s  snn
f )a  Builds a Trigger message with the given data.

Args:
  trigger_ref: Resource, the Trigger to create.
  event_filters: dict or None, the Trigger's event filters.
  event_filters_path_pattern: dict or None, the Trigger's event filters in
    path pattern format.
  event_data_content_type: str or None, the data content type of the
    Trigger's event.
  service_account: str or None, the Trigger's service account.
  destination_message: Destination message or None, the Trigger's
    destination.
  transport_topic_ref: Resource or None, the user-provided transport topic.
  channel_ref: Resource or None, the channel for 3p events
  labels: dict or None, the Trigger's labels.

Returns:
  A Trigger message with a destination service.
N)	attributevaluezmatch-path-pattern)r{   r|   operator)topic)pubsub)r    eventFilterseventDataContentTypeserviceAccountdestination	transportchannellabels)itemsrA   EventFilterappendrO   Pubsub	TransportTrigger)rF   rR   event_filtersevent_filters_path_patternevent_data_content_typeservice_accountdestination_messagetransport_topic_refchannel_refr   keyr|   filter_messagestransport_topic_namer   r   r   s                    r   BuildTriggerMessage$TriggersClientV1.BuildTriggerMessage   s2   > *1b'--/8/JC 	""S">/8O "-288:*#NN&&5I ' K	L ; 
 /;; "&  ^^"")=">F(((7I,7k&&(TG>>!!%%'$4&' " 	 	!8s   %Dc                 l    U R                   R                  UUUUS9nU R                   R                  US9$ )a  Builds a Destination message for a destination Cloud Run service.

Args:
  destination_run_service: str or None, the destination Cloud Run service.
  destination_run_job: str or None, the destination Cloud Run job.
  destination_run_path: str or None, the path on the destination Cloud Run
    service.
  destination_run_region: str or None, the destination Cloud Run service's
    region.

Returns:
  A Destination message for a destination Cloud Run service.
)servicejobpathregion)cloudRun)rA   CloudRunDestination)rF   destination_run_servicedestination_run_jobdestination_run_pathdestination_run_regionrun_messages         r   BuildCloudRunDestinationMessage0TriggersClientV1.BuildCloudRunDestinationMessage   sC    $ ..))'!%	 * 'K
 >>%%{%;;r   c                 n    U R                   R                  UUUUUS9nU R                   R                  US9$ )a)  Builds a Destination message for a destination GKE service.

Args:
  destination_gke_cluster: str or None, the destination GKE service's
    cluster.
  destination_gke_location: str or None, the location of the destination GKE
    service's cluster.
  destination_gke_namespace: str or None, the destination GKE service's
    namespace.
  destination_gke_service: str or None, the destination GKE service.
  destination_gke_path: str or None, the path on the destination GKE
    service.

Returns:
  A Destination message for a destination GKE service.
)clusterlocation	namespacer   r   )gke)rA   GKEr   )rF   destination_gke_clusterdestination_gke_locationdestination_gke_namespacedestination_gke_servicedestination_gke_pathgke_messages          r   BuildGKEDestinationMessage+TriggersClientV1.BuildGKEDestinationMessage   sF    ( ..$$')+'! % #K >>%%+%66r   c                 X    SR                  XU5      nU R                  R                  US9$ )a  Builds a Workflow Destination message with the given data.

Args:
  project_id: the ID of the project.
  destination_workflow: str or None, the Trigger's destination Workflow ID.
  destination_workflow_location: str or None, the location of the Trigger's
    destination Workflow. It defaults to the Trigger's location.

Returns:
  A Destination message with a Workflow destination.
z%projects/{}/locations/{}/workflows/{})workflowformatrA   r   )rF   
project_iddestination_workflowdestination_workflow_locationworkflow_messages        r   BuildWorkflowDestinationMessage0TriggersClientV1.BuildWorkflowDestinationMessage  s5     ?EE3GI>>%%/?%@@r   c                 X    SR                  XU5      nU R                  R                  US9$ )a  Builds a Function Destination message with the given data.

Args:
  project_id: the ID of the project.
  destination_function: str or None, the Trigger's destination Function ID.
  destination_function_location: str or None, the location of the Trigger's
    destination Function. It defaults to the Trigger's location.

Returns:
  A Destination message with a Function destination.
z%projects/{}/locations/{}/functions/{})cloudFunctionr   )rF   r   destination_functiondestination_function_locationfunction_messages        r   BuildFunctionDestinationMessage0TriggersClientV1.BuildFunctionDestinationMessage#  s5     ?EE3GI>>%%4D%EEr   c                     U R                   R                  US9nU R                   R                  US9nU R                   R                  UUS9$ )a-  Builds a HTTP Endpoint Destination message with the given data.

Args:
  destination_http_endpoint_uri: str or None, the Trigger's destination uri.
  network_attachment: str or None, the Trigger's destination
    network attachment.

Returns:
  A Destination message with a HTTP Endpoint destination.
)uri)networkAttachment)httpEndpointnetworkConfig)rA   HttpEndpointNetworkConfigr   )rF   destination_http_endpoint_urinetwork_attachmenthttp_endpoint_messagenetwork_config_messages        r   #BuildHTTPEndpointDestinationMessage4TriggersClientV1.BuildHTTPEndpointDestinationMessage5  sd     !NN77) 8  "^^99, :  >>%%*, &  r   c                    / nU(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U	(       a  UR                  S5        U
(       a  UR                  S5        U(       a  UR                  S5        U(       d  U(       a  UR                  S5        U(       d  U(       a  UR                  S	5        U(       d  U(       a  UR                  S
5        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 Cloud Run trigger.

Args:
  event_filters: bool, whether to update the event filters.
  event_filters_path_pattern: bool, whether to update the event filters with
    path pattern syntax.
  event_data_content_type: bool, whether to update the event data content
    type.
  service_account: bool, whether to update the service account.
  destination_run_service: bool, whether to update the destination Cloud Run
    service.
  destination_run_job: bool, whether to update the desintation Cloud Run
    job.
  destination_run_path: bool, whether to update the destination Cloud Run
    path.
  destination_run_region: bool, whether to update the destination Cloud Run
    region.
  destination_gke_namespace: bool, whether to update the destination GKE
    service namespace.
  destination_gke_service: bool, whether to update the destination GKE
    service name.
  destination_gke_path: bool, whether to update the destination GKE path.
  destination_workflow: bool, whether to update the destination workflow.
  destination_workflow_location: bool, whether to update the destination
    workflow location.
  destination_function: bool, whether to update the destination function.
  destination_function_location: bool, whether to update the destination
    function location.
  labels: bool, whether to update the labels.

Returns:
  The update mask as a string.

Raises:
  NoFieldsSpecifiedError: No fields are being updated.
zdestination.cloudRun.pathzdestination.cloudRun.regionzdestination.cloudRun.servicezdestination.cloudRun.jobzdestination.gke.namespacezdestination.gke.servicezdestination.gke.pathzdestination.workflowzdestination.cloudFunctionr   r   r   r   z*Must specify at least one field to update.,)r   r   join)rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   s                     r   BuildUpdateMask TriggersClientV1.BuildUpdateMaskO  s   n K45677834 4523/0</0<452()*/0""#OPP88K  r   c                 B    [         R                  " UR                  5      $ )zGets the Trigger's event type.)r
   EventFiltersMessageToTyper   )rF   rS   s     r   GetEventTypeTriggersClientV1.GetEventType  s    **?+G+GHHr   c                 B    U R                   R                  R                  $ )zReturns the labels value class.)rA   r   LabelsValue)rF   s    r   LabelsValueClass!TriggersClientV1.LabelsValueClass  s    >>!!---r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rx   rx      s8    ;8t<278A$F$4T!lI.r   rx   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   $googlecloudsdk.api_lib.eventarc.baser   googlecloudsdk.api_lib.utilr	   #googlecloudsdk.command_lib.eventarcr
   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r   r,   Errorr   r$   r6   r8   rx   r   r   r   <module>r      sr    + &  ' ' 2 C , 5 * ) 1 * CZ-- CM*[*, [*|L.* L.r   