
                         h   S r SSK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  SSKJr  SSKJr  \R:                  " S5      rSS0rSr \RB                  " \RD                  RF                  5       " S S\RH                  5      5       r%g)zDeploys a function locally.    N)client)base)
exceptions)parser_extensions)flags)source_util)util)env_vars_util)map_util)log)
console_io)filesa      Your function {name} is serving at localhost:{port}.

    To call this locally deployed function using gcloud:
    gcloud alpha functions local call {name} [--data=DATA] | [--cloud-event=CLOUD_EVENT]

    To call local HTTP functions using curl:
    curl -m 60 -X POST localhost:{port} -H "Content-Type: application/json" -d '{{}}'

    To call local CloudEvent and Background functions using curl, please see:
    https://cloud.google.com/functions/docs/running/calling
    DESCRIPTIONzE
        `{command}` Deploy a Google Cloud Function locally.
        zus-central1c                   j   \ rS rSrSr\r\S 5       rS r	S\
R                  S\R                  \\R                  4   4S jrS\
R                  S\R                  \\4   S\R                  \\4   4S	 jrS
\R                  \\4   S\R$                  \   SS4S jrS\R$                  \   S\4S jrSrg)Deploy9   z'Deploy a Google Cloud Function locally.c                    [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        [        R
                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U SS9  g )NT)hidden)local_flagsAddDeploymentNameFlagAddPortFlagAddBuilderFlag	flag_utilAddEntryPointFlagAddRuntimeFlagAddIgnoreFileFlagAddSourceFlagr
   AddBuildEnvVarsFlagsAddUpdateEnvVarsFlagsAddGen2Flag)parsers    %lib/surface/functions/local/deploy.pyArgsDeploy.Args?   s    %%f-F#v&'V$'F#&&v.''/ &.    c                    [         R                  " 5         U R                  U5      n[        R                  " [
        R                  R                  S9n[        UR                  [        5      R                   Vs1 s H  oDR                  iM     sn5      nUR                  S5      nU R                  Xe5        UR                  S   n[         R"                  " 5        n[$        R&                  " UUR                  SS5      UR                  S5      S9n	[         R(                  " UUR                  S5      UR                  S	5      UR                  S
5      U	UR                  S5      S9  S S S 5        [         R*                  " UUR                  SS5      UR                  S5      US9  [,        R.                  R1                  [2        R5                  XvR                  SS5      S95        g s  snf ! , (       d  f       N= f)N)release_trackr   r   source.zignore-file)source_pathignore_file	--builder	--runtime--entry-pointbuild-env-vars)namebuilderruntimeentry_pointpathbuild_env_varsz--port8080env-vars)r0   portenv_varslabels)r0   r8   )r	   ValidateDependencies_CreateAndUpdateLabels	client_v2FunctionsClientr   ReleaseTrackALPHAsortedListRuntimes_REGIONruntimesr0   get_ValidateFlagsNAME
file_utilsTemporaryDirectoryr   CreateSourcesZipFileRunPackRunDockerContainerr   statusPrint_LOCAL_DEPLOY_MESSAGEformat)
selfargsr:   r   rrD   r   r0   tmp_dirr4   s
             r"   Run
Deploy.RunQ   s   ((.F&&T5F5F5L5LMFv':':7'C'L'LM'L!vv'LMNHJJwE(99Q<D		&	&	(G--
ii#.ii.d
 ll 99[1 99[1$yy9"(**-=">@ 
) 	!&8V!<%+ZZ
%;#)+
 JJ*11		(F3 2 5 61 N 
)	(s   9G%BG**
G8rR   returnc                     0 n[         R                  " UR                  S   5      n[        R                  " UR                  SS5      5      n[        R                  " UR                  SS5      5      n[        R                  " UR                  SS5      5      nU R                  X5      US'   [        R                  " SU5      n[        R                  " U40 UD6US'   [        R                  " SU5      n[        R                  " U40 UD6US'   U$ )Nr   r   z{}r7   r/   )
r	   GetDockerContainerLabelsrG   jsonloadsrE   _ApplyNewFlagsr   GetMapFlagsFromArgsApplyMapFlags)	rQ   rR   r:   
old_labels	old_flagsold_env_varsold_build_env_varsr9   r5   s	            r"   r<   Deploy._CreateAndUpdateLabelsq   s    F..tyy|<J

:>>'489I::jnnZ>?LJNN3CT$JK))$:F7O++J=H!//IIF:112BDIN'55 ., .F Mr%   r`   c                     0 UEUR                  5       EnUR                  5        VVs0 s H  u  pESU;   a  M  SU;   a  M  XE_M     nnnU$ s  snnf )NrG   r7   )GetSpecifiedArgsitems)rQ   rR   r`   r   kvs         r"   r\   Deploy._ApplyNewFlags   s^    4y4D1134E % 5fqaK #-? QTE 5L5s   AA Ar   rD   Nc                    SU;  a  [         R                  " SS5      eSU;  a  SU;  a  U R                  U5      US'   UR                  S5      U;  a4  [        R
                  R                  S5        U R                  U5      US'   g g )Nr.   zFlag `--entry-point` required.r,   r-   z'--runtime must be one of the following:)r   RequiredArgumentException_PromptUserForRuntimerE   r   outrN   )rQ   r   rD   s      r"   rF   Deploy._ValidateFlags   s    e#00
;  %Ku$<55h?eKyyX-	ggmm=>55h?eK .r%   c                     [         R                  " 5       (       d  [        R                  " SS5      e[         R                  " USS9nX   $ )Nr-   z5Flag `--runtime` required when builder not specified.zPlease select a runtime:
)message)r   	CanPromptr   rk   PromptChoice)rQ   rD   idxs      r"   rl   Deploy._PromptUserForRuntime   sL    !!00
N  
!
!6C =r%    )__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr#   rU   r   	NamespacetypingDictstrAnyr<   r\   SetrF   rl   __static_attributes__ru   r%   r"   r   r   9   s    / -/ /"6@#--28++c6::o2N(!2!<!<  &CH 5:@++c3h:O@&++c3h"7 @%zz#@37@FJJsO  r%   r   )&rz   rZ   textwrapr   #googlecloudsdk.api_lib.functions.v2r   r=   googlecloudsdk.callioper   r   r   $googlecloudsdk.command_lib.functionsr   r   r   *googlecloudsdk.command_lib.functions.localr   r	   .googlecloudsdk.command_lib.functions.v2.deployr
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   rH   dedentrO   r{   rC   ReleaseTracksr?   r@   Commandr   ru   r%   r"   <module>r      s    "    C ( . 5 C < K ; H 9 # 2 8 ! ) 	   
  D%%++,gT\\ g -gr%   