Ejemplo n.º 1
0
def do_forward_request_inmem(api, method, path, data, headers, port=None):
    listener_details = PROXY_LISTENERS.get(api)
    if not listener_details:
        message = (
            'Unable to find listener for service "%s" - please make sure to include it in $SERVICES'
            % api
        )
        LOG.warning(message)
        raise HTTPErrorResponse(message, code=400)
    service_name, backend_port, listener = listener_details
    # TODO determine client address..?
    client_address = LOCALHOST_IP
    server_address = headers.get("host") or LOCALHOST
    forward_url = "http://%s:%s" % (LOCALHOST, backend_port)
    response = modify_and_forward(
        method=method,
        path=path,
        data_bytes=data,
        headers=headers,
        forward_base_url=forward_url,
        listeners=[listener],
        request_handler=None,
        client_address=client_address,
        server_address=server_address,
    )
    return response
Ejemplo n.º 2
0
def check_lambda(expect_shutdown=False, print_error=False):
    out = None
    try:
        from localstack.services.infra import PROXY_LISTENERS
        from localstack.utils.aws import aws_stack
        from localstack.utils.common import wait_for_port_open

        # wait for port to be opened
        port = PROXY_LISTENERS.get("lambda")[1]
        wait_for_port_open(port)  # TODO get lambda port in a cleaner way

        endpoint_url = f"http://127.0.0.1:{port}"
        out = aws_stack.connect_to_service(
            service_name="lambda", endpoint_url=endpoint_url).list_functions()
    except Exception:
        if print_error:
            LOG.exception("Lambda health check failed")
    if expect_shutdown:
        assert out is None
    else:
        assert out and isinstance(out.get("Functions"), list)
Ejemplo n.º 3
0
def do_forward_request_inmem(api, port, method, path, data, headers):
    listener_details = PROXY_LISTENERS.get(api)
    if not listener_details:
        message = 'Unable to find listener for service "%s" - please make sure to include it in $SERVICES' % api
        LOG.warning(message)
        raise Exception(message)
    service_name, backend_port, listener = listener_details
    # TODO determine client address..?
    client_address = LOCALHOST_IP
    server_address = headers.get('host') or LOCALHOST
    forward_url = 'http://%s:%s' % (config.HOSTNAME, backend_port)
    response = modify_and_forward(method=method,
                                  path=path,
                                  data_bytes=data,
                                  headers=headers,
                                  forward_base_url=forward_url,
                                  listeners=[listener],
                                  request_handler=None,
                                  client_address=client_address,
                                  server_address=server_address)
    return response
Ejemplo n.º 4
0
def get_handler_for_api(api, headers):
    return PROXY_LISTENERS.get(api)