
    %                        S 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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%  \RL                  \RN                  " \RP                  RR                  \RP                  RT                  5       " S S\RV                  5      5       5       r,\RN                  " \RP                  RZ                  5       " S S\,5      5       r.\,R                   \.l         g )!z;Command for updating env vars and other configuration info.    )absolute_import)division)print_function)unicode_literals)global_methods)service)apis)messages)arg_parsers)base)util)config_changes)connection_context)
exceptions)flags)messages_util)	platforms)pretty_print)resource_args)serverless_operations)stages)concept_parsers)presentation_specs)
properties)	resources)progress_trackerc                   `    \ rS rSrSrSSS.r\S 5       r\S 5       rS r	S	 r
S
 rS rS rSrg)Replace.   z>Create or replace a service from a YAML service specification.zU          Creates or replaces a service from a YAML service specification.
          z          To replace the specification for a service defined in myservice.yaml

              $ {command} myservice.yaml

         )DESCRIPTIONEXAMPLESc           	         [         R                  " S[        R                  " 5       SSSSS9n[        R
                  " U/5      R                  U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        UR                  SS[        R                  " 5       SS	9  UR                  R                  S
5        g )Nz--namespacezNamespace to replace service.TF)requiredprefixeshiddenFILEstoreziThe absolute path to the YAML file with a Knative service definition for the service to update or deploy.)actiontypehelpnone)r   ResourcePresentationSpecr   GetNamespaceResourceSpecr   ConceptParserAddToParserr   AddAsyncFlagAddClientNameAndVersionFlagsAddDryRunFlagadd_argumentr   YAMLFileContentsdisplay_info	AddFormat)clsparsernamespace_presentations      #lib/surface/run/services/replace.py
CommonArgsReplace.CommonArgsA   s     0HH..0' !!#9 #$ %%0[%8 
v	&&v.	
))+B	  C !!&)    c                 &    U R                  U5        g N)r;   r7   r8   s     r:   ArgsReplace.Args\   s    NN6r=   c                 |    [         R                  " U[        R                  R                  U R                  5       US9$ )N)region_label)r   GetConnectionContextr   ProductRUNReleaseTrack)selfargsrD   s      r:   _ConnectionContextReplace._ConnectionContext`   s1    22emm!2!2!4< r=   c                 v    [         R                  " U5      [         R                  " U R                  5       5      /$ r?   )r   ReplaceServiceChangeSetLaunchStageAnnotationChangerH   )rI   new_servicerJ   s      r:   _GetBaseChangesReplace._GetBaseChangese   s3     	++K855d6G6G6IJ r=   c                     g r?    )rI   rJ   rP   changess       r:   _GetMultiRegionRegionsReplace._GetMultiRegionRegionsl   s    r=   c                 \   UR                   (       a.  [        R                  " SR                  UR                  S95        g U(       a.  [        R                  " SR                  UR                  S95        g [        R                  " SR                  UR                  UR
                  S95        g )NzPNew configuration for [{{bold}}{serv}{{reset}}] is being applied asynchronously.)servzKNew configuration has been validated for service [{{bold}}{serv}{{reset}}].zdNew configuration has been applied to service [{{bold}}{serv}{{reset}}].
URL: {{bold}}{url}{{reset}})rY   url)async_r   Successformatnamedomain)rI   service_objdry_runrJ   s       r:   _PrintSuccessMessageReplace._PrintSuccessMessageo   s    {{"F(8(8F9 
''-v;3C3Cv'D
 ((.##);); )/ )r=   c                    [         R                  " [        R                  [        R                  5      n[        UR                  5      nSU;   a  US	 UR                  S0 5      R                  SS5      nUb&  [        U[        5      (       d  [        U5      US   S'   Sn [        R                  " X2R                  5      n[        R                  " Xb5      nUR"                  R$                  R'                  5       R)                  5       nUR*                  R$                  Gb  UR-                  S5      (       a/  XER*                  R$                  :w  a  [        R.                  " S5      eUR*                  R$                  n[0        R2                  " 5       [0        R4                  :X  a  [6        R8                  R:                  R<                  R?                  5       n[@        RB                  " U5      n	XH:w  a4  U[        U	5      :w  a%  [        R.                  " SRE                  X5      5      eXER*                  l        U RG                  XQ5      n
[H        RJ                  R'                  UR*                  RL                  S	UR*                  R$                  0S
S9nURN                  (       a  URP                  OSnU RS                  X5      n[U        US5      (       a  URV                  OSnU(       a  SOSn[X        RZ                  " U5       nUR]                  U5      nU R_                  XU
5      n[`        Rb                  " [d        Rf                  " XUS95        [h        Rj                  " US9nU(       a  SOSnU(       a  Sn[l        Rn                  " UUSURp                  =(       d    US9 nURs                  UU
U Ru                  5       UURp                  SSUUS9	nSSS5        U Rw                  UX5        UsSSS5        $ ! [        R                   a   n[        R                   " USS9   SnAGNJSnAff = f! , (       d  f       Nb= f! , (       d  f       g= f)z#Create or Update service from YAML.statusmetadata	namespaceNzPlease make sure that the YAML file matches the Knative service definition spec in https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/#Service.)	help_textz7Namespace specified in file does not match passed flag.zVNamespace must be project ID [{}] or quoted number [{}] for Cloud Run (fully managed).namespacesIdzrun.namespaces.services)params
collectionra   Fz Validating new configuration forzApplying new configuration to)	operation)regions_listzDeploying...zDeploying new service...zValidating...zDeployment failed)failure_messagesuppress_outputT)asynallow_unauthenticatedfor_replacera   multiregion_regions)<r	   GetMessagesModuler   SERVERLESS_API_NAMESERVERLESS_API_VERSIONdictr&   get
isinstancestrr   DictToMessageWithErrorCheckServicer   ScalarTypeMismatchErrorr   MaybeRaiseCustomFieldMismatchCONCEPTSrg   ParseNamerf   IsSpecifiedConfigurationErrorr   GetPlatformPLATFORM_MANAGEDr   VALUEScoreprojectGetprojects_utilGetProjectNumberr]   rQ   r   REGISTRYr^   
is_managedregionrK   hasattrra   r   Connect
GetServicerV   r   Inforun_messages_utilGetStartDeployMessager   ServiceStagesr   StagedProgressTrackerr[   ReleaseServicerH   rb   )rI   rJ   run_messagesservice_dictrg   rP   raw_serviceer   project_numberrU   service_refrD   conn_contextra   r(   clientr`   regionsdeployment_stagesheadertrackers                         r:   RunReplace.Run   s   ))**--L 		?L
 <
x
    R044[$GIZ	3%?%?.1)nl:{+K
!==
,,.kOOK>k ''--/446I%%1


;
'
'
++55
5++EG 	G&&00i				 I$>$>	>##((00446&77@I^1D$D--++16'+JL L &/""";5G$$**!! 4 4 > >?, + .K
 *5)?)?;%%TL**4>L%dI66dllEG  	+,  
	&	&|	4%%k2k++DwGg

1
16 !..GD"-3Mf	 11

-++0	
 ++"& ' , 

" W;A 
5	4[ 00 ..
 v  
5	4s=    6O1 =BP90P(P91P%P  P%(
P6	2P99
QrT   N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr;   rA   rK   rQ   rV   rb   r   __static_attributes__rT   r=   r:   r   r   .   s[     G- * *4  
(fr=   r   c                   $    \ rS rSr\S 5       rSrg)AlphaReplace   c                 .    [         R                  U5        g r?   )r   r;   r@   s     r:   rA   AlphaReplace.Args   s    vr=   rT   N)r   r   r   r   r   rA   r   rT   r=   r:   r   r      s      r=   r   N)/r   
__future__r   r   r   r   googlecloudsdk.api_lib.runr   r   googlecloudsdk.api_lib.utilr	   r
   r   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.projectsr   r   googlecloudsdk.command_lib.runr   r   r   r   r   r   r   r   r   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   UniverseCompatibleReleaseTracksrH   BETAGACommandr   ALPHAr   rT   r=   r:   <module>r      s    B &  % ' 5 . , A / ( E 9 = 5 0 M 4 7 8 @ 1 D G * ) 8 D%%**D,=,=,@,@Aydll y B yx D%%++,7  -  r=   