
    F                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlZi Z ej                          ej                         fD ]  Zeeej                   <    d	 Z G d
 de      Zy)z1Code related to proxy and emulator configuration.    )absolute_import)division)unicode_literalsN)datastore_util)pubsub_util)filesc                     t        j                  |       D ci c]  \  }}||j                   }}}t        j                  |t        j                  |d             yc c}}w )a  This writes out the routes information to a file.

  The routes will be written as json in the format
  {service1: [route1, route2], service2: [route3, route4]}

  Args:
    emulators: [str], emulators to route the traffic of
    output_file: str, file to write the configuration to
     indentN)six	iteritemsprefixesr   WriteFileContentsjsondumps)	emulatorsoutput_filenameemulatorroutess        2lib/googlecloudsdk/command_lib/emulators/config.pyWriteRoutesConfigr   %   s^     #&--	":<":h (###": 	 < +tzz&'CD<s   Ac                       e Zd ZdZd Zd Zy)ProxyConfigurationz0Configuration necessary to initialize the proxy.c                 .    || _         || _        || _        y)a  Initializes object.

    Args:
      local_emulators: dict, the emulators and the ports they'll listen on
      should_proxy_to_gcp: bool, whether traffic to other emulators should
                           go to prod or not
      proxy_port: int, the port the proxy should bind to
    N)_local_emulators_proxy_port_should_proxy_to_gcp)selflocal_emulatorsshould_proxy_to_gcp
proxy_ports       r   __init__zProxyConfiguration.__init__;   s     ,D!D 3D    c                     | j                   | j                  | j                  d}t        j                  |t        j                  |d             y)zWrites configuration to file.

    The format will be
    {"localEmulators": {emulator1: port1, emulator2: port2},
     "proxyPort": port,
     "shouldProxyToGcp": bool}

    Args:
      output_file: str, file to write to
    )localEmulators	proxyPortshouldProxyToGcpr
   r   N)r   r   r   r   r   r   r   )r    r   datas      r   WriteJsonToFilez"ProxyConfiguration.WriteJsonToFileH   sC     //%% 55D
 
KD)CDr%   N)__name__
__module____qualname____doc__r$   r+    r%   r   r   r   8   s    84Er%   r   )r/   
__future__r   r   r   r   $googlecloudsdk.command_lib.emulatorsr   r   googlecloudsdk.core.utilr   r   	EMULATORSDatastoreEmulatorPubsubEmulatorr   service_namer   objectr   r0   r%   r   <module>r9      su    8 &  '  ? < * 
 	1113+++-/H%-)H!!"/
E& E  Er%   