
    @                         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r " S S\R"                  5      rS rS r " S S\R*                  5      r " S S\5      rg)z$Utilities for Eventarc Triggers API.    )
list_pager)base)common)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   TriggerActiveTimer3   )   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$ )
_BaseTriggersClient>   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    )superr5   __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__A   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)r>   .EventarcProjectsLocationsTriggersCreateRequestParentRelativeNameNamer@   Create)rC   trigger_reftrigger_message
create_reqs       r   rN   _BaseTriggersClient.CreateH   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   )r>   .EventarcProjectsLocationsTriggersDeleteRequestrL   r@   Delete)rC   rO   
delete_reqs      r   rV   _BaseTriggersClient.DeleteY   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.
rT   )r>   +EventarcProjectsLocationsTriggersGetRequestrL   r@   Get)rC   rO   get_reqs      r   r[   _BaseTriggersClient.Getf   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.
)rH   pageSizetriggersr_   )field
batch_sizelimitbatch_size_attribute)r>   ,EventarcProjectsLocationsTriggersListRequestrL   r   YieldFromListr@   )rC   location_refrc   	page_sizelist_reqs        r   List_BaseTriggersClient.Lists   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)r>   -EventarcProjectsLocationsTriggersPatchRequestrL   r@   Patch)rC   rO   rP   update_mask	patch_reqs        r   ro   _BaseTriggersClient.Patch   sG     LL%%' M  I ==y))r   )r>   rB   r@   )r   r   r   r   r   r:   rN   rV   r[   rj   ro   r   __classcell__)rE   s   @r   r5   r5   >   s*    C,",&),* *r   r5   c                   T    \ 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Srg)TriggersClientV1   z3Client for Triggers service in the Eventarc GA API.c                 \   / nUb;  UR                  5        VVs/ s H  u  pU R                  R                  XS9PM      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 R                  U	5      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
  max_retry_attempts: int or None, the Trigger's max retry attempts.
  labels: dict or None, the Trigger's labels.

Returns:
  A Trigger message with a destination service.
N)	attributevaluezmatch-path-pattern)rx   ry   operator)topic)pubsub)	r   eventFilterseventDataContentTypeserviceAccountdestination	transportchannelretryPolicylabels)	itemsr>   EventFilterappendrL   Pubsub	TransportTrigger_BuildRetryPolicy)rC   rO   event_filtersevent_filters_path_patternevent_data_content_typeservice_accountdestination_messagetransport_topic_refchannel_refmax_retry_attemptsr   filter_messageskeyry   transport_topic_namer|   r   r   s                     r   BuildTriggerMessage$TriggersClientV1.BuildTriggerMessage   sJ   B O  *//11jc ..
$
$s
$
@1   "-288:*#NN&&5I ' K	L ; 
 /;; "&  ^^"")=">F(((7I,7k&&(TG>>!!%%'$4&'**+=> " 
 
!s   %D(c                 <    Uc  gU R                   R                  US9$ )zBuilds a RetryPolicy message with the given data.

Args:
  max_retry_attempts: int or None, the Trigger's max retry attempts.

Returns:
  A RetryPolicy message with the given data.
N)maxAttempts)r>   RetryPolicy)rC   r   s     r   r   "TriggersClientV1._BuildRetryPolicy   s&     !>>%%2D%EEr   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)r>   CloudRunDestination)rC   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)r>   GKEr   )rC   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formatr>   r   )rC   
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   )rC   r   destination_functiondestination_function_locationfunction_messages        r   BuildFunctionDestinationMessage0TriggersClientV1.BuildFunctionDestinationMessage2  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)r>   HttpEndpointNetworkConfigr   )rC   destination_http_endpoint_urinetwork_attachmenthttp_endpoint_messagenetwork_config_messages        r   #BuildHTTPEndpointDestinationMessage4TriggersClientV1.BuildHTTPEndpointDestinationMessageD  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(       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.
  max_retry_attempts: bool, whether to update the max retry attempts.
  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   r   z*Must specify at least one field to update.,)r   r   join)rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rp   s                      r   BuildUpdateMask TriggersClientV1.BuildUpdateMask^  s*   r 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}   )rC   rP   s     r   GetEventTypeTriggersClientV1.GetEventType  s    **?+G+GHHr   c                 B    U R                   R                  R                  $ )zReturns the labels value class.)r>   r   LabelsValue)rC   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   r   ru   ru      s>    ;=~F<278A$F$4X!tI.r   ru   N)r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   googlecloudsdk.api_lib.utilr   #googlecloudsdk.command_lib.eventarcr   googlecloudsdk.corer   r	   googlecloudsdk.core.utilr
   r   r)   Errorr   r!   r3   EventarcClientBaser5   ru   r   r   r   <module>r      sp    + ( 0 2 , 5 * ) 1 * CZ-- CM*[*$11 [*|b.* b.r   