
    I                         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Qr
\R                  " S	5      rS
r " S S\	R                  5      rSS jr  SS jrSS jrg)z Parse cloudbuild config files.

    )absolute_import)division)unicode_literalsN)cloudbuild_util)
exceptions)	secretEnv
secret_envsubstitutionsenvMapenv_mapz^_[A-Z0-9_]+$zbuild configc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidBuildConfigException*   z&Build config message is not valid.

  c                 L   > SR                  UUS9n[        [        U ]  U5        g )Nz(validating {path} as build config: {msg})pathmsg)formatsuperr   __init__)selfr   r   	__class__s      /lib/googlecloudsdk/api_lib/cloudbuild/config.pyr   $InvalidBuildConfigException.__init__/   s0    
4
;
; < C 

%t5c:     )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__)r   s   @r   r   r   *   s    ; ;r   r   c                    U R                   nUc  U R                  5       nUc  0 n0 nUR                   H  nUR                  XVR                  '   M     U HG  n[
        R                  U5      (       a  M  [        USR                  U[
        R                  5      5      e   UR                  U5        U R                  5       n[        UR                  5       5       HF  u  pxU R                  R                  5       n	Xyl        Xl        UR                  R                  U	5        MH     UR                  (       a  X@l         U(       d  U R                  (       a  [        US5      eU R                   (       d  U R"                  (       d  [        US5      eU $ )a  Validate the given build message, and merge substitutions.

Args:
  build: The build message to finalize.
  path: The path of the original build config, for error messages.
  params: Any additional substitution parameters as a dict.
  no_source: CLI flag value for --no-source. If set, the build config can
    provide a remote build source.

Raises:
  InvalidBuildConfigException: If the build config is invalid.

Returns:
  The valid build message with substitutions complete.
z.substitution key {} does not respect format {}z9config cannot specify source without the flag --no-sourcez;config must list at least one step or specify remote_config)r
   SubstitutionsValueadditionalPropertiesvaluekey_BUILTIN_SUBSTITUTION_REGEXmatchr   r   patternupdatesorteditemsAdditionalPropertyappendsourceremoteConfigsteps)
buildr   params	no_sourcesubst_value
subst_dictkvr'   r&   aps
             r   FinalizeCloudbuildConfigr:   7   sa     ##+**,K^F *,,bJvv - c&,,S11'

:
A
A.66   F ((*+:++-.jc		!	!	4	4	6BFH$$++B/	 /
 %%% 
u||
%I  
		EKK
%E  
,r   c                 t    [         R                  " XR                  [        [        U5      n[        XCU5      nU$ )a|  Load a cloudbuild config file into a Build message.

Args:
  stream: file-like object containing the JSON or YAML data to be decoded.
  messages: module, The messages module that has a Build type.
  params: dict, parameters to substitute into a templated Build spec.
  path: str or None. Optional path to be used in error messages.

Raises:
  ParserError: If there was a problem parsing the stream as a dict.
  ParseProtoException: If there was a problem interpreting the stream as the
    given message type.
  InvalidBuildConfigException: If the build config has illegal values.

Returns:
  Build message, The build that got decoded.
)r   LoadMessageFromStreamBuild_BUILD_CONFIG_FRIENDLY_NAME_SKIP_CAMEL_CASEr:   )streammessagesr4   r   r3   s        r   LoadCloudbuildConfigFromStreamrB   w   s6    . 
/
/0K0@$H% #5
7%	,r   c                 r    [         R                  " XR                  [        [        5      n[        X@X#5      nU$ )a  Load a cloudbuild config file into a Build message.

Args:
  path: str. Path to the JSON or YAML data to be decoded.
  messages: module, The messages module that has a Build type.
  params: dict, parameters to substitute into a templated Build spec.
  no_source: CLI flag value for --no-source. If set, the build config can
    provide a remote build source.

Raises:
  files.MissingFileError: If the file does not exist.
  ParserError: If there was a problem parsing the file as a dict.
  ParseProtoException: If there was a problem interpreting the file as the
    given message type.
  InvalidBuildConfigException: If the build config has illegal values.

Returns:
  Build message, The build that got decoded.
)r   LoadMessageFromPathr=   r>   r?   r:   )r   rA   r4   r5   r3   s        r   LoadCloudbuildConfigFromPathrE      s3    ( 
-
-
NN79IK%
"5
B%	,r   )NN)r    
__future__r   r   r   re!googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.corer   r?   compiler(   r>   Errorr   r:   rB   rE   r   r   r   <module>rL      si    '  ' 	 = * 
 !jj9  - 
;*"2"2 
;=F 		<r   