def start_proxy(sockets, config): # Take over SIGTERM and SIGINT signal.signal(signal.SIGTERM, stop_child) signal.signal(signal.SIGINT, stop_child) # Create a PluginManager plugin_manager = pynsive.PluginManager() for path in config.core.plugin_paths: plugin_manager.plug_into(path) # Resolve our filter chains try: if config.pipeline.use_singletons: filter_pipeline_factories = _build_singleton_plfactories(config) else: filter_pipeline_factories = _build_plfactories(config) except Exception as ex: _LOG.exception(ex) return -1 # Load any SSL configurations ssl_options = None cert_file = config.ssl.cert_file key_file = config.ssl.key_file if None not in (cert_file, key_file): ssl_options = dict() ssl_options['certfile'] = cert_file ssl_options['keyfile'] = key_file _LOG.debug('SSL enabled: {}'.format(ssl_options)) # Create proxy server ref http_proxy = TornadoHttpProxy( filter_pipeline_factories, config.routing.upstream_hosts, ssl_options) # Add our sockets for watching http_proxy.add_sockets(sockets) # Start tornado IOLoop.current().start()
def start_proxy(sockets, config): # Take over SIGTERM and SIGINT signal.signal(signal.SIGTERM, stop_child) signal.signal(signal.SIGINT, stop_child) # Create a PluginManager plugin_manager = pynsive.PluginManager() for path in config.core.plugin_paths: plugin_manager.plug_into(path) # Resolve our filter chains try: if config.pipeline.use_singletons: filter_pipeline_factories = _build_singleton_plfactories(config) else: filter_pipeline_factories = _build_plfactories(config) except Exception as ex: _LOG.exception(ex) return -1 # Load any SSL configurations ssl_options = None cert_file = config.ssl.cert_file key_file = config.ssl.key_file if None not in (cert_file, key_file): ssl_options = dict() ssl_options['certfile'] = cert_file ssl_options['keyfile'] = key_file _LOG.debug('SSL enabled: {}'.format(ssl_options)) # Create proxy server ref http_proxy = TornadoHttpProxy(filter_pipeline_factories, config.routing.upstream_hosts, ssl_options) # Add our sockets for watching http_proxy.add_sockets(sockets) # Start tornado IOLoop.current().start()
def start_pyrox(other_cfg=None): config = load_config(other_cfg) if other_cfg else load_config() # Init logging logging_manager = get_log_manager() logging_manager.configure(config) # Create a PluginManager plugin_manager = pynsive.PluginManager() for path in config.core.plugin_paths: plugin_manager.plug_into(path) # Resolve our filter chains try: filter_pipeline_factories = _build_fc_factories(config) except Exception as ex: _LOG.exception(ex) return -1 # Create proxy server ref http_proxy = TornadoHttpProxy( filter_pipeline_factories, config.routing.upstream_hosts[0]) _LOG.info('Upstream targets are: {}'.format( ['http://{0}:{1}'.format(dst[0], dst[1]) for dst in config.routing.upstream_hosts])) # Set bind host bind_host = config.core.bind_host.split(':') if len(bind_host) != 2: raise ConfigurationError('bind_host must have a port specified') # Bind the server http_proxy.bind(address=bind_host[0], port=int(bind_host[1])) _LOG.info('Pyrox listening on: http://{0}:{1}'.format( bind_host[0], bind_host[1])) # Start Tornado http_proxy.start(config.core.processes) IOLoop.instance().start()
def start_proxy(sockets, config): # Take over SIGTERM and SIGINT signal.signal(signal.SIGTERM, stop_child) signal.signal(signal.SIGINT, stop_child) # Create a PluginManager plugin_manager = pynsive.PluginManager() for path in config.core.plugin_paths: plugin_manager.plug_into(path) # Resolve our filter chains try: if config.pipeline.use_singletons: filter_pipeline_factories = _build_singleton_plfactories(config) else: filter_pipeline_factories = _build_plfactories(config) except Exception as ex: _LOG.exception(ex) return -1 #TODO(jwood) Get SSL info from config file. ssl_options = None # { # "certfile": "/Users/john.wood/projects/security/tornado_related/pyrox/test.crt", # "keyfile": "/Users/john.wood/projects/security/tornado_related/pyrox/test.key" # } # Create proxy server ref http_proxy = TornadoHttpProxy( filter_pipeline_factories, config.routing.upstream_hosts, ssl_options=ssl_options) # Add our sockets for watching http_proxy.add_sockets(sockets) # Start tornado IOLoop.current().start()