
    7                        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SKrSr\R@                  " S/ SQ5      r!Sr"\!" SSSS\"-   S9r#\!" SSSS\"-   S9r$\!" SSSS \"-   S9r%\!" S!S"S#S$S9r&\!" SS%S&S'S9r'\#// \$\&/\#\&/\&/\'\%\&/\$\&/\%\&// \'/S(.
r(S) r)S* r*\RV                  \RX                  " \RZ                  R\                  5       " S+ S,\R^                  5      5       5       r0\RV                  \RX                  " \RZ                  Rb                  5       " S- S.\05      5       5       r2g)/;Upgrade a 1st gen Cloud Function to the Cloud Run function.    )absolute_import)division)unicode_literalsN)api_enablement)client)
exceptions)util)base)types)flags)run_util)service_account_util)deploy_util)log)
console_io)zgoogle.pubsub.topic.publishz/providers/cloud.pubsub/eventTypes/topic.publishUpgradeAction)target_state
prompt_msgop_descriptionsuccess_msgz^You can abort the upgrade process at any time by rerunning this command with the --abort flag.(SETUP_FUNCTION_UPGRADE_CONFIG_SUCCESSFULa  This creates a Cloud Run function with the same name [{}], code, and configuration as the 1st gen function. The 1st gen function will continue to serve traffic until you redirect traffic to the Cloud Run function in the next step.

To learn more about the differences between 1st gen and Cloud Run functions, visit: https://cloud.google.com/functions/docs/concepts/version-comparisonzSetting up the upgrade for function. Please wait while we duplicate the 1st gen function configuration and code to a Cloud Run function.a  The Cloud Run function is now ready for testing:
  {}
View the function upgrade testing guide for steps on how to test the function before redirecting traffic to it.

Once you are ready to redirect traffic, rerun this command with the --redirect-traffic flag.

,REDIRECT_FUNCTION_UPGRADE_TRAFFIC_SUCCESSFULzThis will redirect all traffic from the 1st gen function [{}] to its Cloud Run function copy. Please ensure that you have tested the Cloud Run function before proceeding.z.Redirecting traffic to the Cloud Run function.zThe Cloud Run function is now serving all traffic. If you experience issues, rerun this command with the --rollback-traffic flag. Otherwise, once you are ready to finalize the upgrade, rerun this command with the --commit flag.

zThis will rollback all traffic from the Cloud Run function copy [{}] to the original 1st gen function. The Cloud Run function is still available for testing.z-Rolling back traffic to the 1st gen function.ziThe 1st gen function is now serving all traffic. The Cloud Run function is still available for testing.

ELIGIBLE_FOR_2ND_GEN_UPGRADEzhThis will abort the upgrade process and delete the Cloud Run function copy of the 1st gen function [{}].z"Aborting the upgrade for function.zDUpgrade aborted and the Cloud Run function was successfully deleted.ztThis will complete the upgrade process for function [{}] and delete the 1st gen copy.

This action cannot be undone.zBCompleting the upgrade and deleting the 1st gen copy for function.a(  Upgrade completed and the 1st gen copy was successfully deleted.

Your function will continue to be available at the following endpoints:
{}
Reminder, your function can now be managed through the Cloud Run API. Any event triggers are now Eventarc triggers and can be managed through Eventarc API.)
r   UPGRADE_OPERATION_IN_PROGRESSr   #SETUP_FUNCTION_UPGRADE_CONFIG_ERRORABORT_FUNCTION_UPGRADE_ERRORr   'REDIRECT_FUNCTION_UPGRADE_TRAFFIC_ERROR'ROLLBACK_FUNCTION_UPGRADE_TRAFFIC_ERROR"COMMIT_FUNCTION_UPGRADE_SUCCESSFULCOMMIT_FUNCTION_UPGRADE_ERRORc                 4   [         R                  " U 5      nUS:X  a  [        R                  " S5      eX!R                  :X  a%  [        R                  " SR                  U 5      5      eU[        U   ;  a%  [        R                  " SR                  U 5      5      eg)zKValidates whether the action is a valid action for the given upgrade state.r   zVAn upgrade operation is already in progress for this function. Please try again later.z9This function is already in the desired upgrade state: {}zTThis function is not eligible for this operation. Its current upgrade state is '{}'.N)six	text_typer	   FunctionsErrorr   format_VALID_TRANSITION_ACTIONS)upgrade_stateactionupgrade_state_strs       lib/surface/functions/upgrade.py_ValidateStateTransitionr,      s     mmM299

#
#	# 
 ---

#
#CJJ	
  ,->??

#
#	 &/  @    c                    [         R                  " U R                  5      S:X  a$  [        R                  " SU R
                   S35      eS[        R                  " 5       ;   a$  [        R                  " SU R
                   S35      e[         R                  " U R                  5      S:w  a1  [        R                  " SU R
                   SU R                   S35      eU R                  (       dB  U R                  R                  [        ;  a$  [        R                  " SU R
                   S	35      e[        R                  " SU R
                   S
35      e)z>Raises an error when the function is not eligible for upgrade.GEN_2
Function [z] is not eligible for Upgrade. To migrate to Cloud Run function, please detach the function using `gcloud functions detach` instead.:zq] is not eligible for Cloud Run function upgrade. It is in domain-scoped project that Cloud Run does not support.ACTIVEzB] is not eligible for Cloud Run function upgrade. It is in state [z].zt] is not eligible for Cloud Run function upgrade. Only HTTP functions and Pub/Sub triggered functions are supported.z1] is not eligible for Cloud Run function upgrade.)r#   r$   environmentr	   r%   nameapi_util
GetProjectstateurleventTrigger	eventTypeSUPPORTED_EVENT_TYPES)functions    r+    _RaiseNotEligibleForUpgradeErrorr=      s7   ]]8''(G3

#
#
X]]O $& 	& 
 	H!!

#
#
X]]O $ 	 
 	]]8>>"h.

#
#
X]]O $%%-^^$4B	8 
 ,,



)
)1F
F

#
#
X]]O $ 	 
 	!!8==/ " 	 r-   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
UpgradeBeta   r   z{description}a            To start the upgrade process for a 1st gen function `foo` and create a Cloud Run function copy, run:

            $ {command} foo --setup-config

          Once you are ready to redirect traffic to the Cloud Run function copy, run:

            $ {command} foo --redirect-traffic

          If you find you need to do more local testing you can rollback traffic to the 1st gen copy:

            $ {command} foo --rollback-traffic

          Once you're ready to finish upgrading and delete the 1st gen copy, run:

            $ {command} foo --commit

          You can abort the upgrade process at any time by running:

            $ {command} foo --abort
          )DESCRIPTIONEXAMPLESc                 ^    [         R                  " U S5        [         R                  " U 5        g )Nz
to upgrade)r   AddFunctionResourceArgAddUpgradeFlags)parsers    r+   ArgsUpgradeBeta.Args	  s     	  6	&!r-   c                 	   [         R                  " U R                  5       5      nUR                  R                  R                  5       nUR                  5       nUR                  U5      nU(       d%  [        R                  " SR                  U5      5      eUR                  (       d  [        U5        UR                  R                  n[        R                  " U5      S:X  a;  [        R                  " SUR                   SUR                   R"                   S35      eS nS nUR$                  (       a  [&        nUR(                  nOUR*                  (       a  [,        nUR.                  nOUR0                  (       a  [2        nUR4                  nOaUR6                  (       a  [8        nUR:                  nO=UR<                  (       a  [>        nUR@                  nO[B        RD                  " / SQS5      e[G        Xg5        URH                  R                  U5      n	[J        RL                  " U	SS	9(       d  g U[>        :X  Ga  [N        RP                  " S
5        [N        RP                  " S5        URR                  n
U
(       d(  URT                  (       a  [B        RV                  " SS5      eU
(       a:  [X        RZ                  " U
R\                  5      (       a  [^        R`                  " 5         U
(       aE  [X        Rb                  " U
R\                  5      (       a   [^        Rd                  " U
Rf                  5        U" XART                  5      nOU" U5      nURh                  n[j        Rl                  " URn                  URp                  X5        [r        Rt                  Rw                  5         U[>        :X  a  UR                  U5      nURR                  (       a4  [x        Rz                  " U[j        R|                  " 5       URT                  SS9  [r        Rt                  Rw                  UR~                  R                  UR                  R                  R                  5      5        g U[2        :X  aq  [        R                  " U5      nSR                  S UR                   5       5      n[r        Rt                  Rw                  UR~                  R                  U5      5        g [r        Rt                  Rw                  UR~                  5        g )NzFunction [{}] does not exist.)INELIGIBLE_FOR_UPGRADE_UNTIL_REDEPLOYMENTr0   z?] is not eligible for Cloud Run function upgrade. The runtime [z] is not supported. Please update to a supported runtime instead and try again. Use `gcloud functions runtimes list` to get a list of available runtimes.)z--abortz--commitz--redirect-trafficz--rollback-trafficz--setup-configz*One of the upgrade step must be specified.T)defaultzcloudbuild.googleapis.comzartifactregistry.googleapis.comz--trigger-service-accountzLTrigger service account can only be specified for event-triggered functions.F)is_gen2 c              3   .   #    U  H  nS U S3v   M     g7f)z* 
N ).0r8   s     r+   	<genexpr>"UpgradeBeta.Run.<locals>.<genexpr>{  s     B\cr#b\\s   )F	client_v2FunctionsClientReleaseTrackCONCEPTSr4   ParseRelativeNameGetFunctionr	   r%   r&   upgradeInfor=   upgradeStater#   r$   buildConfigruntimeredirect_traffic_REDIRECT_TRAFFIC_ACTIONRedirectFunctionUpgradeTrafficrollback_traffic_ROLLBACK_TRAFFIC_ACTIONRollbackFunctionUpgradeTrafficcommit_COMMIT_ACTIONCommitFunctionUpgradeabort_ABORT_ACTIONAbortFunctionUpgradesetup_config_SETUP_CONFIG_ACTIONSetupFunctionUpgradeConfigcalliope_exceptionsOneOfArgumentsRequiredExceptionr,   r   r   PromptContinuer   PromptToEnableApiIfDisabledr9   trigger_service_accountInvalidArgumentExceptiontrigger_typesIsPubsubTyper:   r   'ensure_pubsub_sa_has_token_creator_roleIsAuditLogType#ensure_data_access_logs_are_enabledeventFiltersr   r5   WaitForOperationr   messagesr   statusPrintr   $ValidateAndBindTriggerServiceAccountr6   r   serviceConfigurir   
GetServicejoinurls)selfargsr   function_reffunction_namer<   r(   r)   	action_fnmessagetrigger	operationdescriptionserviceurls_stringss                  r+   RunUpgradeBeta.Run  s   &&t'8'8':;F==%%++-L --/M!!-0H%%
)
0
0
?  &x0((55M 	m$6	7 %%x}}o &$$,$8$8$@$@#A B!!  FI'f77i			'f77i	f..i	f--i			#f33i?? 7	 	 ]3&&}5G$$Wd;%% 001LM00
+ %%g55!::'*
 	

 
]//0A0ABB;;=	]11'2C2CDD778L8LMM+G+GHiM*i''Kv	 JJ%%##M2h			 	AA!((		
 
jj



#
#H$8$8$F$F$J$J
K 
>	!##H-gWWBW\\BBl	jjv))00>?	jjv))*r-   rP   N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodrG   r   __static_attributes__rP   r-   r+   r?   r?      s3     D %-2 " "p+r-   r?   c                       \ rS rSrSrSrg)UpgradeAlphai  r   rP   N)r   r   r   r   r   r   rP   r-   r+   r   r     s     Dr-   r   )3r   
__future__r   r   r   collections googlecloudsdk.api_lib.functionsr   #googlecloudsdk.api_lib.functions.v2r   rT   r	   r
   r5   googlecloudsdk.callioper   rn   #googlecloudsdk.command_lib.eventarcr   rt   $googlecloudsdk.command_lib.functionsr   r   r   'googlecloudsdk.command_lib.functions.v2r   googlecloudsdk.corer   googlecloudsdk.core.consoler   r#   r;   
namedtupler   _ABORT_GUIDANCE_MSGrl   r`   rc   ri   rf   r'   r,   r=   DefaultUniverseOnlyReleaseTracksrV   BETACommandr?   ALPHAr   rP   r-   r+   <module>r      s!   B &  '  ; C : @ ( E F 6 9 E ? # 2 
 
 && 
 %;	O	  2 )?	+ D  $ );	" C
    /	. 8N
 	> 	M	=( &:$:%' 1
 	, &3O 5 	!0
 	!0 +-&4%55 <2D D%%**+Q+$,, Q+ , Q+h D%%++,D; D - Dr-   