コード例 #1
0
 def __init__(self, config):
     for option in [
             "manage_dynamic_proxy", "dynamic_proxy_bind_port",
             "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
             "dynamic_proxy_external_proxy", "dynamic_proxy_prefix"
     ]:
         setattr(self, option, getattr(config, option))
     self.launch_by = "node"  # TODO: Support docker
     if self.manage_dynamic_proxy:
         self.lazy_process = self.__setup_lazy_process(config)
     else:
         self.lazy_process = NoOpLazyProcess()
     self.proxy_ipc = proxy_ipc(config)
コード例 #2
0
class ProxyManager(object):
    def __init__(self, config):
        for option in [
                "manage_dynamic_proxy", "dynamic_proxy_bind_port",
                "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
                "dynamic_proxy_external_proxy", "dynamic_proxy_prefix"
        ]:
            setattr(self, option, getattr(config, option))
        self.launch_by = "node"  # TODO: Support docker
        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()
        self.proxy_ipc = proxy_ipc(config)

    def shutdown(self):
        self.lazy_process.shutdown()

    def setup_proxy(self,
                    trans,
                    host=DEFAULT_PROXY_TO_HOST,
                    port=None,
                    proxy_prefix=""):
        if self.manage_dynamic_proxy:
            log.info("Attempting to start dynamic proxy process")
            self.lazy_process.start_process()

        authentication = AuthenticationToken(trans)
        proxy_requests = ProxyRequests(host=host, port=port)
        self.proxy_ipc.handle_requests(authentication, proxy_requests)
        # TODO: These shouldn't need to be request.host and request.scheme -
        # though they are reasonable defaults.
        host = trans.request.host
        if ':' in host:
            host = host[0:host.index(':')]
        scheme = trans.request.scheme
        if not self.dynamic_proxy_external_proxy:
            proxy_url = '%s://%s:%d' % (scheme, host,
                                        self.dynamic_proxy_bind_port)
        else:
            proxy_url = '%s://%s%s' % (scheme, host, proxy_prefix)
        return {
            'proxy_url': proxy_url,
            'proxied_port': proxy_requests.port,
            'proxied_host': proxy_requests.host,
        }

    def __setup_lazy_process(self, config):
        launcher = proxy_launcher(self)
        command = launcher.launch_proxy_command(config)
        return LazyProcess(command)
コード例 #3
0
ファイル: __init__.py プロジェクト: galaxyguardians/galaxy
class ProxyManager(object):
    def __init__(self, config):
        for option in [
            "manage_dynamic_proxy",
            "dynamic_proxy_bind_port",
            "dynamic_proxy_bind_ip",
            "dynamic_proxy_debug",
            "dynamic_proxy_external_proxy",
            "dynamic_proxy_prefix",
        ]:
            setattr(self, option, getattr(config, option))
        self.launch_by = "node"  # TODO: Support docker
        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()
        self.proxy_ipc = proxy_ipc(config)

    def shutdown(self):
        self.lazy_process.shutdown()

    def setup_proxy(self, trans, host=DEFAULT_PROXY_TO_HOST, port=None, proxy_prefix=""):
        if self.manage_dynamic_proxy:
            log.info("Attempting to start dynamic proxy process")
            self.lazy_process.start_process()

        authentication = AuthenticationToken(trans)
        proxy_requests = ProxyRequests(host=host, port=port)
        self.proxy_ipc.handle_requests(authentication, proxy_requests)
        # TODO: These shouldn't need to be request.host and request.scheme -
        # though they are reasonable defaults.
        host = trans.request.host
        if ":" in host:
            host = host[0 : host.index(":")]
        scheme = trans.request.scheme
        if not self.dynamic_proxy_external_proxy:
            proxy_url = "%s://%s:%d" % (scheme, host, self.dynamic_proxy_bind_port)
        else:
            proxy_url = "%s://%s%s" % (scheme, host, proxy_prefix)
        return {"proxy_url": proxy_url, "proxied_port": proxy_requests.port, "proxied_host": proxy_requests.host}

    def __setup_lazy_process(self, config):
        launcher = proxy_launcher(self)
        command = launcher.launch_proxy_command(config)
        return LazyProcess(command)
コード例 #4
0
ファイル: __init__.py プロジェクト: BinglanLi/galaxy
 def __init__( self, config ):
     for option in [ "manage_dynamic_proxy", "dynamic_proxy_bind_port", "dynamic_proxy_bind_ip", "dynamic_proxy_debug", "dynamic_proxy_external_proxy" ]:
         setattr( self, option, getattr( config, option ) )
     self.launch_by = "node"  # TODO: Support docker
     if self.manage_dynamic_proxy:
         self.lazy_process = self.__setup_lazy_process( config )
     else:
         self.lazy_process = NoOpLazyProcess()
     self.proxy_ipc = proxy_ipc(config)
コード例 #5
0
    def __init__(self, config):
        for option in ["manage_dynamic_proxy", "dynamic_proxy_bind_port",
                       "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
                       "dynamic_proxy_external_proxy", "dynamic_proxy_prefix",
                       "proxy_session_map",
                       "dynamic_proxy", "cookie_path",
                       "dynamic_proxy_golang_noaccess",
                       "dynamic_proxy_golang_clean_interval",
                       "dynamic_proxy_golang_docker_address",
                       "dynamic_proxy_golang_api_key"]:

            setattr(self, option, getattr(config, option))

        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()

        if self.dynamic_proxy_golang_api_key is None:
            self.dynamic_proxy_golang_api_key = unique_id()

        self.proxy_ipc = proxy_ipc(config)
コード例 #6
0
ファイル: __init__.py プロジェクト: bwlang/galaxy
    def __init__(self, config):
        for option in ["manage_dynamic_proxy", "dynamic_proxy_bind_port",
                       "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
                       "dynamic_proxy_external_proxy", "dynamic_proxy_prefix",
                       "proxy_session_map",
                       "dynamic_proxy", "cookie_path",
                       "dynamic_proxy_golang_noaccess",
                       "dynamic_proxy_golang_clean_interval",
                       "dynamic_proxy_golang_docker_address",
                       "dynamic_proxy_golang_api_key"]:

            setattr(self, option, getattr(config, option))

        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()

        if self.dynamic_proxy_golang_api_key is None:
            self.dynamic_proxy_golang_api_key = unique_id()

        self.proxy_ipc = proxy_ipc(config)
コード例 #7
0
class ProxyManager:

    valid_update_keys = (
        'host',
        'port',
    )

    def __init__(self, config):
        for option in [
                "manage_dynamic_proxy", "dynamic_proxy_bind_port",
                "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
                "dynamic_proxy_external_proxy", "dynamic_proxy_prefix",
                "proxy_session_map", "dynamic_proxy", "cookie_path",
                "dynamic_proxy_golang_noaccess",
                "dynamic_proxy_golang_clean_interval",
                "dynamic_proxy_golang_docker_address",
                "dynamic_proxy_golang_api_key"
        ]:

            setattr(self, option, getattr(config, option))

        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()

        if self.dynamic_proxy_golang_api_key is None:
            self.dynamic_proxy_golang_api_key = unique_id()

        self.proxy_ipc = proxy_ipc(config)

    def shutdown(self):
        self.lazy_process.shutdown()

    def setup_proxy(self,
                    trans,
                    host=DEFAULT_PROXY_TO_HOST,
                    port=None,
                    proxy_prefix="",
                    route_name="",
                    container_ids=None,
                    container_interface=None):
        if self.manage_dynamic_proxy:
            log.info("Attempting to start dynamic proxy process")
            log.debug("Cmd: " + ' '.join(self.lazy_process.command_and_args))
            self.lazy_process.start_process()

        if container_ids is None:
            container_ids = []

        authentication = AuthenticationToken(trans)
        proxy_requests = ProxyRequests(host=host, port=port)
        self.proxy_ipc.handle_requests(
            authentication,
            proxy_requests,
            '/%s' % route_name,
            container_ids,
            container_interface,
        )
        # TODO: These shouldn't need to be request.host and request.scheme -
        # though they are reasonable defaults.
        host = trans.request.host
        if ':' in host:
            host = host[0:host.index(':')]
        scheme = trans.request.scheme
        if not self.dynamic_proxy_external_proxy:
            proxy_url = '%s://%s:%d' % (scheme, host,
                                        self.dynamic_proxy_bind_port)
        else:
            proxy_url = f'{scheme}://{host}{proxy_prefix}'
        return {
            'proxy_url': proxy_url,
            'proxied_port': proxy_requests.port,
            'proxied_host': proxy_requests.host,
        }

    def update_proxy(self, trans, **kwargs):
        authentication = AuthenticationToken(trans)
        for k in kwargs.keys():
            if k not in self.valid_update_keys:
                raise Exception("Invalid proxy request update key: %s" % k)
        return self.proxy_ipc.update_requests(authentication, **kwargs)

    def query_proxy(self, trans):
        authentication = AuthenticationToken(trans)
        return self.proxy_ipc.fetch_requests(authentication)

    def __setup_lazy_process(self, config):
        launcher = self.proxy_launcher()
        command = launcher.launch_proxy_command(config)
        return LazyProcess(command)

    def proxy_launcher(self):
        if self.dynamic_proxy == "node":
            return NodeProxyLauncher()
        elif self.dynamic_proxy == "golang":
            return GolangProxyLauncher()
        else:
            raise Exception("Unknown proxy type")
コード例 #8
0
ファイル: __init__.py プロジェクト: bwlang/galaxy
class ProxyManager(object):

    def __init__(self, config):
        for option in ["manage_dynamic_proxy", "dynamic_proxy_bind_port",
                       "dynamic_proxy_bind_ip", "dynamic_proxy_debug",
                       "dynamic_proxy_external_proxy", "dynamic_proxy_prefix",
                       "proxy_session_map",
                       "dynamic_proxy", "cookie_path",
                       "dynamic_proxy_golang_noaccess",
                       "dynamic_proxy_golang_clean_interval",
                       "dynamic_proxy_golang_docker_address",
                       "dynamic_proxy_golang_api_key"]:

            setattr(self, option, getattr(config, option))

        if self.manage_dynamic_proxy:
            self.lazy_process = self.__setup_lazy_process(config)
        else:
            self.lazy_process = NoOpLazyProcess()

        if self.dynamic_proxy_golang_api_key is None:
            self.dynamic_proxy_golang_api_key = unique_id()

        self.proxy_ipc = proxy_ipc(config)

    def shutdown(self):
        self.lazy_process.shutdown()

    def setup_proxy(self, trans, host=DEFAULT_PROXY_TO_HOST, port=None, proxy_prefix="", route_name="", container_ids=None, container_interface=None):
        if self.manage_dynamic_proxy:
            log.info("Attempting to start dynamic proxy process")
            log.debug("Cmd: " + ' '.join(self.lazy_process.command_and_args))
            self.lazy_process.start_process()

        if container_ids is None:
            container_ids = []

        authentication = AuthenticationToken(trans)
        proxy_requests = ProxyRequests(host=host, port=port)
        self.proxy_ipc.handle_requests(
            authentication,
            proxy_requests,
            '/%s' % route_name,
            container_ids,
            container_interface,
        )
        # TODO: These shouldn't need to be request.host and request.scheme -
        # though they are reasonable defaults.
        host = trans.request.host
        if ':' in host:
            host = host[0:host.index(':')]
        scheme = trans.request.scheme
        if not self.dynamic_proxy_external_proxy:
            proxy_url = '%s://%s:%d' % (scheme, host, self.dynamic_proxy_bind_port)
        else:
            proxy_url = '%s://%s%s' % (scheme, host, proxy_prefix)
        return {
            'proxy_url': proxy_url,
            'proxied_port': proxy_requests.port,
            'proxied_host': proxy_requests.host,
        }

    def query_proxy(self, trans):
        authentication = AuthenticationToken(trans)
        return self.proxy_ipc.fetch_requests(authentication)

    def __setup_lazy_process(self, config):
        launcher = self.proxy_launcher()
        command = launcher.launch_proxy_command(config)
        return LazyProcess(command)

    def proxy_launcher(self):
        if self.dynamic_proxy == "node":
            return NodeProxyLauncher()
        elif self.dynamic_proxy == "golang":
            return GolangProxyLauncher()
        else:
            raise Exception("Unknown proxy type")