
                             S r SSKrSSKJr  SSKJr  SSKJr  \R                  " S5      r	\R                  " S5      r
S rS	 rS
 rS rS rS\\\4   S\4S jrS rS rS rS rS rS rS rS rS rS rg)z7Utilities for the parsing input for cloud build v2 API.    N)MutableMapping)cloudbuild_exceptions)yamlzK^projects/[^/]+/locations/[^/]+/connections/[^/]+/gitRepositoryLinks/[^/]+$z^projects/[^/]+/topics/[^/]+$c                     UR                  S5      Gt p#U H  nX@;  a    g U R                  U5      n M     X0;   a  X   R                  5       X'   g g )N.)splitgetupper)
input_dict
dotted_keykeylastbits        6lib/googlecloudsdk/api_lib/cloudbuild/v2/input_util.pySetDictDottedKeyUpperCaser      sV    $*3c
$J  
!'--/J     c                     [         R                  " U SSS9n[         R                  " U5      (       d  [        R                  " U S5      eU$ ! [         R                   a%  n[        R                  " XR
                  5      eS nAff = f)NT)
round_trippreserve_quotesz Could not parse as a dictionary.)r   	load_pathErrorr   ParserErrorinner_error	dict_like)pathdataes      r   LoadYamlFromPathr   &   sw    A>>$4FD 
		

+
+D,NP P	+ 
 A

+
+D--
@@As   A B  B  Bc                 h    [         R                  " SSU S9R                  5       R                  S5      $ )Nz([A-Z]+)z_\1)patternreplstring_)resublowerlstripr   s    r   CamelToSnaker)   1   s*    	t
55:UWVVC[Ir   c                     U R                  5       nU(       a2  [        R                  " SR                  SR	                  U5      S95      eg )Nz Unrecognized fields in yaml: {f}z, )f)all_unrecognized_fieldsr   InvalidYamlErrorformatjoin)messageunrecognized_fieldss     r   UnrecognizedFieldsr2   6   sL    779

0
0*11ii+, 	2 	./ / r   c           	         U R                  S5      U S'   U R                  SU R                  SS5      5      nU(       d  [        R                  " S5      e[        R                  " [
        U5      (       a  SU0U S'   O[        R                  " [        U5      (       a  SU0U S'   OuUR                  S	5      (       a  S
U0U S'   OWUS:X  a.  U R                  SS5      (       d  [        R                  " S5      eO#[        R                  " SR                  US95      eSSSSS.nSU ;   ak  U R                  S5      nUR                  U5      nUb  X@S'   OA[        R                  " SR                  USR                  UR                  5       5      S95      eU R                  S0 5      R                  5        H	  u  pVX`U'   M     SU ;   a#  SU S   ;   a  U S   R                  S5      U S   S'   [        U R                  S/ 5      5        g)a  Transform workflow trigger according to the proto.

Refer to:
  * go/gcb-v2-filters
  * go/re-scope-workflow-resources-to-triggers-only
to understand more details.

Args:
  trigger: the trigger defined in the workflow YAML.
Raises:
  InvalidYamlError: The eventType was unsupported.
nameidsourceeventSource zEmpty event sourcetopicgitRepoLinkzhttps://urlwebhookwebhookValidationSecretz2Webhook trigger requires a webhookValidationSecretz'Unsupported event source: {eventsource})eventsourcePUSH_BRANCHPUSH_TAGPULL_REQUESTALL)zbranch-pushztag-pushzpull-requestany	eventTypeNz>Unsupported event type: {event_type}. Supported: {event_types},)
event_typeevent_typesfiltersgitRefregex	nameRegexparams)popr   r-   r$   match_PUB_SUB_TOPIC_PAT_DC_GIT_REPO_LINK_PAT
startswithr	   r.   r/   keysitemsParamDictTransform)triggerr>   event_type_mappingrF   mapped_event_typer   values          r   WorkflowTriggerTransformrY   >   s	    ++f%'$-Hgkk-&DE+	

0
01E
FFXX +.. +.GH	xx%{33&4GHj)),GHi;;0"55!22
>@ @ 6  
0
0188# 	9 	
  #$	 G[)J*..z:$.k!22&'-v$88$6$;$;$=> (. (@A A
 KK	2.446jcCL 7W(99%,X%6%:%:7%CGHk"W[[2./r   	input_mapr   c                 8    X;   a  X   R                  5       X'   g g )N)r
   )rZ   r   s     r   _ConvertToUpperCaser\   x   s    ^))+IN r   c                 J    SU ;   a  [        U S   5      U S'   [        U S5        g )Ndefaulttype)ParamValueTransformr\   )
param_specs    r   ParamSpecTransformrb   }   s(    */
90EFJyj&)r   c                 4    SU ;   a  [        U S   5      U S'   g g NrX   )ResultValueTransform)pipeline_results    r   PipelineResultTransformrg      s#    3OG4LMOG  r   c                     SU ;   a  [        U S   5        [        U R                  S/ 5      5        SU ;   a  [        U 5        g g )NrefrL   onError)RefTransformrT   r	   OnErrorTransform)	task_steps    r   TaskStepTransformrn      s?    
i5!"Y]]8R01)Y r   c                     U S   S;  a&  [         R                  " SR                  U S   S95      e[        U S   5      R	                  5       U S'   g )Nrj   )continuestopAndFailzDUnsupported onError value: {value}. Supported: continue, stopAndFail)rX   )r   r-   r.   r)   r
   r(   s    r   rl   rl      sR    	)_77

0
0N	d9o	& 
 #4	?399;DOr   c                     [        U S5        U R                  S/ 5       H  n[        U S   U   5        M     SU ;   a  [        U S   5      U S'   g g )Nr_   
propertiesrX   )r\   r	   PropertySpecTransformr`   )task_resultproperty_names     r   TaskResultTransformrw      sV    k6*"|R8m+l3MBC 9 .{7/CDK r   c                     [        U S5        g)zuMutates the given property spec from Tekton to GCB format.

Args:
  property_spec: A Tekton-compliant property spec.
r_   N)r\   )property_specs    r   rt   rt      s     mV,r   c                 8    U  H  n[        US   5      US'   M     g rd   )r`   )rL   params     r   rT   rT      s    e(w8E'N r   c                 (   [        U [        5      (       d*  [        U [        5      (       d  [        U [        5      (       a  S[        U 5      S.$ [        U [        5      (       a  SU S.$ [
        R                  " SR                  [        U 5      S95      e)NSTRINGr_   	stringValARRAYr_   arrayVal(Unsupported param value type. {msg_type}msg_type)	
isinstancestrfloatintlistr   r-   r.   r_   )param_values    r   r`   r`      s    c""	K	'	'	K	%	%3{+;<<+t$$55

0
0299+& 	: 	() )r   c                 \   [        U [        5      (       d*  [        U [        5      (       d  [        U [        5      (       a  S[        U 5      S.$ [        U [        5      (       a  SU S.$ [        U [
        5      (       a  SU S.$ [        R                  " SR                  [        U 5      S95      e)	zITransforms the string result value from Tekton to GCB resultValue struct.r}   r~   r   r   OBJECT)r_   	objectValr   r   )
r   r   r   r   r   objectr   r-   r.   r_   )result_values    r   re   re      s     s##	L%	(	(	L#	&	&3|+<==,%%66,''<88

0
0299,' 	: 	
 r   c                     SU ;   a"  U R                  S5      R                  5       U S'   [        U R                  S/ 5      5        g )NresolverrL   )rM   r
   rT   r	   )ri   s    r   rk   rk      s8    3ggj)//1C
OSWWXr*+r   )__doc__r$   typingr   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.corer   compilerP   rO   r   r   r)   r2   rY   r   r\   rb   rg   rn   rl   rw   rt   rT   r`   re   rk    r   r   <module>r      s    > 	 ! C $

 $F G ZZ ?@ 0I
/70t,>#s(#; ,# ,
*N
 <E-9
)(,r   