
                             S 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\R(                  5      rS rS rS rS rS rS rg)z.Utility functions for gcloud spanner emulator.    N)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.49i2#  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   _BuildStartArgsForDockerr6   .   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+   r.   r0   r   r1   )r2   spanner_executablenative_argss      r   "_BuildStartArgsForNativeExecutablerC   V   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       nU[         R                  R                  L d  U[         R                  R                  L a  U R
                  (       d  [        U 5      $ [        U 5      $ r   )r   OperatingSystemCurrentLINUXMACOSX
use_dockerrC   r6   )r2   
current_oss     r   _BuildStartArgsrK   t   s[    ((002*I--333	y0077	7OO-d33#D))r   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)   )r2   s    r   GetEnvrN      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} )rK   r   statusPrintr(   r;   r   ExecWriteEnvYamlrN   r   PrefixOutputSPANNER_EMULATOR_COMPONENT_ID)r2   spanner_argsspanner_processs      r   StartrY      st     &,**#**388L+ABCyy/fTlJL1o'DE s   AB,,
B:)__doc__r%   r9   $googlecloudsdk.command_lib.emulatorsr   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   r?   r   rV   SPANNER_EMULATOR_TITLEr=   r>   r-   r*   r,   Errorr   r   r6   rC   rK   rN   rY   r   r   r   <module>r`      s    5  	 5 * / # . 
#,   8 8 ": #1   O %) "%) "J,, ;%NP=<*Fr   