
    Q                     t   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KJr  SSKJr  SSKJr  SSKJr  SSKJr  SrSrSrSrSrSrSR=                  \5      rSR=                  S5      r SR=                  S5      r!SR=                  S5      r"S R=                  S5      r#S!r$ " S" S#\RJ                  5      r% " S$ S%\%5      r& " S& S'\%5      r' " S( S)\%5      r( " S* S+\)5      r* " S, S-\*5      r+ " S. S/\+5      r, " S0 S1\*5      r-S5S2 jr.S3 r/S6S4 jr0g)7z1Module to parse .yaml files for an appengine app.    )absolute_import)division)unicode_literalsN)env)appinfo)appinfo_errors)appinfo_includes)croninfo)dispatchinfo)	queueinfo)
validation)yaml_errors)datastore_index)
exceptions)log)fileszThis field is not used by gcloud and must be removed. Project name should instead be specified either by `gcloud config set project MY_PROJECT` or by setting the `--project` flag on individual command executions.zThis field is not used by gcloud and must be removed. Versions are generated automatically by default but can also be manually specified by setting the `--version` flag on individual command executions.zHThis field is not supported with runtime [{}] and can safely be removed.zThis field is not configurable with runtime [{}] since static files are always readable by the application. It can safely be removed.zDeployments using `vm: true` have been deprecated.  Please update your app.yaml to use `env: flex`. To learn more, please visit https://cloud.google.com/appengine/docs/flexible/migration.
zAhttps://cloud.google.com/appengine/docs/flexible/python/migratingzSupport for the compat runtimes and their base images (enable_app_engine_apis: true) has been deprecated.  Please migrate to a new base image, or use a Google managed runtime. To learn more, visit {}.aT  You are using an outdated version [2.7] of the Python SSL library. Please update your app.yaml file to specify SSL library [latest] to avoid security risks. On April 2, 2018, version 2.7 will be decommissioned and your app will be blocked from deploying until you you specify SSL library [latest] or [2.7.11].For more information, visit {}.zBhttps://cloud.google.com/appengine/docs/deprecations/python-ssl-27a9  You are using a deprecated version [3.4] of Python on the App Engine Flexible environment. Please update your app.yaml file to specify [python_version: latest]. Python 3.4 will be decommissioned on March 29, 2019. After this date, new deployments will fail. For more information about this deprecation, visit  {}.z=https://cloud.google.com/appengine/docs/deprecations/python34ay  You might have set automatic_scaling.max_instances to 0. Starting from March, 2025, App Engine sets the automatic scaling maximum instances default for standard environment deployments to 20. This change doesn't impact existing apps. To disable the maximum instances default configuration setting, specify the maximum permitted value 2147483647. For more information, see {}. 
zWhttps://cloud.google.com/appengine/docs/standard/reference/app-yaml.md#scaling_elementsa  You might be using automatic scaling for a standard environment deployment, without providing a value for automatic_scaling.max_instances. Starting from March, 2025, App Engine sets the automatic scaling maximum instances default for standard environment deployments to 20. This change doesn't impact existing apps. To override the default, specify the new max_instances value in your app.yaml file, and deploy a new version or redeploy over an existing version. For details on max_instances, see {}. 
zn^(.*/)?#.*#$|^(.*/)?.*~$|^(.*/)?.*\.py[co]$|^(.*/)?.*/RCS/.*$|^(.*/)?.git(ignore|/.*)$|^(.*/)?node_modules/.*$c                       \ rS rSrSrSrg)Error   zA base error for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       .lib/googlecloudsdk/api_lib/app/yaml_parsing.pyr   r      s    %r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )YamlParseError   z>An exception for when a specific yaml file is not well formed.c                 F   > [         [        U ]  SR                  XS95        g)zCreates a new Error.

Args:
  file_path: str, The full path of the file that failed to parse.
  e: Exception, The exception that was originally raised.
z9An error occurred while parsing file: [{file_path}]
{err})	file_patherrN)superr!   __init__format)selfr$   e	__class__s      r   r'   YamlParseError.__init__   s#     
.$(D	)	+-r   r   )r   r   r   r   r   r'   r   __classcell__r+   s   @r   r!   r!      s    F	- 	-r   r!   c                       \ rS rSrSrSrg)YamlValidationError   z<An exception for when a specific yaml file has invalid info.r   Nr   r   r   r   r0   r0      s    Dr   r0   c                       \ rS rSrSrSrg)AppConfigError   zErrors in Application Config.r   Nr   r   r   r   r3   r3      s    %r   r3   c                   .    \ rS rSrSrS r\S 5       rSrg)	_YamlInfo   zFA base class for holding some basic attributes of a parsed .yaml file.c                     Xl         X l        g)zCreates a new _YamlInfo.

Args:
  file_path: str, The full path the file that was parsed.
  parsed: The parsed yaml data as one of the *_info objects.
Nfileparsed)r)   r$   r;   s      r   r'   _YamlInfo.__init__   s     IKr   c                 t    [         R                  " U 5       nU" U5      sSSS5        $ ! , (       d  f       g= f)zParses the given file using the given parser.

Args:
  file_path: str, The full path of the file to parse.
  parser: str, The parser to use to parse this yaml file.

Returns:
  The result of the parse.
N)r   
FileReader)r$   parserfps      r   
_ParseYaml_YamlInfo._ParseYaml   s'     
		)	$BZ 
%	$	$s   )
7r9   N)	r   r   r   r   r   r'   staticmethodrA   r   r   r   r   r6   r6      s    N  r   r6   c                      ^  \ rS rSrSrSrSrSrSr\\	R                  \\R                  \\R                  \\R                   0rU 4S jr\S 5       r\S	 5       rS
rU =r$ )ConfigYamlInfo   zHA class for holding some basic attributes of a parsed config .yaml file.crondispatchindexqueuec                 8   > [         [        U ]  X5        X l        g)zCreates a new ConfigYamlInfo.

Args:
  file_path: str, The full path the file that was parsed.
  config: str, The name of the config that was parsed (i.e. 'cron')
  parsed: The parsed yaml data as one of the *_info objects.
N)r&   rE   r'   config)r)   r$   rL   r;   r+   s       r   r'   ConfigYamlInfo.__init__   s     
.$(;Kr   c                     [         R                  R                  [         R                  R                  U R                  5      5      u  pU$ )z7Name of the config file without extension, e.g. `cron`.)ospathsplitextbasenamer:   )r)   base_s      r   nameConfigYamlInfo.name   s2       !1!1$))!<=ITKr   c                 |   [         R                  R                  [         R                  R                  U 5      5      u  pUS:X  a  [	        S5      e[         R                  R                  U 5      (       a3  UR                  5       S;   a  [        R                  R                  U5      OSnU(       d  g [        R                  X5      nU(       d  [        U S5      e [        SUS U [         S9  US	:X  a
  [#        XUS
9$ [        XUS
9$ ! [        R                  [        R                  4 a  n[        X5      eSnAff = f)zParses the given config file.

Args:
  file_path: str, The full path to the config file.

Raises:
  Error: If a user tries to parse a dos.yaml file.
  YamlParseError: If the file is not valid.

Returns:
  A ConfigYamlInfo object for the parsed file.
doszd`gcloud app deploy dos.yaml` is no longer supported. Please use `gcloud app firewall-rules` instead.)z.yamlz.ymlNzThe file is emptyapplicationc                     U R                   $ NrY   yamls    r   <lambda>)ConfigYamlInfo.FromFile.<locals>.<lambda>   
    D$4$4r   rU   	yaml_infoextractor_funcr$   msgrH   )rL   r;   )rO   rP   rQ   rR   r   isfilelowerrE   CONFIG_YAML_PARSERSgetr6   rA   r!   r   r   _CheckIllegalAttributeHINT_PROJECTDispatchConfigYamlInfo)r$   rS   extr?   r;   r*   s         r   FromFileConfigYamlInfo.FromFile   s!      !1!1)!<=IDu}2 
 	**syy{>O/O 0044T:  )##I6fY(;<< 
 4 z#I6JJ)@@ z//0 )9(()s   2(D $D;+D66D;)rL   )r   r   r   r   r   CRONDISPATCHINDEXQUEUEr
   LoadSingleCronr   LoadSingleDispatchr   ParseIndexDefinitionsr   LoadSingleQueuerh   r'   propertyrU   rC   rn   r   r-   r.   s   @r   rE   rE      s    P	$(
%
% H##//_22Y&&		  
 (A (Ar   rE   c                   $    \ rS rSrSrS rS rSrg)rl   i  z5Provides methods for getting 1p-ready representation.c                 <   [         R                  " UR                  5      nUR                  nUR                  (       d  SU-   nUR
                  nUR                  (       d.  UR                  S5      (       a  SOSnUR                  S5      U-   nUUUR                  S.$ )z5Converst a dispatchinfo handler into a 1p-ready dict.*/z/*)domainrP   service)
r   	ParsedURLurlhost
host_exactrP   
path_exactendswithrstripr~   )r)   handler
parsed_urldispatch_domaindispatch_pathtrailing_matchers         r   _HandlerToDict%DispatchConfigYamlInfo._HandlerToDict  s    ''4J ooO  o-oOOM  !.!7!7!<!<##**3/2BBm!?? r   c                     U R                   R                  =(       d    /  Vs/ s H  oR                  U5      PM     sn$ s  snf )zzGet dispatch rules on a format suitable for Admin API.

Returns:
  [{'service': str, 'domain': str, 'path': str}], rules.
)r;   rH   r   )r)   hs     r   GetRulesDispatchConfigYamlInfo.GetRules  s9     -1KK,@,@,FB,FG,Fq",FGGGs   ?r   N)r   r   r   r   r   r   r   r   r   r   r   rl   rl     s    ="Hr   rl   c                   p   ^  \ rS rSrSrSrU 4S jr\S 5       rS r	S r
S rS	 rS
 rS rS rS rSrU =r$ )ServiceYamlInfoi"  zHA class for holding some basic attributes of a parsed service yaml file.defaultc                   > [         [        U ]  X5        UR                  =(       d    [        R                  U l        UR                  S;   a  [        R                  U l        OLUR                  (       d  UR                  S:X  a  [        R                  U l        O[        R                  U l        U R                  [        R                  L a  SU l        O^UR                  (       aF  UR                   H.  nUR                  (       d  UR                  (       d  M'  SU l          O   SU l        OSU l        U R!                  X5        U R#                  U5        U R                  [        R                  L d  U R                  (       a&  UR%                  5       U l	        U R'                  5         OUR                  U l	        [        R(                  " 5       R+                  U R                  U R                  5      U l        g)zCreates a new ServiceYamlInfo.

Args:
  file_path: str, The full path the file that was parsed.
  parsed: appinfo.AppInfoExternal, parsed Application Configuration.
)2flexflexiblevmTFN)r&   r   r'   r~   DEFAULT_SERVICE_NAMEmoduler   FLEXr   runtimeMANAGED_VMSSTANDARDis_hermetichandlers
static_dirstatic_files_InitializeHasExplicitSkipFiles_UpdateSkipFilesGetEffectiveRuntime_UpdateVMSettingsGetTiRuntimeRegistryGetis_ti_runtime)r)   r$   r;   urlmapr+   s       r   r'   ServiceYamlInfo.__init__&  sM    
/4))<..HO$H$HDKzz..dh	fnn,dhdh
 xx388d	OO& 3 3 3"$

 $
  d((;&!COO#(8(8//1dl
^^dl 11377dhhODr   c                      [         R                  U [        R                  5      n[        X5      nUR                  5         U$ ! [        R
                  [        R
                  4 a  n[        X5      eSnAff = f)a  Parses the given service file.

Args:
  file_path: str, The full path to the service file.

Raises:
  YamlParseError: If the file is not a valid Yaml-file.
  YamlValidationError: If validation of parsed info fails.

Returns:
  A ServiceYamlInfo object for the parsed file.
N)
r6   rA   r	   Parser   r   r   r!   r   Validate)r$   r;   r*   infos       r   rn   ServiceYamlInfo.FromFileR  sh    )##I/?/E/EFf 9-DMMOK ~334 )9(()s   $A $A7'A22A7c                 	   U R                   R                  S:X  a  U R                   R                  5       nOSnU R                   R                  S:X  aC  [        SR	                  U R                   R
                  =(       d    [        R                  S95      eU R                   R                  S:X  a  [        S5      eU R                   R                  S:X  a&  U R                   R                  (       d  [        S	5      eU R                  [        R                  L a  [        R                  " [        5        U R                  [        R                  L a_  U R                   R                  (       aD  U R                   R                  R                  S
5      (       a  [        R                  " [         5        U R                  [        R                  L a  US:X  a  [        S5      eU R                  [        R                  L a0  US:X  a*  [        R                  " SR	                  U["        5      5        U R                  [        R                  La  U R                   R$                  (       d  U R                   R&                  (       d  U R                   R(                  (       ad  U R                   R(                  (       ac  U R                   R(                  R*                  (       d>  U R                   R(                  R*                  S:w  a  [        R                  " [,        5        U R                  [        R                  LaY  U R                   R(                  (       a>  U R                   R(                  R*                  S:X  a  [        R                  " [.        5        U R                   R1                  5        H3  n[        R                  " SR	                  U R2                  U5      5        M5     U R                  [        R4                  L aP  U R                   R                  S:X  a6  [7        U R                   SS5      (       a  [        R                  " [8        5        U R                  [        R                  L a:  US:X  a4  [;        U R                   S5      S:X  a  [        R                  " [<        5        [?        SU R                   S U R2                  [@        S9  [?        SU R                   S U R2                  [B        S9  U RE                  5         g)zDisplays warnings and raises exceptions for non-schema errors.

Raises:
  YamlValidationError: If validation of parsed info fails.
r   Npythonz`Service [{service}] uses unsupported Python 2.5 runtime. Please use [runtime: python27] instead.)r~   zpython-compatz+"python-compat" is not a supported runtime.customz;runtime "custom" requires that env be explicitly specified.enable_app_engine_apispython27zQThe "python27" is not a valid runtime in env: flex.  Please use [python] instead.zZ[runtime: {}] is deprecated.  Please use [runtime: python] instead.  See {} for more info.r   zIn file [{0}]: {1}sslz2.7python_versionz3.4rY   c                     U R                   $ r[   r\   r]   s    r   r_   *ServiceYamlInfo.Validate.<locals>.<lambda>  ra   r   rb   versionc                     U R                   $ r[   )r   r]   s    r   r_   r     s    DLLr   )#r;   r   r   r0   r(   r~   r   r   r   r   r   warningMANAGED_VMS_DEPRECATION_WARNINGr   beta_settingsri   #APP_ENGINE_APIS_DEPRECATION_WARNINGUPGRADE_FLEX_PYTHON_URLbasic_scalingmanual_scalingautomatic_scalingmax_instances,DEFAULT_MAX_INSTANCES_FORWARD_CHANGE_WARNING1DEFAULT_MAX_INSTANCES_FORWARD_CHANGE_ZERO_WARNINGGetWarningsr:   r   HasLibPYTHON_SSL_WARNINGGetRuntimeConfigAttrFLEX_PY34_WARNINGrj   rk   HINT_VERSION_ValidateTi)r)   
vm_runtime	warn_texts      r   r   ServiceYamlInfo.Validatei  sY    {{d";;224jj				(!66<f,, >(== 7= 7@A 	A
 ;;/1!9; 	;;;(*4;;??!IK 	K xx3??"	kk12CHH!:!:!!%%&>??	kk56xx388
j 8)* * xx388
o =	kk 46*&=>@ 	 ))**----55CCKK11??1D 
kk>? 	 KK))KK))771<	kkCD[[,,.		kk&--diiCD / 	CLL z)t{{E5))	kk$%CHHhT[[*:;uD	kk#$++4)) ++0)) 	r   c           
      R  ^ U R                   (       d  g[        SU R                  S U R                  [        R                  U R                  5      S9  U R                  R                   H;  m[        STU4S jU R                  [        R                  U R                  5      S9  M=     g)z(Validation specifically for Ti-runtimes.N
threadsafec                     U R                   $ r[   )r   r]   s    r   r_   -ServiceYamlInfo._ValidateTi.<locals>.<lambda>  s    DOOr   rb   application_readablec                    > TR                   $ r[   )r   )r^   r   s    r   r_   r     s    g&B&Br   )	r   rj   r;   r:   HINT_THREADSAFEr(   r   r   HINT_READABLE)r)   r   s    @r   r   ServiceYamlInfo._ValidateTi  s}    ++3))""4<<02 ;;''%BII""4<<02 (r   c                 `    U R                   [         R                  L =(       d    U R                  $ )z3Returns True if we'll need to build a docker image.)r   r   r   r)   s    r   RequiresImageServiceYamlInfo.RequiresImage  s     88s&:$*:*::r   c                 t   U R                   [         R                  [         R                  4;  a  [        S5      eU R                  R
                  (       d$  [        R                  " 5       U R                  l        [        R                  R                  U R                  5      U R                  R
                  S'   g)zOverwrites vm_settings for App Engine services with VMs.

Also sets module_yaml_path which is needed for some runtimes.

Raises:
  AppConfigError: if the function was called for a standard service
zMThis is not an App Engine Flexible service. Please set `env` field to `flex`.module_yaml_pathN)r   r   r   r3   r;   vm_settingsr   
VmSettingsrO   rP   rR   r:   r   s    r   r   !ServiceYamlInfo._UpdateVMSettings  s{     xx22  ;;"" ' 2 2 4dkk24''2B2B4992MDKK./r   c                 T    [         R                  R                  U R                  5      $ )z<Returns the basename for the app.yaml file for this service.)rO   rP   rR   r:   r   s    r   GetAppYamlBasename"ServiceYamlInfo.GetAppYamlBasename  s    77DII&&r   c                     U R                   $ )zCReturns whether user has explicitly defined skip_files in app.yaml.)_has_explicit_skip_filesr   s    r   HasExplicitSkipFiles$ServiceYamlInfo.HasExplicitSkipFiles  s    (((r   c                     [        USS5      [        R                  :X  a"   [        R                  " U5      nSU;   U l        gSU l        g! [        R
                   a    Sn N+f = f)zFRead app.yaml to determine whether user explicitly defined skip_files.
skip_filesN T)getattrr   DEFAULT_SKIP_FILESr   ReadFileContentsr   r   )r)   r$   r;   contentss       r   r   /ServiceYamlInfo._InitializeHasExplicitSkipFiles  s_    v|T*g.H.HH)))4 '3h&>d#&*d#	 [[ s   A
 
A#"A#c                     U R                  5       (       aP  U R                  5       (       d:  [        R                  " [        R                  " [
        5      [
        S5      Ul        ggg)z6Resets skip_files field to Flex default if applicable.r   N)r   r   r   _RegexStrValueRegexDEFAULT_SKIP_FILES_FLEXr   )r)   r;   s     r   r    ServiceYamlInfo._UpdateSkipFiles	  sP    D$=$=$?$?$33


2
3
!
f %@r   )r   r   r   r   r   r   )r   r   r   r   r   r   r'   rC   rn   r   r   r   r   r   r   r   r   r   r-   r.   s   @r   r   r   "  sW    P"*PX  ,aF2(;N"')
+ r   r   c                    ^^ U R                   =(       d    / nT(       a  [        UU4S jU 5       5      $ [        U4S jU 5       5      $ )a'  Check if the parsed yaml has specified the given library.

Args:
  parsed: parsed from yaml to python object
  name: str, Name of the library
  version: str, If specified, also matches against the version of the library.

Returns:
  True if library with optionally the given version is present.
c              3   l   >#    U  H)  oR                   T:H  =(       a    UR                  T:H  v   M+     g 7fr[   )rU   r   ).0librU   r   s     r   	<genexpr>HasLib.<locals>.<genexpr>!  s)     Kdsxx4:CKK7$::ds   14c              3   @   >#    U  H  oR                   T:H  v   M     g 7fr[   )rU   )r   r   rU   s     r   r   r   #  s     04Cxx44s   )	librariesany)r;   rU   r   libss    `` r   r   r     s:     
			R$KdKKK04000r   c                 J    U R                   =(       d    0 R                  U5      $ )zRetrieve an attribute under runtime_config section.

Args:
  parsed: parsed from yaml to python object
  attr: str, Attribute name, e.g. `runtime_version`

Returns:
  The value of runtime_config.attr or None if the attribute isn't set.
)runtime_configri   )r;   attrs     r   r   r   &  s      


%2	*	*4	00r   c                 T    U" U5      nUb  [        SR                  X5      U-   5      eg)a  Validates that an illegal attribute is not set.

Args:
  name: str, The name of the attribute in the yaml files.
  yaml_info: AppInfoExternal, The yaml to validate.
  extractor_func: func(AppInfoExternal)->str, A function to extract the
    value of the attribute from a _YamlInfo object.
  file_path: str, The path of file from which yaml_info was parsed.
  msg: str, Message to couple with the error

Raises:
    YamlValidationError: If illegal attribute is set.

Nz,The [{0}] field is specified in file [{1}]. )r0   r(   )rU   rc   rd   r$   re   	attributes         r   rj   rj   3  s<     Y')
6==dN
	  r   r[   )r   )1r   
__future__r   r   r   rO   googlecloudsdk.api_lib.appr   googlecloudsdk.appengine.apir   r   r	   r
   r   r   r   r   "googlecloudsdk.appengine.datastorer   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   rk   r   r   r   r   r   r(   r   r   r   r   r   r   r   r!   r0   r3   objectr6   rE   rl   r   r   r   rj   r   r   r   <module>r     sk    8 &  ' 	 * 0 7 9 1 5 2 3 4 > * # *E
1
(*#  H  !''> ?	 $& 	&	MN )
 	&	HI ( 	&] 29 	&] -*6 J 
-U -% 
&U & 8IAY IAXH^ H:ni nd1$
1r   