
    (!                     x   S r SSKJr  SSKJr  SSKJr  SSK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  \R4                  \R6                  \R8                  " \R:                  R<                  5       " S S\R>                  5      5       5       5       r g)z&The gcloud app migrate-to-run command.    )absolute_import)division)unicode_literalsN)appengine_api_client)
k8s_object)base)gae_to_cr_migration_util)list_incompatible_features)	translate)config_changes)flags)log)
properties)deployc                      ^  \ rS rSrSrSSS.r\U 4S j5       rU 4S jrS r	S	 r
SS jrS rS\S
\R                  \\4   4S jrSrU =r$ )AppEngineToCloudRun&   z8Migrate a second-generation App Engine app to Cloud Run.zP          Migrates the second-generation App Engine app to Cloud Run.
          a9            To migrate an App Engine app to Cloud Run:

          through app.yaml

          gcloud app migrate-to-run --appyaml=path/to/app.yaml --entrypoint=main

          OR

          through service and version

          gcloud app migrate-to-run --service=default --version=v1 --entrypoint=main

          )DESCRIPTIONEXAMPLESc                    > [         TU ]  U5        UR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  SS	S9  g )
Nz	--appyamlzFYAML file for the second generation App Engine version to be migrated.)helpz	--servicez+service name that is deployed in App Enginez	--versionz+version name that is deployed in App Enginez--entrypointz%entrypoint required for some runtimes)superArgsadd_argument)clsparser	__class__s     !lib/surface/app/migrate_to_run.pyr   AppEngineToCloudRun.Args:   s{    	GL
   :   :   4      c                   > [         R                  " U R                  5       5      n[        R                  " X!5        U R                  5       U l        [        R                  n U R                  [        l        U R                  U5        [        TU ]-  U5        U R                  U5        U[        l        g! U[        l        f = f)zTOverrides the Deploy.Run method, applying the wrapper logic for FlagIsExplicitlySet.N)r   GetApiClientForTrackReleaseTrackr	   GAEToCRMigrationUtilrelease_trackr   FlagIsExplicitlySet_flag_is_explicitly_set_wrapperStartMigrationr   RunPrintMigrationSummary)selfargs
api_clientoriginal_flag_is_explicitly_setr   s       r   r)   AppEngineToCloudRun.RunQ   s    %::4;L;L;NOJ11*C**,D&+&?&?#B"&"F"Fe
$ gk$
  &"Ae"Aes   "AB4 4Cc                 D    [        U S5      =(       a    X R                  ;   $ )a@  Wrapper function to check if a flag is explicitly set.

This wrapper checks for flags added during the migration process,
in addition to the original flags.FlagIsExplicitlySet check.

Args:
  args: The arguments to check.
  flag: The flag to check.

Returns:
  bool: True if the flag is explicitly set, False otherwise.
_migration_flags)hasattrr1   )r+   r,   flags      r   r'   3AppEngineToCloudRun._flag_is_explicitly_set_wrappera   s      4+,N9N9N1NNr    c                 0   [         R                  " XR                  5       5      nUR                  S[        R
                  " [        R                  5      5        UR                  [        R                  " [        R                  R                  5      5        U$ )z>Returns the service config changes with some default settings.r   )r   GetServiceConfigurationChangesr#   insertr   DeleteAnnotationChanger   BINAUTHZ_BREAKGLASS_ANNOTATIONappendSetLaunchStageAnnotationChanger   ALPHA)r+   r,   changess      r   _GetBaseChanges#AppEngineToCloudRun._GetBaseChangesp   sp    2249J9J9LMGNN	--55	
 NN55d6G6G6M6MN Nr    returnc                    [         R                   " UR                  UR                  UR                  5        [        R                  " UR                  UR                  UR                  UR
                  5      nSnU H"  nUR                  S5      (       a  SnX4S-   -  nM$     UR
                  (       a+  [        USSUR
                  05        USUR
                  -   -  n[        R                  R                  SUS	5        [        US
US   5        / U l        U GH  nUR                  S5      (       d  M  UR                  SS5      nUR                  S5      nUS   R                  SS5      US'   U R                  R                  US   5        US   S:X  a  UR                  US   SSS.5        M  US   S:X  a&  UR                  US   U R!                  U5      5        M  US   S:X  a@  US   S:X  a  UR                  US   S5        OUS   S:X  a  UR                  US   S5        GM  US   S:X  a/  UR                  US   ["        R$                  " US   5      5        GMH  US   S:X  a/  UR                  US   ["        R$                  " US   5      5        GM  ['        U5      S:  a  UR                  US   US   5        GM  UR                  US   S5        GM     g) zStarts the migration process. z--labelszO--labels=migrated-from=app-engine,migration-tool=gcloud-app-migrate-standard-v1 zset-build-env-varsGOOGLE_ENTRYPOINTz( --set-build-env-vars GOOGLE_ENTRYPOINT=zCommand to run:
SERVICE   z--=r   -_labelsz
app-enginezgcloud-app-migrate-standard-v1)zmigrated-fromzmigration-toolset_env_varstimeout   600iX  3600i  min_instancesmax_instancesTN)r
   appyamlserviceversionr   
entrypoint
startswithsetattrr   statusPrintr1   replacesplitr:   __setattr__ParseSetEnvVarsr   
ScaleValuelen)r+   r,   cloud_run_deploy_commandprint_deploy_commandcommand_strcommand_argss         r   r(   "AppEngineToCloudRun.StartMigration~   s    99dllDLL
  )22dllDLL$//  /			
	+	+gC// 0 


0
 
4t
F
 JJ&(<dCD)5a89D/				%	%!))$3 #((-&q/11#s;Q$$\!_5?h&


1o#/$D ?n,


<?D,@,@,M
N
?i'!_%\!_c2A&(\!_d3
?o-


<?E,<,<\!_,M
N
?o-


<?E,<,<\!_,M
N
|q 


<?LO
<


<?D
1G 0H r    c                    [         R                  R                  S5        [        R                  R
                  R                  R                  5       nUR                  =(       d    Sn[        R                  R                  R                  R                  5       n[         R                  R                  SU SU SU SU SU SU S	35        g
)zPrints the migration summary.zU
The code and configuration of your App Engine service has been copied to Cloud Run.
defaultzPView and edit in Cloud Run console: https://console.cloud.google.com/run/detail//z/metrics?project=zW
Deploy new versions of your code with the same configuration using "gcloud run deploy z --source=. --region=z --project=z"
N)r   rY   rZ   r   VALUESrunregionGetrF   coreproject)r+   r,   rk   rT   rn   s        r   r*   )AppEngineToCloudRun.PrintMigrationSummary   s    JJ	 ""))--/Fll'iG$$,,002GJJ	88>xq	IZ[bZc di  HKy		5r    	input_strc                    [         R                  " SU5      nU(       d  [        R                  " 5       $ UR	                  S5      nU(       d  [        R                  " 5       $ [        R                  " S UR                  S5       5       5      nU$ )zParses a 'set-env-vars' string and converts it into an OrderedDict.

Args:
    input_str: A string in the format of
      'set-env-vars="KEY1=VALUE1,KEY2=VALUE2"'.

Returns:
    An OrderedDict containing the environment variables.
z
="([^"]*)"rN   c              3   D   #    U  H  oR                  S S5      v   M     g7f)rH   rN   N)r\   ).0pairs     r   	<genexpr>6AppEngineToCloudRun.ParseSetEnvVars.<locals>.<genexpr>   s       ''=t

3'=s    ,)researchcollectionsOrderedDictgroupr\   )r+   rp   matchvars_stringenv_varss        r   r^   #AppEngineToCloudRun.ParseSetEnvVars   st     IImY/E$$&&++a.K$$&&&& ''2'8'8'=' H Or    )r1   r%   )r@   N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr   r)   r'   r>   r(   r*   strrz   r{   r^   __static_attributes____classcell__)r   s   @r   r   r   &   st     A	-  ,B OCJ(sCx( r    r   )!r   
__future__r   r   r   rz   rx   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.runr   googlecloudsdk.callioper   googlecloudsdk.command_lib.appr	   7googlecloudsdk.command_lib.app.gae_to_cr_migration_utilr
   r   googlecloudsdk.command_lib.runr   r   googlecloudsdk.corer   r   surface.runr   HiddenDefaultUniverseOnlyReleaseTracksr#   r<   AlphaDeployr    r    r   <module>r      s     - &  '  	 ; 1 ( C ^ M 9 0 # *  D%%++,F&,, F -  Fr    