Exemplo n.º 1
0
def do_start_edge(bind_address, port, use_ssl, asynchronous=False):
    from localstack.http.adapters import RouterListener
    from localstack.services.internal import LocalstackResourceHandler

    start_dns_server(asynchronous=True)

    listeners = [
        LocalstackResourceHandler(),  # handle internal resources first
        RouterListener(ROUTER),  # then custom routes
        PROXY_LISTENER_EDGE,  # then call the edge proxy listener
    ]

    # get port and start Edge
    print("Starting edge router (http%s port %s)..." % ("s" if use_ssl else "", port))
    # use use_ssl=True here because our proxy allows both, HTTP and HTTPS traffic
    proxy = start_proxy_server(
        port,
        bind_address=bind_address,
        use_ssl=True,
        update_listener=listeners,
        check_port=False,
    )
    if not asynchronous:
        proxy.join()
    return proxy
Exemplo n.º 2
0
 def test_cloudformation_ui(self):
     with proxy_server(LocalstackResourceHandler()) as url:
         # make sure it renders
         response = requests.get(f"{url}/_localstack/cloudformation/deploy")
         assert response.ok
         assert "</html>" in response.text, "deploy UI did not render HTML"
         assert "text/html" in response.headers.get("content-type", "")
Exemplo n.º 3
0
    def test_fallthrough(self):
        with proxy_server(LocalstackResourceHandler()) as url:
            # some other error is thrown by the proxy if there are no more listeners
            response = requests.get(f"{url}/foobar")
            assert not response.ok
            assert not response.status_code == 404

            # internal paths are 404ed
            response = requests.get(f"{url}/_localstack/foobar")
            assert not response.ok
            assert response.status_code == 404
Exemplo n.º 4
0
    def test_health(self, monkeypatch):
        with proxy_server(LocalstackResourceHandler()) as url:
            # legacy endpoint
            response = requests.get(f"{url}/health")
            assert response.ok
            assert "services" in response.json()

            # new internal endpoint
            response = requests.get(f"{url}/_localstack/health")
            assert response.ok
            assert "services" in response.json()
Exemplo n.º 5
0
    def test_fallthrough(self):
        class RaiseError(ProxyListener):
            def forward_request(self, method, path, data, headers):
                raise ValueError("this error is expected")

        with proxy_server([LocalstackResourceHandler(), RaiseError()]) as url:
            # the RaiseError handler is called since this is not a /_localstack resource
            response = requests.get(f"{url}/foobar")
            assert not response.ok
            assert response.status_code >= 500

            # internal paths are 404ed
            response = requests.get(f"{url}/_localstack/foobar")
            assert not response.ok
            assert response.status_code == 404
Exemplo n.º 6
0
    def start_runtime_components():
        from localstack.services.edge import start_edge
        from localstack.services.internal import LocalstackResourceHandler, get_internal_apis

        # serve internal APIs through the generic proxy
        ProxyListener.DEFAULT_LISTENERS.append(LocalstackResourceHandler(get_internal_apis()))

        # TODO: we want a composable LocalStack runtime (edge proxy, service manager, dns, ...)
        t = start_thread(start_edge, quiet=False)

        # TODO: properly encapsulate starting/stopping of edge server in a class
        if not poll_condition(
            lambda: is_port_open(config.get_edge_port_http()), timeout=5, interval=0.1
        ):
            raise TimeoutError(
                f"gave up waiting for edge server on {config.EDGE_BIND_HOST}:{config.EDGE_PORT}"
            )

        return t
Exemplo n.º 7
0
def do_start_edge(bind_address, port, use_ssl, asynchronous=False):
    from localstack.services.internal import LocalstackResourceHandler

    # add internal routes as default listener
    ProxyListener.DEFAULT_LISTENERS.append(LocalstackResourceHandler())

    start_dns_server(asynchronous=True)

    # get port and start Edge
    print("Starting edge router (http%s port %s)..." % ("s" if use_ssl else "", port))
    # use use=True here because our proxy allows both, HTTP and HTTPS traffic
    proxy = start_proxy_server(
        port,
        bind_address=bind_address,
        use_ssl=True,
        update_listener=PROXY_LISTENER_EDGE,
    )
    if not asynchronous:
        proxy.join()
    return proxy