
    3                        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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   \RB                  " S5      r"SS0r#Sr$\RJ                  " \RL                  RN                  5       " S S\RP                  5      5       r)g)zDeploys a function locally.    )absolute_import)division)unicode_literalsN)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)Deploy<   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.ArgsB   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)r3   portenv_varslabels)r3   r;   )r   ValidateDependencies_CreateAndUpdateLabels	client_v2FunctionsClientr   ReleaseTrackALPHAsortedListRuntimes_REGIONruntimesr3   get_ValidateFlagsNAME
file_utilsTemporaryDirectoryr   CreateSourcesZipFileRunPackRunDockerContainerr   statusPrint_LOCAL_DEPLOY_MESSAGEformat)
selfargsr=   r   rrG   r
   r3   tmp_dirr7   s
             r%   Run
Deploy.RunT   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rU   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{}r:   r2   )
r   GetDockerContainerLabelsrJ   jsonloadsrH   _ApplyNewFlagsr   GetMapFlagsFromArgsApplyMapFlags)	rT   rU   r=   
old_labels	old_flagsold_env_varsold_build_env_varsr<   r8   s	            r%   r?   Deploy._CreateAndUpdateLabelst   s    F..tyy|<J

:>>'489I::jnnZ>?LJNN3CT$JK))$:F7O++J=H!//IIF:112BDIN'55 ., .F Mr(   rc   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 )NrJ   r:   )GetSpecifiedArgsitems)rT   rU   rc   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
   rG   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 )Nr1   zFlag `--entry-point` required.r/   r0   z'--runtime must be one of the following:)r   RequiredArgumentException_PromptUserForRuntimerH   r   outrQ   )rT   r
   rG   s      r%   rI   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   $ )Nr0   z5Flag `--runtime` required when builder not specified.zPlease select a runtime:
)message)r   	CanPromptr   rn   PromptChoice)rT   rG   idxs      r%   ro   Deploy._PromptUserForRuntime   sL    !!00
N  
!
!6C =r(    )__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr&   rX   r	   	NamespacetypingDictstrAnyr?   r_   SetrI   ro   __static_attributes__rx   r(   r%   r   r   <   s    / -/ /"6@#--28++c6::o2N(!2!<!<  &CH 5:@++c3h:O@&++c3h"7 @%zz#@37@FJJsO  r(   r   )*r}   
__future__r   r   r   r]   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   rK   dedentrR   r~   rF   ReleaseTracksrB   rC   Commandr   rx   r(   r%   <module>r      s    " &  '    C ( . 5 C < K ; H 9 # 2 8 ! ) 	   
  D%%++,gT\\ g -gr(   