
    7!                     $   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 dddZ ej$                  ej&                  j(                        ej*                   G d dej,                                      Zy)zCommand to update a trigger.    )absolute_import)division)unicode_literals)triggers)base)
exceptions)flags)types)labels_util)logz{description}z         To update the trigger ``my-trigger'' by setting its destination Cloud Run service to ``my-service'', run:

          $ {command} my-trigger --destination-run-service=my-service
        )DESCRIPTIONEXAMPLESc                   H    e Zd ZdZeZed        Zd Zd Z	d Z
d Zd Zd Zy	)
UpdatezUpdate an Eventarc trigger.c                 0   t        j                  |dd       t        j                  || j                                t        j                  || j                                t        j
                  || j                                t        j                  || j                                t        j                  j                  |       |j                         }t        j                  |       t        j                  |       t        j                  |       y )NzThe trigger to update.T)required)r	   AddTriggerResourceArgAddEventFiltersArgReleaseTrackAddEventFiltersPathPatternArgAddEventDataContentTypeArgAddUpdateDestinationArgsr   
ASYNC_FLAGAddToParseradd_mutually_exclusive_groupAddServiceAccountArgAddClearServiceAccountArgr   AddUpdateLabelsFlags)clsparserservice_account_groups      'lib/surface/eventarc/triggers/update.pyArgszUpdate.Args0   s    	(@4P	VS%5%5%78	''0@0@0BC	$$VS-=-=-?@	""63+;+;+=>OO'"??A	45	##$9:$$V,    c                 $	   t        j                         }|j                  j                  j	                         }t        j                  || j                               }t        j                  || j                               }t        j                  || j                               }|j                  |      }t        j                  j                  |      j                  |j                         |j                         }|j#                  |du|du|du|j%                  d      xs |j&                  |j%                  d      |j%                  d      |j%                  d      xs |j(                  |j%                  d      |j%                  d      |j%                  d      |j%                  d	      xs |j*                  |j%                  d
      |j%                  d      |j%                  d      |j%                  d      |j,                        }	|j/                  |      | _        d}
|j%                  d      s?|j%                  d      s.|j%                  d      s|j%                  d      s|j(                  r>|j3                  |j4                  |j6                  |j8                  |j:                        }
n{|j%                  d      s.|j%                  d      s|j%                  d	      s|j*                  r5|j=                  dd|j>                  |j@                  |jB                        }
n|j%                  d
      s|j%                  d      rb| jE                  ||      }| jG                  ||      }|jI                  |jK                         jK                         jM                         ||      }
n|j%                  d      s|j%                  d      ra| jO                  ||      }| jQ                  ||      }|jS                  |jK                         jK                         jM                         ||      }
|jU                  |||||jV                  |
dd|jY                         	      }|j[                  |||	      }|j\                  r|S |j_                  |d|      S )zRun the update command.Nservice_accountdestination_run_servicedestination_run_jobdestination_run_pathdestination_run_regiondestination_gke_namespacedestination_gke_servicedestination_gke_pathdestination_workflowdestination_workflow_locationdestination_functiondestination_function_location)event_filtersevent_filters_path_patternevent_data_content_typer&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   labelsUpdating)0r   TriggersClientV1CONCEPTStriggerParser	   GetEventFiltersArgr   GetEventFiltersPathPatternArgGetEventDataContentTypeArgGetr   DiffFromUpdateArgsApplyLabelsValueClassr5   BuildUpdateMaskIsSpecifiedclear_service_accountclear_destination_run_pathclear_destination_gke_pathneeds_updateGetEventType_event_typeBuildCloudRunDestinationMessager'   r(   r)   r*   BuildGKEDestinationMessager+   r,   r-   GetWorkflowDestinationLocationGetWorkflowDestinationBuildWorkflowDestinationMessageParentNameGetFunctionDestinationLocationGetFunctionDestinationBuildFunctionDestinationMessageBuildTriggerMessager&   	GetOrNonePatchasync_WaitFor)selfargsclienttrigger_refr2   r3   r4   original_triggerlabels_update_resultupdate_maskdestination_messagelocationworkflowfunctiontrigger_message	operations                   r"   Runz
Update.Run>   sD   &&(F--''--/K,,T43D3D3FGM!&!D!Dd!"##>>d! zz+.&++::4@FF!#3#:#: ((#4/#=T#I 7t C(():; &%% $ 0 01J K ,,-BC!--.DE +**#//0HI"&"2"23N"O $ 0 01J K!--.DE +**!--.DE&*&6&6+'
 "--.DE&*&6&6+'
 $00/ ) K8 **+;<D23./12/0''"BB

&
&(@(@

#
#T%@%@B 

6
7


4
5


1
2

)
)"==
d44

&
&(A(AC 

1
2


:
;44T;KLh,,T3CDh"BB




%
%
'
,
,
.(D


1
2


:
;44T;KLh,,T3CDh"BB




%
%
'
,
,
.(D00"&&(
O [/;GI{{>>)Z==r$   c                     |rSt        j                  | j                        r3t        j                  dj                  t        j                               y y y )Nz@It may take up to {} minutes for the update to take full effect.)r
   IsAuditLogTyperJ   r   warningformatr   MAX_ACTIVE_DELAY_MINUTES)rZ   resources_were_displayeds     r"   EpilogzUpdate.Epilog   s@    E$8$89I9I$J	kk
L6(3346 %Kr$   c                     |j                  d      r|j                  S |j                  j                  r(|j                  j                  j	                  d      d   S t        j                  dd      )Nr/   /   z--destination-workflow8The specified trigger is not for a workflow destination.)rD   r/   destinationrc   splitr   InvalidArgumentExceptionrZ   r[   old_triggers      r"   rM   z%Update.GetWorkflowDestinationLocation   si    78///''$$--33C8;;

-
- BD Dr$   c                     |j                  d      r|j                  S |j                  j                  r(|j                  j                  j	                  d      d   S t        j                  dd      )Nr.   rp      z--destination-workflow-locationrr   )rD   r.   rs   rc   rt   r   ru   rv   s      r"   rN   zUpdate.GetWorkflowDestination   si    ./&&&''$$--33C8;;

-
-)BD Dr$   c                     |j                  d      r|j                  S |j                  j                  r(|j                  j                  j	                  d      d   S t        j                  dd      )Nr1   rp   rq   z--destination-function8The specified trigger is not for a function destination.)rD   r1   rs   cloudFunctionrt   r   ru   rv   s      r"   rR   z%Update.GetFunctionDestinationLocation   si    78///,,$$2288=a@@

-
- BD Dr$   c                     |j                  d      r|j                  S |j                  j                  r(|j                  j                  j	                  d      d   S t        j                  dd      )Nr0   rp   ry   z--destination-function-locationr{   )rD   r0   rs   r|   rt   r   ru   rv   s      r"   rS   zUpdate.GetFunctionDestination   si    ./&&&,,$$2288=a@@

-
-)BD Dr$   N)__name__
__module____qualname____doc___DETAILED_HELPdetailed_helpclassmethodr#   rg   rn   rM   rN   rR   rS    r$   r"   r   r   )   sB     $ -- -W>r6DDDDr$   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.eventarcr   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.eventarcr	   r
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   ReleaseTracksr   GADefaultUniverseOnlyUpdateCommandr   r   r$   r"   <module>r      s    # &  ' 4 ( . 5 5 < # 				 D%%(()TDT TD  *TDr$   