
                             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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SrSrSrSrSrSrSr " S S\
R0                  5      rS rS rS rS rS rS rg)z.Utility functions for gcloud spanner emulator.    )absolute_import)division)unicode_literalsN)util)
exceptions)execution_utils)log)	platformsspannerzcloud-spanner-emulatorzGoogle Cloud Spanner Emulatorcloud_spanner_emulatorgateway_mainz-gcr.io/cloud-spanner-emulator/emulator:1.5.28i2#  i<#  c                       \ rS rSrSrg)InvalidHostPortFormat)    N)__name__
__module____qualname____firstlineno____static_attributes__r       8lib/googlecloudsdk/command_lib/emulators/spanner_util.pyr   r   )   s    r   r   c                  6    [         R                  " [        5      $ N)r   
GetDataDir SPANNER_EMULATOR_PROPERTY_PREFIXr   r   r   r   r   -   s    	9	::r   c           
      N   U R                   R                  nUS:X  a  Sn [        R                  " U5        SSSSR                  XR                   R                  [        5      SSR                  XR                  [        5      [        /n/ n[        U SS	5      n[        U S
S	5      nU(       d  U(       aC  UR                  / SQ5        U(       a  UR                  S5        U(       a  UR                  S5        [        R                   " X#-   6 $ ! [         a    [        SU-   5      ef = f)z@Builds arguments for starting the spanner emulator under docker.	localhostz	127.0.0.1z]When using docker, hostname specified via --host-port must be an IPV4 or IPV6 address, found dockerrunz-pz{}:{}:{}enable_fault_injectionFprint_notices)z./gateway_main
--hostnamez0.0.0.0--enable_fault_injection	--notices)	host_porthost	ipaddress
ip_address
ValueErrorr   formatport"SPANNER_EMULATOR_DEFAULT_GRPC_PORT	rest_port"SPANNER_EMULATOR_DEFAULT_REST_PORTSPANNER_EMULATOR_DOCKER_IMAGEgetattrextendappendr   ArgsForExecutableTool)argshost_ipdocker_argsgateway_argsr!   r"   s         r   _BuildStartArgsForDockerr9   1   s    NN'G=! t!4!4:<=A:<#+ , #4)A5I$7-}CD45+&		.	.1K	MM5 
 =
	24;	<= ==s   D D$c           	         [         R                  R                  [        R                  " 5       S[
        [        5      nU R                  R                  c  [        S5      eUSU R                  R                  SU R                  R                  S[        R                  " U R                  5      /n[        U SS5      (       a  UR                  S5        [        U S	S5      (       a  UR                  S
5        [         R"                  " U6 $ )a0  Builds arguments for starting the spanner emulator as a native executable.

Args:
  args: An argparse.Namespace object containing the command line arguments.

Returns:
  A list of strings representing the command and its arguments.

Raises:
  InvalidHostPortFormat: If the host_port is missing the port.
binz>Invalid value for --host-port. Must be in the format host:portr#   z--grpc_portz--http_portr!   Fr$   r"   r%   )ospathjoinr   GetCloudSDKRootSPANNER_EMULATOR_EXECUTABLE_DIR SPANNER_EMULATOR_EXECUTABLE_FILEr&   r,   r   r'   six	text_typer.   r1   r3   r   r4   )r5   spanner_executablenative_argss      r   "_BuildStartArgsForNativeExecutablerF   Y   s     ww||D$8$8$:E$C$DF 
^^ 
HJ J ,(;(;]
nn=	mmDNN#+
 T+U3312T?E**{#		.	.	<<r   c                     [         R                  R                  5       [         R                  R                  Ld  U R                  (       a  [        U 5      $ [        U 5      $ r   )r
   OperatingSystemCurrentLINUX
use_dockerr9   rF   r5   s    r   _BuildStartArgsrM   w   sB    '')1J1J1P1PP	#D))-d33r   c                 z    SSR                  U R                  R                  U R                  R                  5      0$ )zCReturns an environment variable mapping from an argparse.Namespace.SPANNER_EMULATOR_HOSTz{}:{})r+   r&   r'   r,   rL   s    r   GetEnvrP      s3     
..,,dnn.A.A
B
 r   c                 z   [        U 5      n[        R                  R                  SR	                  SR                  U5      5      5        [        R                  " U5       n[        R                  " [        U 5      [        5       5        [        R                  " U[        5        S S S 5        g ! , (       d  f       g = f)NzExecuting: {0} )rM   r	   statusPrintr+   r>   r   ExecWriteEnvYamlrP   r   PrefixOutputSPANNER_EMULATOR_COMPONENT_ID)r5   spanner_argsspanner_processs      r   Startr[      st     &,**#**388L+ABCyy/fTlJL1o'DE s   AB,,
B:) __doc__
__future__r   r   r   r(   r<   $googlecloudsdk.command_lib.emulatorsr   googlecloudsdk.corer   r   r	   googlecloudsdk.core.utilr
   rB   r   rX   SPANNER_EMULATOR_TITLEr@   rA   r0   r-   r/   Errorr   r   r9   rF   rM   rP   r[   r   r   r   <module>rc      s    5 &  '  	 5 * / # . 
#,   8 8 ": #1   O %) "%) "J,, ;%NP=<4Fr   