
                             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 S\
R*                  5      rg)zUpdate Pub/Sub trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)
exceptions)resource_args)concept_parsers)log)
properties)	resourcesc                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
UpdatePubsub    z-Update a Pub/Sub trigger used by Cloud Build.EXAMPLESa              To update the branch from which the trigger clones:

              $ {command} my-trigger --source-to-build-branch=my-branch

            To update the topic:

              $ {command} my-trigger --topic=projects/my-project/topics/my-topic

            To update the substitutions of the trigger:
              $ {command} my-trigger --update-substitutions=_REPO_NAME=my-repo,_BRANCH_NAME=master
          c                 V   [         R                  R                  S[        R                  " 5       SSS9R                  U 5        [        R                  " U SSS9nUR                  SSS	9  [        R                  " USS
9  [        R                  " U5        [        R                  " U5        g)zRegister flags for this command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order
    to capture some information, but behaves like an ArgumentParser.
TRIGGERzBuild Trigger.TrequiredF)add_region_flagadd_namez--topicz1The topic to which this trigger should subscribe.)help)has_file_sourceN)r   ConceptParserForResourcer
   GetTriggerResourceSpecAddToParsertrigger_utilsAddTriggerArgsadd_argumentAddBuildConfigArgsForUpdateAddRepoSourceForUpdateAddFilterArgForUpdate)parserflag_configs     ,lib/surface/builds/triggers/update/pubsub.pyArgsUpdatePubsub.Args3   s     !!--,,.4 . ) *5V)<..7K@  B --T+((5''4    c                 N   [         R                  " 5       n[        R                  " X5      u  pVU(       a  U$ UR                  (       a  UR                  UR                  S9Ul        [        R                  R                  R                  R                  SS9nSU< SUR                  < S3n[        R                  " UUUUUUSSS9  UR                  Ul        UR                  b(  UR                  (       d  [         R"                  " SS	5      eUR$                  (       a  S
Ul        U$ )zParses arguments into a build trigger.

Args:
  args: An argparse arguments object.
  old_trigger: The existing trigger to be updated.
  update_mask: The fields to be updated.

Returns:
  A build trigger object.
)topicTr   zgcr.io/z/gcb-z:$COMMIT_SHA)has_repo_sourcer   z--subscription-filterzucannot update subscription filter to be empty; please use `--clear-subscription-filter` to clear subscription filter. )r   GetMessagesModuler   ParseTriggerArgsForUpdater,   PubsubConfigpubsubConfigr   VALUEScoreprojectGetr   ParseBuildConfigArgsForUpdatesubscription_filterfilterc_exceptionsInvalidArgumentExceptionclear_subscription_filter)	selfargsold_triggerupdate_maskmessagestriggerdoner5   default_images	            r'   ParseTriggerFromFlags"UpdatePubsub.ParseTriggerFromFlagsJ   s     002H!;;DKMGnzz%222Dg$$,,00$0?G6=t||LM//	 --GN+D4L4L11
!I 
 
	'	'gnNr*   c                   ^ [         R                  " 5       n[         R                  " 5       n[        R                  R
                  R                  R                  SS9n[        R                  R                  R                  R                  5       nUR                  =(       d    U=(       d    [         R                  nUR                  n[        R                  R                  UUUUS.SS9R                  5       nUR                   R                  UR"                  R%                  XS95      n	/ n
U R'                  XU
5      nSmU
R)                  [         R*                  " U5      5        [-        [/        [1        U4S jU
5      5      5      n
UR3                  UUUS	R5                  U
5      S
9nUR                   R7                  U5      n[8        R:                  " USS9  U$ )zThis is what handles the command execution.

Args:
  args: An argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  The updated webhook trigger.
Tr   )
projectsIdlocationsId
triggersIdz&cloudbuild.projects.locations.triggers)params
collection)name	triggerIdsubstitutionsc                 8   > U R                  T5      (       a  T$ U $ )N)
startswith)msubs    r'   <lambda>"UpdatePubsub.Run.<locals>.<lambda>   s    c!2!2#99r*   ,)resourceNamerN   buildTrigger
updateMaskbuild_trigger)kind)r   GetClientInstancer/   r   r3   r4   r5   r6   buildsregionDEFAULT_REGIONr   r   REGISTRYParseRelativeNameprojects_locations_triggersMESSAGES_MODULE-CloudbuildProjectsLocationsTriggersGetRequestrE   extendMessageToFieldPathssortedsetmap/CloudbuildProjectsLocationsTriggersPatchRequestjoinPatchr   UpdatedResource)r=   r>   clientrA   r5   
regionproplocation	triggeridrM   r?   r@   rB   requpdated_triggerrS   s                 @r'   RunUpdatePubsub.Runv   s    ..0F002H$$,,00$0?G""))00446J{{JjJO,J,JHI##!##

 < $ = >J\^ 	 4488LL 	M 	,-K K((KHG C::7CDC9;GHK 
B
B88K(	 C *C 88>>sCO	8r*    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr(   rE   ru   __static_attributes__rw   r*   r'   r   r       s5    5 -  5 5,*X2r*   r   N)r|   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   r	   r:   %googlecloudsdk.command_lib.cloudbuildr
   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   r   UpdateCommandr   rw   r*   r'   <module>r      sB    & &  ' = M ( > ? D # * )H4%% Hr*   