
    4                         S r SSKJr  SSKJr  SSKJr  SSK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 Webhook trigger command.    )absolute_import)division)unicode_literalsN)cloudbuild_util)trigger_config)base)resource_args)concept_parsers)log)
properties)	resourcesc                   \    \ rS rSrSrS\R                  " S5      0r\S 5       r	S r
S rSrg	)
UpdateWebhook!   z-Update a Webhook trigger used by Cloud Build.EXAMPLESa              To update the branch from which the trigger clones:

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

            To update the webhook secret:

              $ {command} my-webhook-trigger --secret=projects/my-project/secrets/my-secret/versions/2

            To update the substitutions of the trigger:
              $ {command} my-trigger --update-substitutions=_REPO_NAME=my-repo,_BRANCH_NAME=master
          c                    [         R                  R                  S[        R                  " 5       SSS9R                  U 5        [        R                  " U SSS9nUR                  S[        R                  " S5      S	9  [        R                  " US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--secretz
            The full path of the secret version required to validate webhook requests against this trigger.
            For example, projects/my-project/secrets/my-secret/versions/1.
        )help)has_file_sourcerequire_docker_imageN)r
   ConceptParserForResourcer	   GetTriggerResourceSpecAddToParsertrigger_utilsAddTriggerArgsadd_argumenttextwrapdedentAddBuildConfigArgsForUpdateAddRepoSourceForUpdateAddFilterArg)parserflag_configs     -lib/surface/builds/triggers/update/webhook.pyArgsUpdateWebhook.Args3   s     !!--,,.	 . 
 k&..K __     --T ((5{+    c                 V   [         R                  " 5       n[        R                  " X5      u  pVU(       a  U$ [        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$ )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.
Tr   zgcr.io/z/gcb-z:$COMMIT_SHA)default_imagehas_repo_sourcer   )r   GetMessagesModuler   ParseTriggerArgsForUpdater   VALUEScoreprojectGetr   ParseBuildConfigArgsForUpdatesubscription_filterfilter)	selfargsold_triggerupdate_maskmessagestriggerdoner4   r.   s	            r)   ParseTriggerFromFlags#UpdateWebhook.ParseTriggerFromFlagsR   s     002H!;;DKMGn$$,,00$0?G6=t||LM//#	 --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UR)                  UR*                  S9Ul        SmU
R/                  [         R0                  " U5      5        [3        [5        U4S	 jU
 5       5      5      n
UR7                  UUUS
R9                  U
5      S9nUR                   R;                  U5      n[<        R>                  " USS9  U$ )zThis is what gets called when the user runs this command.

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)secretsubstitutionsc              3   V   >#    U  H  oR                  T5      (       a  TOUv   M      g 7f)N)
startswith).0msubs     r)   	<genexpr>$UpdateWebhook.Run.<locals>.<genexpr>   s"     A[<<$$C!+[s   &),)resourceNamerI   buildTrigger
updateMaskbuild_trigger)kind) r   GetClientInstancer0   r   r2   r3   r4   r5   buildsregionDEFAULT_REGIONr   r   REGISTRYParseRelativeNameprojects_locations_triggersMESSAGES_MODULE-CloudbuildProjectsLocationsTriggersGetRequestr@   WebhookConfigrJ   webhookConfigextendMessageToFieldPathssortedset/CloudbuildProjectsLocationsTriggersPatchRequestjoinPatchr   UpdatedResource)r9   r:   clientr=   r4   
regionproplocation	triggeridrH   r;   r<   r>   requpdated_triggerrP   s                 @r)   RunUpdateWebhook.Runt   s    ..0F002H$$,,00$0?G""))00446J{{JjJO,J,JHI##!##

 < $  ln 	 4488LL 	M 	
K K((KHG$22$++2FG C::7CDA[AAK 
B
B88K(	 C C 88>>sCO	8r,    N)__name__
__module____qualname____firstlineno____doc__r"   r#   detailed_helpstaticmethodr*   r@   rs   __static_attributes__ru   r,   r)   r   r   !   s@    5 (// # - , ,< D7r,   r   )rz   
__future__r   r   r   r"   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   %googlecloudsdk.command_lib.cloudbuildr	   (googlecloudsdk.command_lib.util.conceptsr
   googlecloudsdk.corer   r   r   UpdateCommandr   ru   r,   r)   <module>r      sB    & &  '  = M ( ? D # * )JD&& Jr,   