Exemple #1
0
def main(ctx, port, config, addresses, version):
    """run the relay server"""
    logging.basicConfig(
        format="%(asctime)s[%(levelname)s] %(name)s: %(message)s",
        level=os.environ.get("LOGLEVEL", "INFO").upper(),
    )

    # silence warnings from urllib3, see github issue 246
    logging.getLogger("urllib3.connectionpool").setLevel(logging.CRITICAL)

    logger.info("Starting relay server version %s", get_version())

    # we still handle the json file for now. This will be removed
    # soon. But it's nice to see the end2end tests succeed.
    with open(config) as config_file:
        if config.lower().endswith(".json"):
            config_dict = {"relay": json.load(config_file)}
        else:
            config_dict = toml.load(config_file)
    configure_logging(config_dict)

    trustlines = TrustlinesRelay(config=config_dict["relay"],
                                 addresses_json_path=addresses)
    trustlines.start()
    ipport = ("", port)
    app = ApiApp(trustlines)
    http_server = WSGIServer(ipport,
                             app,
                             log=None,
                             handler_class=WebSocketHandler)
    logger.info("Server is running on {}".format(ipport))
    http_server.serve_forever()
Exemple #2
0
def _show_version(ctx, param, value):
    """handle --version argument

    we need this function, because otherwise click may check that the default
    --config or --addresses arguments are really files and they may not
    exist"""
    if value:
        click.echo(get_version())
        ctx.exit()
Exemple #3
0
def main(
    ctx, port: int, config: str, addresses: str, version: bool, report_coverage: bool
) -> None:
    """run the relay server"""

    # silence warnings from urllib3, see github issue 246
    logging.getLogger("urllib3.connectionpool").setLevel(logging.CRITICAL)

    logger.info("Starting relay server version %s", get_version())

    if report_coverage:
        coverage = Coverage()
        coverage.start()

    try:
        config_dict = load_config(config)
    except ValidationError as error:
        logger.error("Validation error in config: " + validation_error_string(error))
        sys.exit(1)
    configure_logging(config_dict)
    sentry_config = config_dict.get("sentry", None)
    if sentry_config is not None:
        sentry_sdk.init(
            dsn=sentry_config["dsn"],
            integrations=[sentry_sdk.integrations.flask.FlaskIntegration()],
        )

    if addresses is None:
        addresses = config_dict["relay"]["addresses_filepath"]
    trustlines = TrustlinesRelay(config=config_dict, addresses_json_path=addresses)
    trustlines.start()

    rest_config = config_dict["rest"]
    if port is None:
        port = rest_config["port"]
    host = rest_config["host"]
    ipport = (host, port)
    app = ApiApp(trustlines, enabled_apis=select_enabled_apis(config_dict))
    http_server = WSGIServer(ipport, app, log=None, handler_class=WebSocketHandler)

    if report_coverage:

        def shutdown(code, frame):
            logger.info("Relay server is shutting down ...")
            http_server.stop(timeout=60)
            coverage.stop()
            coverage.xml_report(outfile="/end2end-coverage/coverage.xml")
            exit(signal.SIGTERM)

        signal.signal(signal.SIGTERM, shutdown)
        signal.signal(signal.SIGQUIT, shutdown)
        signal.signal(signal.SIGINT, shutdown)

    logger.info("Server is running on {}".format(ipport))
    http_server.serve_forever()
Exemple #4
0
def main(ctx, port: int, config: str, addresses: str, version) -> None:
    """run the relay server"""

    # silence warnings from urllib3, see github issue 246
    logging.getLogger("urllib3.connectionpool").setLevel(logging.CRITICAL)

    logger.info("Starting relay server version %s", get_version())

    try:
        config_dict = load_config(config)
    except ValidationError as error:
        logger.error("Validation error in config: " +
                     validation_error_string(error))
        sys.exit(1)
    configure_logging(config_dict)
    sentry_config = config_dict.get("sentry", None)
    if sentry_config is not None:
        sentry_sdk.init(
            dsn=sentry_config["dsn"],
            integrations=[sentry_sdk.integrations.flask.FlaskIntegration()],
        )

    if addresses is None:
        addresses = config_dict["relay"]["addresses_filepath"]
    trustlines = TrustlinesRelay(config=config_dict,
                                 addresses_json_path=addresses)
    trustlines.start()

    rest_config = config_dict["rest"]
    if port is None:
        port = rest_config["port"]
    host = rest_config["host"]
    ipport = (host, port)
    app = ApiApp(trustlines, enabled_apis=select_enabled_apis(config_dict))
    http_server = WSGIServer(ipport,
                             app,
                             log=None,
                             handler_class=WebSocketHandler)
    logger.info("Server is running on {}".format(ipport))
    http_server.serve_forever()