
                            S r SSKrSSKrSSKJrJr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/  SSK0J1r1  SSK2J3r3  SSK4J	r5  SSK4J6r6  SSK4J7r7  SSK8J9r9  SSK8J:r:  SSK;J<r=  SSK;J>r>  S r?\R                  " S!5      rAS"rB\R                  " S#5      rCS$rDS%rES&rF/ S'QrGS(rHS)rIS*rJ\:R                  " S+S,S-9rL\:R                  " S.S/S-9rM\:R                  " S0S1S-9rN\L\M\N/rO/ S2QrPS3/\P-   rQS4rRS5rSS6\R                  S7\US8\R                  4S9 jrWS6\R                  S7\US8\R                  4S: jrX SdS;\R                  S<\R                  S=\7R                  S7\US>\\U   S8\R                  4S? jjr\S;\R                  S<\R                  S=\7R                  S@\\R                     S8\\\R                     \\U   4   4
SA jr^S;\R                  S6\R                  S@\\R                     S8\\R                  \\U   4   4SB jr`SC\US8\\U   4SD jraSE\US8\\U   4SF jrbS;\R                  S6\R                  S@\\R                     S8\\\R                     \\U   4   4SG jrdS;\R                  S6\R                  S8\R                  4SH jreS;\R                  S6\R                  S8\R                  4SI jrfS;\R                  S6\R                  SJ\\R                     S8\\R                  \\U   4   4SK jrhSL\US8\U4SM jriS;\R                  S<\R                  S=\7R                  S@\\R                     S8\\R                  \\U   4   4
SN jrlS;\R                  S@\\R                     S8\\U   4SO jrmS;\R                  S6\R                  S8\\\R                     \\U   4   4SP jroS;\R                  S6\R                  S8\\\U   \\R                     \\U   4   4SQ jrqS;\R                  S6\R                  S8\\\r\R                        \\R                     \\U   4   4SR jruS;\R                  S8S4SS jrvS;\R                  S6\R                  S@\\R                     S8\\\R                     \\U   4   4ST jrxS;\R                  SU\R                  S@\\R                     S=\7R                  S8\\U   4
SV jryS;\R                  SU\R                  S@\\R                     S8\\U   4SW jrzSX\US8\{4SY jr|SZ\R                  S=\7R                  SU\R                  S8S4S[ jr}SZ\R                  S=\7R                  SU\R                  S\\\U   S8S4
S] jr~\>R                  " S^S_S`9Sa 5       rS;\R                  Sb\GR                  S8\R                  4Sc jrg)ezHThis file provides the implementation of the `functions deploy` command.    N)	FrozenSetOptionalTuple)base_api)
exceptions)api_enablement)	cmek_util)secrets)util)client)types)storage_util)base)parser_extensions)ArgumentTypeError)flags)labels_util)run_util)secrets_config)service_account_util)source_util)deploy_util)serverless_operations)	arg_utils)map_util)log)	resources)
console_io)progress_tracker)files)retryz^There was a problem uploading the source code to a signed Cloud Storage URL. Please try again.zgs://([^/]+)/(.*)zNInvalid Cloud Storage URL. Must match the following format: gs://bucket/objectzhttps://source\.developers\.google\.com/projects/(?P<project_id>[^/]+)/repos/(?P<repo_name>[^/]+)(((/revisions/(?P<commit>[^/]+))|(/moveable-aliases/(?P<branch>[^/]+))|(/fixed-aliases/(?P<tag>[^/]+)))(/paths/(?P<path>[^/]+))?)?/?$aB  Invalid Cloud Source Repository URL provided. Must match the following format: https://source.developers.google.com/projects/<projectId>/repos/<repoName>. Specify the desired branch by appending /moveable-aliases/<branchName>, the desired tag with /fixed-aliases/<tagName>, or the desired commit with /revisions/<commit>. zD`--retry` is only supported with an event trigger not http triggers.zThe latest revision of this function is not serving 100% of traffic. Please see the associated Cloud Run service to confirm your expected traffic settings.))docker_registryz--docker-registry)security_levelz--security-level)buildpack_stackz--buildpack-stackz=`%s` is only supported in Cloud Functions (First generation).zdeployment-toolz
cli-gcloudz[ArtifactRegistry]ARTIFACT_REGISTRY)keyz[Healthcheck]SERVICE_ROLLBACKz[Triggercheck]TRIGGER_ROLLBACK)
kKiMMiGGiTTiPPima  
    ^                                    # Beginning of input marker.
    (?P<amount>\d+)                      # Amount.
    ((?P<suffix>[-/ac-zAC-Z]+)([bB])?)?  # Optional scale and optional 'b'.
    $                                    # End of input marker.
z
    ^                                    # Beginning of input marker.
    (?P<amount>\d*.?\d*)                 # Amount.
    (?P<suffix>[-/ac-zAC-Z]+)?           # Optional scale.
    $                                    # End of input marker.
messagessourcereturnc                     [         R                  U5      nU(       d  [        R                  " [        5      eU R                  U R                  UR                  S5      UR                  S5      S9S9$ )zConstructs a `Source` message from a Cloud Storage object.

Args:
  messages: messages module, the GCFv2 message stubs.
  source: the Cloud Storage URL.

Returns:
  The resulting cloudfunctions_v2_messages.Source.
      bucketobjectstorageSource)_GCS_SOURCE_REGEXmatchr   FunctionsError_GCS_SOURCE_ERROR_MESSAGESourceStorageSourcegroup)r4   r5   r@   s      =lib/googlecloudsdk/command_lib/functions/v2/deploy/command.py_GetSourceGCSrG      sg     
!
!&
)%	

#
#$=
>>	**QA +  
 
     c                    [         R                  U5      nUc  [        R                  " [        5      eU R                  UR                  S5      UR                  S5      UR                  S5      S9nUR                  S5      nUR                  S5      nUR                  S5      nU(       a  XCl        OU(       a  Xcl        OU=(       d    SUl	        U R                  US	9$ )
zConstructs a `Source` message from a Cloud Source Repository reference.

Args:
  messages: messages module, the GCFv2 message stubs.
  source: the Cloud Source Repository reference.

Returns:
  The resulting cloudfunctions_v2_messages.Source.

project_id	repo_namepath)	projectIdrepoNamedircommitbranchtagmaster)
repoSource)_CSR_SOURCE_REGEXr@   r   rA   _CSR_SOURCE_ERROR_MESSAGE
RepoSourcerE   	commitShatagName
branchNamerC   )r4   r5   r@   repo_sourcerP   rQ   rR   s          rF   _GetSourceCSRr\      s     
!
!&
)%
]

#
#$=
>>##L){{;'
++f
 $ + ;;x &;;x &E#"
 $/xK	K	00rH   argsr   function_refkms_keyc                    UR                   n[        R                  " 5        n[        R                  " XcU R
                  5      nU R                  (       a[  [        R                  " XrU R                  5      nUR                  UR                  UR                  UR                  S9S9sSSS5        $ UR                  US9n	 UR                  R                  UR                  U	UR!                  5       R#                  5       S95      n
[        R,                  " XzR.                  5        UR                  U
R0                  S9sSSS5        $ ! [$        R&                   a  n[(        R*                  " X5        UeSnAff = f! , (       d  f       g= f)as  Constructs a `Source` message from a local file system path.

Args:
  args: The arguments that this command was invoked with.
  client: The GCFv2 Base API client.
  function_ref: The GCFv2 functions resource reference.
  source: The source path.
  kms_key: resource name of the customer managed KMS key | None

Returns:
  The resulting cloudfunctions_v2_messages.Source.
r:   r=   N)
kmsKeyName)generateUploadUrlRequestparent)MESSAGES_MODULE
file_utilsTemporaryDirectoryr   CreateSourcesZipFileignore_filestage_bucketUploadToStageBucketrC   rD   r;   nameGenerateUploadUrlRequestprojects_locations_functionsGenerateUploadUrl@CloudfunctionsProjectsLocationsFunctionsGenerateUploadUrlRequestParentRelativeNameapitools_exceptions	HttpErrorr	   ProcessExceptionUploadToGeneratedUrl	uploadUrlr>   )r]   r   r^   r5   r_   r4   tmp_dirzip_file_pathdest_objectgenerate_upload_url_requestdestes               rF   _GetSourceLocalr}      sd   & ##($$&'44))M 33
t'8'8k __ .. ''0@0@ /    '& %-$E$E %F %!	22DDUU)D#**,99; V 
 &&}nnE__4+=+=_>? '&2 !** ""1.3 '&s7   BE;0E; AE8E;E8E33E88E;;
F	existing_functionc           
      <   U R                   c4  Ub1  UR                  R                   R                  (       a  S[        5       4$ U R                   =(       d    SnUR                  nUR                  S5      (       a  [        XT5      [        S/5      4$ UR                  S5      (       a  [        XT5      [        S/5      4$ U R                  =(       d    UR                  R                  n[        R                  " XF5        [        U UUU[        X5      S9[        S/5      4$ )a  Parses the source bucket and object from the --source flag.

Args:
  args: arguments that this command was invoked with.
  client: The GCFv2 API client
  function_ref: The GCFv2 functions resource reference.
  existing_function: `cloudfunctions_v2_messages.Function | None`,
    pre-existing function.

Returns:
  A tuple `(function_source, update_field_set)` where
  - `function_source` is the resulting `cloudfunctions_v2_messages.Source`,
  - `update_field_set` is a set of update mask fields.
N.zgs://zbuild_config.sourcezhttps://)r_   )r5   buildConfigrT   	frozensetrd   
startswithrG   r\   runtimer   (ValidateDirectoryHasRequiredRuntimeFilesr}   _GetActiveKmsKey)r]   r   r^   r~   r5   r4   r   s          rF   
_GetSourcer     s   * kk

'

'
'
.
.
9
9
 ;;#&##(w*I7L6M,NNN$$*I7L6M,NNNllC/;;CCG88I 9 '()* *rH   c                 
   0 nU(       a  UR                   (       a  UR                   R                  (       ad  UR                   R                  R                  (       a?  UR                   R                  R                   H  nUR                  X4R                  '   M     [
        R                  " SU 5      n[
        R                  " U40 UD6n0 n0 nU(       aP  UR                   (       a?  [        R                  " UR                   R                  UR                   R                  5      n[        R                  " U 5      (       aU   [        R                  " UU [        R                   " 5       ["        R$                  " [        R                   " 5       5      5      nOUn[        R0                  " U5      u  p[        R0                  " U5      u  p[3        XU5      u  pn[5        XU5      u  nnn[7        X5      u  nn[9        U SS5      n[9        U SS5      n[;        5       nU R<                  (       a  UR?                  S5        U R@                  b  UR?                  S5        Ub  UR?                  S5        Ub  UR?                  S5        U RB                  c  U RD                  (       a  UR?                  S	5        U RF                  c  U RH                  (       a  UR?                  S
5        U RJ                  c  U RL                  b  UR?                  S5        U RN                  b  UR?                  S5        Xc:w  a  UR?                  S5        X:w  a  UR?                  S5        X:w  a  UR?                  S5        SnU RQ                  S5      (       a  UR?                  S5        O3U RQ                  S5      (       a  U RR                  nUR?                  S5        [T        RW                  UUUU5      nURY                  [[        U R@                  5      U RD                  (       a  SOU RB                  U RH                  (       a  SOU RF                  U RJ                  =(       d    U RL                  U RN                  UUUU R<                  =(       d    SURX                  R]                  [_        URa                  5       5       VVs/ s H*  u  nnURX                  R\                  Rc                  UUS9PM,     snnS9[        Rd                  " X5      [        Rf                  " XSS9U[i        U5      UUS9nU(       a  UUl5        UU4$ ! [&         a5  n	[(        R*                  " [,        R.                  " U	5      5         Sn	A	GNSn	A	ff = fs  snnf )a  Constructs a ServiceConfig message from the command-line arguments.

Args:
  args: arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.
  existing_function: the existing function.

Returns:
  A tuple `(service_config, updated_fields_set)` where
  - `service_config` is the resulting
  `cloudfunctions_v2_messages.ServiceConfig`.
  - `updated_fields_set` is a set of update mask fields.
zenv-varsNconcurrencycpuz-service_config.all_traffic_on_latest_revisionzservice_config.available_memoryz/service_config.max_instance_request_concurrencyzservice_config.available_cpuz!service_config.max_instance_countz!service_config.min_instance_countz$service_config.service_account_emailzservice_config.timeout_secondsz$service_config.environment_variablesz+service_config.secret_environment_variableszservice_config.secret_volumesclear_binary_authorizationz*service_config.binary_authorization_policybinary_authorizationr&   valueadditionalPropertiesT)normalize_for_v2)availableMemorymaxInstanceCountminInstanceCountserviceAccountEmailtimeoutSecondsingressSettingsvpcConnectorvpcConnectorEgressSettingsallTrafficOnLatestRevisionenvironmentVariablessecretEnvironmentVariablessecretVolumesmaxInstanceRequestConcurrencyavailableCpubinaryAuthorizationPolicydirectVpcEgress)6serviceConfigr   r   r   r&   r   GetMapFlagsFromArgsApplyMapFlagssecrets_utilGetSecretsAsDictr   r   r   IsArgsSpecified
ApplyFlagsapi_util
GetProjectprojects_utilGetProjectNumberr   core_exceptionsreraiser   rA   SplitSecretsDict_GetVpcAndVpcEgressSettings_GetDirectVpcNetworkSettings_GetIngressSettingsgetattrset!serve_all_traffic_latest_revisionaddmemorymax_instancesclear_max_instancesmin_instancesclear_min_instancesrun_service_accountservice_accounttimeoutIsKnownAndSpecifiedr   r   unionServiceConfig_ParseMemoryStrToK8sMemoryEnvironmentVariablesValuesorteditemsAdditionalPropertySecretEnvVarsToMessagesSecretVolumesToMessages_ValidateK8sCpuStrdirectVpcNetworkInterface)r]   r4   r~   old_env_varsadditional_propertyenv_var_flagsenv_varsold_secretsnew_secretserrorold_secret_env_varsold_secret_volumessecret_env_varssecret_volumesvpc_connectorvpc_egress_settingsvpc_updated_fieldsnetwork_interfacesdirect_vpc_egressdirect_vpc_updated_fieldsingress_settingsingress_updated_fieldsr   r   updated_fieldsbinary_authorization_policyservice_updated_fieldsr&   r   service_configs                                 rF   _GetServiceConfigr   E  s   & ,

)
)

)
)
>
>

)
)
>
>
S
S
 	''<<QQ 	 /B.G.Gl**+ 	R ..z4@-##LBMB(++,:://''BB''55K
 ##D))@"--







(
()<)<)>
?	k K,:,K,K-) %3$C$CK$P!/ "$2CD 9-&8 #43DE C')B .A-P**mT2+eT"#5.	++FG	[[89HI_56	#t'?'?:;	#t'?'?:;	)T-A-A-M=>	\\78=>+DE)67 $	:;;CD 677"&";";CD$??	 ))0=#77tT=O=O#77tT=O=O22Jd6J6J\\& !4

0
0
8D#11KK
 !'x~~'7 8	  !9*#u $$>>QQ R  !9	  L  ".!E!E
" !88
T %0%c* ;'; * .> /AN,
0	11  @j77>??@V s   ?AT) (1U+ )
U(3*U##U(r   c                     U b  U (       d  g[         R                  " [        U [         R                  5      nU(       d&  [        R
                  " SSR                  U 5      5      eUR                  S5      nUR                  S5      nUc  Sn[        [         Vs/ s H  oDR                  5       U4PM     sn5      nUR                  UR                  5       5      nU(       d&  [        R
                  " SSR                  U 5      5      eX6-   nU$ s  snf )aH  Parses user provided memory to kubernetes expected format.

Ensure --gen2 continues to parse Gen1 --memory passed in arguments. Defaults
as M if no unit was specified.

k8s format:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/generated.proto

Args:
  memory: input from `args.memory`

Returns:
  k8s_memory: str|None, in kubernetes memory format. GCF 2nd Gen control plane
    is case-sensitive and only accepts: value + m, k, M, G, T, Ki, Mi, Gi, Ti.

Raises:
  InvalidArgumentException: User provided invalid input for flag.
Nz--memoryz'Invalid memory value for: {} specified.suffixamountr+   !Invalid suffix for: {} specified.)rer@   _MEMORY_VALUE_PATTERNVERBOSEr   InvalidArgumentExceptionformatrE   dict_GCF_GEN2_UNITSupperget)r   r@   r   r   unituppercased_gen2_unitscorrected_suffixparsed_memorys           rF   r   r     s    & ^6
(((&"**
=%	

-
-=DDVL  ;;x &;;x & ^F (78

d8 +..v||~>	

-
-7>>vF  +-	 9s   Dr   c                    U c  g[         R                  " [        U [         R                  5      nU(       d&  [        R
                  " SSR                  U 5      5      eUR                  S5      =(       d    SnUR                  S5      nU(       a  US:X  a&  [        R
                  " SSR                  U 5      5      eU(       a0  U[        ;  a&  [        R
                  " SS	R                  U 5      5      eX2-   nU$ )
af  Validates user provided cpu to kubernetes expected format.

k8s format:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/generated.proto

Args:
  cpu: input from `args.cpu`

Returns:
  k8s_cpu: str|None, in kubernetes cpu format.

Raises:
  InvalidArgumentException: User provided invalid input for flag.
Nz--cpuz$Invalid cpu value for: {} specified.r    r   r   z!Invalid amount for: {} specified.r   )	r   r@   _CPU_VALUE_PATTERNr   r   r   r   rE   _GCF_GEN2_CPU_UNITS)r   r@   r   r   r   s        rF   r   r     s     	[
((%sBJJ
7%	

-
-7>>sC  ;;x &B&;;x &	6S=

-
-4;;C@  11

-
-4;;C@  /-	rH   c                 Z   U R                   (       a  S[        U(       a  S/O/ 5      pCOU R                  (       d  U R                  (       a  [	        X5      [        S/5      pCOU R
                  (       d"  U R                  (       d  U R                  (       a  [        X5      [        S/5      pCO6U(       a  UR                  [        5       pCO[        R                  " / SQS5      eU R                  S5      (       a%  [        XU5      u  pVXSl        UR                  U5      nU(       a:  [         R"                  " UR$                  5      (       a  [&        R(                  " 5         U(       aE  [         R*                  " UR$                  5      (       a   [&        R,                  " UR.                  5        X44$ )a  Constructs an EventTrigger message from the command-line arguments.

Args:
  args: The arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.
  existing_function: The pre-existing function.

Returns:
  A tuple `(event_trigger, update_fields_set)` where:
  - `event_trigger` is a `cloudfunctions_v2_messages.EventTrigger` used to
  request events sent from another service,
  - `updated_fields_set` is a set of update mask fields.
Nevent_trigger)z--trigger-topicz--trigger-bucketz--trigger-http--trigger-eventz--trigger-event-filtersz9You must specify a trigger when deploying a new function.r!   )trigger_httpr   trigger_eventtrigger_resource_GetEventTriggerForEventTypetrigger_topictrigger_buckettrigger_event_filters_GetEventTriggerForOthereventTriggercalliope_exceptionsOneOfArgumentsRequiredExceptionIsSpecified	_GetRetryretryPolicyr   trigger_typesIsPubsubType	eventTyper   'ensure_pubsub_sa_has_token_creator_roleIsAuditLogType#ensure_data_access_logs_are_enabledeventFilters)r]   r4   r~   r   updated_fields_setretry_policyretry_updated_fields          rF   _GetEventTriggerr  6  sU   $ 
(,i.B/% T22(D)/"# & T00D4N4N(@)/"# &
 

(
(
+ (
  ?? F	 	 
g(1$-(P%L ,+112EF}11-2I2IJJ779}33M4K4KLL33M4N4NO		**rH   c                    U R                   nU R                  nU R                  =(       d    U R                  nU[        R
                  ;   aI  [        R                  " U5      nUR                  [        R                  [        U5      UU R                  S9$ U[        R                  ;   d  U[        R                  ;   as  [        R                  R!                  U5      R"                  n[        R                  R%                  X"5      nUR                  UUR'                  SUS9/UU R                  S9$ [(        R*                  " SSR-                  U5      5      e)a*  Constructs an EventTrigger message from the command-line arguments.

Args:
  args: The arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.

Returns:
  A `cloudfunctions_v2_messages.EventTrigger`, used to request
    events sent from another service.
)r  pubsubTopicr   triggerRegionr;   	attributer   )r  r  r   r  r   zOEvent type {} is not supported by this flag, try using --trigger-event-filters.)r   r   trigger_service_accountr   r   PUBSUB_MESSAGE_PUBLISH_TYPESapi_util_v1ValidatePubsubTopicNameOrRaiseEventTriggerEA_PUBSUB_MESSAGE_PUBLISHED_BuildFullPubsubTopictrigger_locationEVENTARC_STORAGE_TYPES!EVENTFLOW_TO_EVENTARC_STORAGE_MAPr   BucketReferenceFromUrlr;   r   EventFilterr   r   r   )r]   r4   r   r   service_account_emailpubsub_topicbucket_namestorage_event_types           rF   r   r   u  sG    $$-**66N$:N:Nh;;;==>NOL  66),71++	 !   x666	(DD	D ..667GHOOK!CCGG   $  8; G
 2++ !   
-
-	$$*F=$9 rH   c                    / nSnSnU R                   =(       d    U R                  nU R                  nU R                  (       a'  [        R
                  n[        U R                  5      nGOU R                  (       a@  U R                  SS R                  S5      n[        R                  nUR                  SUS9/nOU R                  (       a  U R                  R                  S5      nU R                  R                  5        VV	s/ s H  u  pUS:w  d  M  UR                  XS9PM     nnn	U R                  (       aN  Sn
UR                  U R                  R                  5        VV	s/ s H  u  pUR                  XU
S9PM     sn	n5        SnU R                   (       a2  U R"                  R                   R%                  5       R'                  5       nUR)                  UUUUUUS	9$ s  sn	nf s  sn	nf )
a+  Constructs an EventTrigger when using `--trigger-[bucket|topic|filters]`.

Args:
  args: arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.

Returns:
  A `cloudfunctions_v2_messages.EventTrigger` used to request
    events sent from another service.
N   /r;   r  typezmatch-path-pattern)r  r   operator)r  r  r  r   channelr  )r  r   r   r   r   r  r  r   rstripEA_STORAGE_FINALIZEr%  r  r   r   "trigger_event_filters_path_patternextendtrigger_channelCONCEPTSParserq   r  )r]   r4   event_filters
event_typer'  r&  r   r;   attrvalr.  r4  s               rF   r  r    s    -*,66N$:N:N**	55J(););<L  $++C0F--J))HF)KLM!!++//7J 3399;;ID6> 	8t7;  
 ..%hBBHHJJid 

8

LJ 	
 /	mm3399;HHJO			 /$ 
 
 !s   G"G"%G(
r   c                     Uc  [         R                  " [        5      eU R                  (       a'  UR                  R                  S5      [        S/5      4$ UR                  R                  S5      [        S/5      4$ )a  Constructs an RetryPolicy enum from --(no-)retry flag.

Args:
  args: arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.
  event_trigger: trigger used to request events sent from another service.

Returns:
  A tuple `(retry_policy, update_fields_set)` where:
  - `retry_policy` is the retry policy enum value,
  - `update_fields_set` is the set of update mask fields.
RETRY_POLICY_RETRYzeventTrigger.retryPolicyRETRY_POLICY_DO_NOT_RETRY)r   rA   !_INVALID_RETRY_FLAG_ERROR_MESSAGEr!   r  RetryPolicyValueValuesEnumr   )r]   r4   r   s      rF   r  r    s    $ 

#
#$E
FF	ZZ  ;;,-./ /
   ;;#,-./ /rH   r'  c                 L    SR                  [        R                  " 5       U 5      $ )Nzprojects/{}/topics/{})r   r   r   )r'  s    rF   r  r    s    	 	'	'(;(;(=|	LLrH   c                    [        U UUU5      u  pE0 nU(       a  UR                  (       a  UR                  R                  (       ad  UR                  R                  R                  (       a?  UR                  R                  R                   H  nUR                  XgR
                  '   M     [        R                  " SU 5      n[        R                  " U40 UD6n	[        5       n
X:w  a  U
R                  S5        U R                  b  U
R                  S5        U R                  b  U
R                  S5        U R                  (       a  SOU R                  nU R                  c  U R                  (       a  U
R                  S5        U R                  nUc  U R                   (       a  U
R                  S5        UR"                  nSnSnU R%                  S5      (       aQ  U
R'                  S	5        U R(                  S
:X  a  UR+                  5       nU R(                  S:X  a  UR-                  5       n[.        R1                  XZ5      nUR3                  U R                  U R                  UUUR2                  R5                  [7        U	R9                  5       5       VVs/ s H*  u  nnUR2                  R4                  R;                  UUS9PM,     snnS9UUUS9U4$ s  snnf )aQ  Constructs a BuildConfig message from the command-line arguments.

Args:
  args: arguments that this command was invoked with.
  client: The GCFv2 API client.
  function_ref: The GCFv2 functions resource reference.
  existing_function: The pre-existing function.

Returns:
  The resulting build config and the set of update mask fields.
zbuild-env-varsz"build_config.environment_variablesNzbuild_config.entry_pointzbuild_config.runtimezbuild_config.worker_poolzbuild_config.service_accountruntime_update_policy)z$build_config.automatic_update_policyz$build_config.on_deploy_update_policy	automaticz	on-deployr   r   )
entryPointr   r5   
workerPoolr   serviceAccountautomaticUpdatePolicyonDeployUpdatePolicy)r   r   r   r   r   r&   r   r   r   r   r   entry_pointr   clear_build_worker_poolbuild_worker_poolbuild_service_accountclear_build_service_accountrd   r  updaterB  AutomaticUpdatePolicyOnDeployUpdatePolicyr   r   BuildConfigr   r   r   r   )r]   r   r^   r~   function_sourcesource_updated_fieldsold_build_env_varsr   build_env_var_flagsbuild_env_varsr   worker_poolr   r4   automatic_update_policyon_deploy_update_policybuild_updated_fieldsr&   r   s                      rF   _GetBuildConfigr[    s   " ,6
	,(/ 

'
'

'
'
<
<

'
'
<
<
Q
Q
 	%%::OO 	 5H4M4M001 	P !445EtL))/. 5.);<	!12	\\-.44$:P:P+	'4+G+G12../ D$D$D56##(  	-..   !![0 ( > > @!![0 ( = = ?")>O%%,,  '33MM
 %+>+?+?+A$B	$ %Cjc5 &&@@SSU T  %C	$  N   ) 76  " %
 $s   1Kc                     U R                  S5      (       a  U R                  $ U R                  S5      (       a  gU(       d  S$ UR                  $ )zRetrives KMS key applicable to the deployment request.

Args:
  args: arguments that this command was invoked with.
  existing_function: the pre-existing function.

Returns:
  Either newly passed or pre-existing KMS key.
r_   clear_kms_keyN)r  r_   ra   )r]   r~   s     rF   r   r   f  sG     
i  <<((&H,=,H,HHrH   c                     U R                   (       a_  [        R                  " SUR                  R                  [
        R                  S9R                  U R                   5      nU[        S/5      4$ S[        5       4$ )as  Constructs ingress setting enum from command-line arguments.

Args:
  args: arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.

Returns:
  A tuple `(ingress_settings_enum, updated_fields_set)` where:
  - `ingress_settings_enum` is the ingress setting enum value,
  - `updated_fields_set` is the set of update mask fields.
r   arg_namemessage_enumcustom_mappingszservice_config.ingress_settingsN)	r   r   ChoiceEnumMapperr   IngressSettingsValueValuesEnumr   INGRESS_SETTINGS_MAPPINGGetEnumForChoicer   )r]   r4   ingress_settings_enums      rF   r   r   z  sq     
%66#++JJ66 t,,-	 
 !)-N,O"PPPrH   c                    U R                   (       a  SS[        SS/5      4$ [        5       nSnU R                  (       aD  U R                  R                  R                  5       R                  5       nUR                  S5        OIU(       aB  UR                  (       a1  UR                  R                  (       a  UR                  R                  nSnU R                  (       a  U(       d  [        R                  " SS5      e[        R                  " SUR                  R                   ["        R$                  S9R'                  U R                  5      nUR                  S5        XE[        U5      4$ )a  Constructs vpc connector and egress settings from command-line arguments.

Args:
  args: The arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.
  existing_function: The pre-existing function.

Returns:
  A tuple `(vpc_connector, egress_settings, updated_fields_set)` where:
  - `vpc_connector` is the name of the vpc connector,
  - `egress_settings` is the egress settings for the vpc connector,
  - `updated_fields_set` is the set of update mask fields.
Nzservice_config.vpc_connectorz,service_config.vpc_connector_egress_settingszvpc-connectorzCFlag `--vpc-connector` is required for setting `--egress-settings`.egress_settingsr_  )clear_vpc_connectorr   r   r   r5  r6  rq   r   r   r   ri  r   RequiredArgumentExceptionr   rc  r   )VpcConnectorEgressSettingsValueValuesEnumr   EGRESS_SETTINGS_MAPPINGrf  )r]   r4   r~   update_fields_setr   ri  s         rF   r   r     s3   , 
*:
 	  e-	MM//557DDFM89

)
)

)
)
6
6%33@@M/	00

O 
  00"++UU55 t++,	 
 HI	3D)E	EErH   c                 Z   [        U SS5      (       a  SS[        SS/5      4$ [        5       nSnSnU(       aE  UR                  (       a4  UR                  R                  (       a  UR                  R                  S   n[        U SS5      n[        U SS5      n[        U SS5      n[        U S	S5      n	U=(       d    U=(       d    U=(       d    U	n
U
(       a  UR                  5       n/ Ul        U(       a<  UR                  Ul        UR                  Ul        UR                  =(       d    / Ul        U(       a  Xdl        U(       a  Xtl        U(       a  Xl        OU	(       a  / Ul        UR                  S5        O	U(       a  UnSn[        U S
S5      (       a  U(       d  [        R                  " SS5      e[        R                  " S
UR                  R                  [         R"                  S9R%                  U R&                  5      nUR                  S5        U(       a  U/OSnX[        U5      4$ )a  Constructs direct VPC network settings from command-line arguments.

Args:
  args: The arguments that this command was invoked with.
  messages: messages module, the GCFv2 message stubs.
  existing_function: The pre-existing function.

Returns:
  A tuple `(network_interfaces, direct_vpc_egress, updated_fields_set)`
  where:
  - `network_interfaces` is the list containing configuration of the Direct
  VPC,
  - `direct_vpc_egress` is the egress settings for the Direct VPC network,
  - `updated_fields_set` is the set of update mask fields.
clear_networkNz+service_config.direct_vpc_network_interfacez service_config.direct_vpc_egressr   networksubnetnetwork_tagsclear_network_tagsr   zdirect-vpc-egressz9Direct VPC is required for setting `--direct-vpc-egress`.r_  )r   r   r   r   r   DirectVpcNetworkInterfacetagsrq  
subnetworkr   r   rk  r   rc  r   DirectVpcEgressValueValuesEnumr   "DIRECT_VPC_EGRESS_SETTINGS_MAPPINGrf  r   )r]   r4   r~   rn  network_interfaceexisting_network_interfacerq  rr  rs  rt  has_direct_vpc_flagsr   r   s                rF   r   r     s   0 T?D))9.
 	  e#

)
)

)
)
C
C 	''AA!D  D)T*'44(&~t4,t%94@ PFPlP>P ::<!"<"D"D%?%J%J"9>>D"")%+"+	!GH!2T&--00

E 
 "22$++JJ@@ t--.	 
 <=.?)*T		:K0L	LLrH   c                     [          H8  u  pU R                  U5      (       d  M  [        R                  " [        U-  5      e   g)zDEnsures that only the arguments supported in V2 are passing through.N)_V1_ONLY_FLAGSr   r   rA   _V1_ONLY_FLAG_ERROR)r]   flag_variable	flag_names      rF   _ValidateV1OnlyFlagsr  /  s7    "0m..%%&9I&EFF #1rH   c                 D   U(       a  0 nO[         [        0n[        R                  R	                  XS9nUR                  UR                  R                  U(       a  UR                  OS5      nUR                  (       a  UR                  [        S/5      4$ S[        5       4$ )au  Constructs labels from command-line arguments.

Args:
  args: The arguments that this command was invoked with
  messages: messages module, the GCFv2 message stubs.
  existing_function: The pre-existing function.

Returns:
  A tuple `(labels, updated_fields_set)` where:
  - `labels` is functions labels metadata,
  - `updated_fields_set` is the set of update mask fields.
)required_labelsNlabels)_DEPLOYMENT_TOOL_LABEL_DEPLOYMENT_TOOL_VALUEr   DiffFromUpdateArgsApplyFunctionLabelsValuer  needs_updater   )r]   r4   r~   r  labels_difflabels_updates         rF   
_GetLabelsr  6  s    " O-/EFO  //
 0 + ####"3- H:!666rH   functionc                    [        5       nU(       a  UR                  OSUl        U R                  S5      (       d  U R                  S5      (       a)  U R                  S5      (       a  SOU R                  Ul        Ub  UR                  UR                  :w  a?  U R                  b!  [        R
                  " UR                  U5        UR                  S5        U$ )a  Sets CMEK-related fields on the function.

Args:
  args: arguments that this command was invoked with.
  function: `cloudfunctions_v2alpha_messages.Function`, the recently created
    or updated GCF function.
  existing_function: `cloudfunctions_v2_messages.Function | None`, the
    pre-existing function.
  function_ref: resource reference.

Returns:
  A set of update mask fields.
Nr_   r]  kms_key_name)r   ra   r  r_   r	   ValidateKMSKeyForFunctionr   )r]   r  r~   r^   r   s        rF   _SetCmekFieldsr  X  s    & 5.&7""T  
i  D$4$4_$E$E  11t||  			 1 < <	<||))(*=*=|L~&	rH   c                 j   [        5       nU(       a  UR                  R                  OSUR                  l        U R                  S5      (       d  U R                  S5      (       a  U R                  S5      (       a  SOU R                  n[
        R                  " U5      UR                  l        Ub.  UR                  R                  UR                  R                  :w  a  UR                  S5        UR                  (       a2  UR                  R                  (       d  [        R                  " SS5      eU$ )a`  Sets user-provided docker repository field on the function.

Args:
  args: arguments that this command was invoked with
  function: `cloudfunctions_v2_messages.Function`, recently created or updated
    GCF function.
  existing_function: `cloudfunctions_v2_messages.Function | None`,
    pre-existing function.

Returns:
  A set of update mask fields.
Ndocker_repositoryclear_docker_repositoryzbuild_config.docker_repositoryz--docker-repositoryzTA Docker repository must be specified when a KMS key is configured for the function.)r   r   dockerRepositoryr  r  r	   NormalizeDockerRepositoryFormatr   ra   r  rk  )r]   r  r~   r   updated_docker_repositorys        rF   _SetDockerRepositoryConfigr  }  s   " 5. 
 ##44 '
 
)**d.>.>/ /
 566 	##  	112KL ) 	!00((99: 9:!5!5!F!F

7
7!  
rH   rk   c                 J    [         R                  " SR                  U 5      SS9$ )zMPrompts the user to allow unauthenticated invocations for the given function.z7Allow unauthenticated invocations of new function [{}]?F)prompt_stringdefault)r   PromptContinuer   )rk   s    rF   (_PromptToAllowUnauthenticatedInvocationsr    s&    		"	"
C
J
J4
P	
 rH   
gcf_clientc                    U R                   nU R                  nUR                  UR                  5       R	                  5       UR                  5       US9nUR                  R                  U5      nSn[        R                  " X4Xg[        5        g)a
  Create a function.

This does not include setting the invoker permissions.

Args:
  gcf_client: The GCFv2 API client.
  function_ref: The GCFv2 functions resource reference.
  function: `cloudfunctions_v2_messages.Function`, The function to create.

Returns:
  None
)rc   
functionIdr  zDeploying functionN)r   r4   5CloudfunctionsProjectsLocationsFunctionsCreateRequestrp   rq   Namerm   Creater   WaitForOperation_EXTRA_STAGES)r  r^   r  r   r4   create_request	operationoperation_descriptions           rF   _CreateAndWaitr    s    " &  (DD$$&335!&&( E   1188H).
	-rH   r  c                 b   U R                   nU R                  nU(       aq  UR                  UR                  5       SR	                  [        U5      5      US9nUR                  R                  U5      nSn[        R                  " XEXx[        5        g[        R                  R                  S5        g)a=  Update a function.

This does not include setting the invoker permissions.

Args:
  gcf_client: The GCFv2 API client.
  function_ref: The GCFv2 functions resource reference.
  function: `cloudfunctions_v2_messages.Function`, The function to update.
  updated_fields_set: A set of update mask fields.

Returns:
  None
,)rk   
updateMaskr  z$Updating function (may take a while)zNothing to update.N)r   r4   4CloudfunctionsProjectsLocationsFunctionsPatchRequestrq   joinr   rm   Patchr   r  r  r   statusPrint)	r  r^   r  r  r   r4   update_requestr  r  s	            rF   _UpdateAndWaitr    s    & &  (EE**,xx'9 :; 	F 	
  3399.IIB)M JJ)*rH      i  )max_retrialssleep_msc                      U R                  UR                  5       5      $ ! [        R                   a  n[        R
                  " SU5      eSnAff = f)z Retrieves a function with retry.z"Function not found after retries, N)GetFunctionrq   rr   rs   r   rA   )r   r^   r   s      rF   _GetFunctionWithRetryr    sN    Ql779::		&	& Q

#
#$H%
PPQs   ! AAArelease_trackc           	      	   [         R                  " US9nUR                  nU R                  R                  R                  5       n[        U 5        UR                  UR                  5       5      nUR                  UR                  5      R                   Vs0 s H7  n[        UR                  5      S:X  d  M  UR                  SUR                  0_M9     nnUSL nU(       a  U R                  (       d  [         R"                  " 5       (       d  [$        R&                  " SS5      e[)        UR+                  5       5      n	[         R,                  " U	SS9n
X   U l        [.        R0                  R3                  S	R5                  U R                  5      5        [6        R8                  " 5       (       a7  U(       a0  [        UR                  5      S
:X  a  [:        R<                  " SS5      eU R                  =(       d    UR>                  R                  nU(       a  X;  a  [:        R<                  " SU S35      eX;   a0  X{   S   (       a$  X{   S    H  n[.        R@                  " U5        M     U(       aK  URB                  (       a:  URB                  RD                  nUb!  U(       d  [.        R@                  " [F        5        [I        XU5      u  p[K        U URL                  UU5      u  nn[O        XU5      u  nn[Q        XU5      u  nnURS                  UR                  5       UUUUS9n[U        U UXT5      n[W        U UU5      n[X        RZ                  " S5        [X        RZ                  " S5        [X        RZ                  " S5        SnU R]                  S5      (       a  U R^                  nO#U(       a  U(       d  [a        U Rb                  5      n[d        Rf                  " [h        Rj                  " 5       UR                  URl                  5        U(       a  [o        X$U5        O'[p        Rs                  UUUUUU5      n[u        X$UU5        [w        X$5      nU(       a  U(       d  U(       a:  U R]                  S5      (       a$  [x        Rz                  " UU[|        R~                  S9  [.        R0                  R3                  SSR5                  UR                  UR                  5       [h        Rj                  " 5       5      -   5        U$ s  snf )z/Runs a function deployment with the given args.)r  GEN_2warningsNr   z/Flag `--runtime` is required for new functions.zPlease select a runtime:
)messagezCTo skip this prompt, add `--runtime={}` to your command next time.
GEN_1z--gen2zAFunction already exists in 1st gen, can't change the environment.z	--runtimezt is not a supported runtime on GCF 2nd gen. Use `gcloud functions runtimes list` to get a list of available runtimes)rk   r   r  r   r  zrun.googleapis.comzcloudbuild.googleapis.comzartifactregistry.googleapis.comallow_unauthenticated)add_bindingmemberz6You can view your function in the Cloud Console here: zDhttps://console.cloud.google.com/functions/details/{}/{}?project={}
)A	client_v2FunctionsClientr4   r5  rk   r6  r  r  rq   ListRuntimeslocationsIdruntimesstrenvironmentr  r   r   	CanPromptr  rk  r   keysPromptChoicer   r  r  r   r   ShouldUseGen2r   r   r   warningr   r   (_LATEST_REVISION_TRAFFIC_WARNING_MESSAGEr  r[  r   r   r  r  r  r  r   PromptToEnableApiIfDisabledr  r  r  NAMEr   2ValidateDefaultBuildServiceAccountAndPromptWarningr   r   rF  r  r   r   r  r  r   AddOrRemoveInvokerBindingr   "ALLOW_UNAUTH_POLICY_BINDING_MEMBERr  )r]   r  r   r4   r^   r~   rgen2_runtimesis_new_functionr  idxr   w"has_all_traffic_on_latest_revisionr   trigger_updated_fieldsbuild_configrZ  r   r   labels_valuelabels_updated_fieldsr  cmek_updated_fields docker_repository_updated_fieldsr  r   s                              rF   Runr    si    $$=A&__(##))+,t(()B)B)DE ""<#;#;<EEE!	Q]]	w	& 'affz1::&&E   &-/T\\!!99
F  m((*+H

!
!6C =DLJJN		 

++
,
7

-
-K  LLA-99AA'-

-
-i ) )  -"8"D#J/	kk!n 0 ,::''BB ' 	+62	kk:;*:
'+'- (7
mm	($,$ ,=
',(.( )3
')%,%
 $$& "  ( '
H' &@
H'&" ,,-AB,,-HI,,-NO	-.. 66}DTYYOII!!
 62__(N 6>B"68(
 
 



2
3
3&&)$GG **>Ov

"
"L$5$5$79L9L9N 
/as   S97S9)N)__doc__r   r   typingr   r   r   apitools.base.pyr   r   rr    googlecloudsdk.api_lib.functionsr   r	   r
   r   #googlecloudsdk.api_lib.functions.v1r   r  #googlecloudsdk.api_lib.functions.v2r   r  	api_typesr   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   calliope_baser  r   #googlecloudsdk.calliope.arg_parsersr   #googlecloudsdk.command_lib.eventarcr	  $googlecloudsdk.command_lib.functionsr   r   r   r   r   r   'googlecloudsdk.command_lib.functions.v2r   #googlecloudsdk.command_lib.projectsr   googlecloudsdk.command_lib.runr   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   r   googlecloudsdk.core.utilr    re   r!   !_SIGNED_URL_UPLOAD_ERROR_MESSSAGEcompiler?   rB   rU   rV   r>  r  r~  r  r  r  Stage_ARTIFACT_REGISTRY_STAGE_SERVICE_ROLLBACK_STAGE_TRIGGER_ROLLBACK_STAGEr  r   r   r   r   
ModuleTyper  rC   rG   r\   	NamespaceBaseApiClientResourcer}   r  r   r   r   r   r   r  r  r   r  RetryPolicyr  r  r  rQ  r[  r   IngressSettingsr   VpcConnectorEgressSettingsr   listru  DirectVpcEgressr   r  r  r  r  r  boolr  r  r  RetryOnExceptionr  ReleaseTrackr   rH   rF   <module>r     s   O 
  - - % > ; 6 D C C : B @ 7 9 E 5 A F 6 < 9 ? E < ? E @ : 9 = # ) 2 8 8 * "
 JJ23   JJ	 Q  K "
. ) D  + %  ,111  +00+  +00, 
  eo-   E,, c i>N>N *"1E,, "1c "1i>N>N "1T "3?

%
%3?""3? $$3? 	3?
 c]3? 3?l.*

%
%.*"".* $$.*  	 2 23	.*
 8I$$%y~56.*bS2

%
%S2S2  	 2 23S2 9""IcN23	S2l/s /x} /d&C &HSM &R<+

%
%<+<+  	 2 23<+ 8I**+Ys^;<	<+~1

%
%1161A1A11h3

%
%3161A1A33l/

%
%// I223/ 9  )C.01	/@M M M`

%
%`%%` $$`  	 2 23	`
 9  )C.01`FI

%
%I	 2 23I c]I(

%
%161A1A
8I--.	#>?2<F

%
%<F<F SMY112cN	<F~ZM

%
%ZMZM T)5567Y&&'cN	ZMzG0:: Gt G

%
%  	 2 23 8I))*IcN:;	D"

%
%"  "  	 2 23" $$	"
 s^"J0

%
%0  0  	 2 230 s^	0f3 4 ))$$    
	D%+))%+$$%+   %+ "#	%+
 
%+P Q6Q 7Q]

%
%]6C6P6P]]rH   