def wrapper(**kwargs): if configure_sentry and kwargs["sentry_dsn"]: configure_sentry_logging( dsn=kwargs["sentry_dsn"], environment=kwargs["sentry_environment"]) return fn(**kwargs)
def wrapper(config_dir, *args, **kwargs): assert "config" not in kwargs ssl_keyfile = kwargs["ssl_keyfile"] ssl_certfile = kwargs["ssl_certfile"] if ssl_certfile or ssl_keyfile: ssl_context = trio.ssl.create_default_context( trio.ssl.Purpose.SERVER_CLIENT) if ssl_certfile: ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile) else: ssl_context.load_default_certs() kwargs["ssl_context"] = ssl_context configure_logging(kwargs["log_level"], kwargs["log_format"], kwargs["log_file"], kwargs["log_filter"]) config_dir = Path( config_dir) if config_dir else get_default_config_dir(os.environ) config = load_config(config_dir, debug="DEBUG" in os.environ) if config.sentry_url: configure_sentry_logging(config.sentry_url) kwargs["config"] = config return fn(**kwargs)
def run_gui( config: CoreConfig, url: str, diagnose: bool, sentry_dsn: Optional[str], sentry_environment: str, **kwargs, ) -> None: """ Run parsec GUI """ # Necessary for DialogInProcess since it's not the default on windows # This method should only be called once which is why we do it here. multiprocessing.set_start_method("spawn") with cli_exception_handler(config.debug): if config.telemetry_enabled and sentry_dsn: configure_sentry_logging(dsn=sentry_dsn, environment=sentry_environment) config = config.evolve(mountpoint_enabled=True) try: _run_gui(config, start_arg=url, diagnose=diagnose) except KeyboardInterrupt: click.echo("bye ;-)")
def wrapper(config_dir, *args, **kwargs): assert "config" not in kwargs configure_logging(kwargs["log_level"], kwargs["log_format"], kwargs["log_file"], kwargs["log_filter"]) config_dir = Path( config_dir) if config_dir else get_default_config_dir(os.environ) config = load_config(config_dir, debug="DEBUG" in os.environ) if config.telemetry_enabled and config.sentry_url: configure_sentry_logging(config.sentry_url) kwargs["config"] = config return fn(**kwargs)
def run_cmd( host, port, db, db_drop_deleted_data, db_min_connections, db_max_connections, blockstore, administration_token, ssl_keyfile, ssl_certfile, log_level, log_format, log_file, log_filter, sentry_url, debug, dev, ): configure_logging(log_level, log_format, log_file, log_filter) if sentry_url: configure_sentry_logging(sentry_url) with cli_exception_handler(debug): config = BackendConfig( administration_token=administration_token, db_url=db, db_drop_deleted_data=db_drop_deleted_data, db_min_connections=db_min_connections, db_max_connections=db_max_connections, blockstore_config=blockstore, debug=debug, ) if ssl_certfile or ssl_keyfile: ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) if ssl_certfile: ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile) else: ssl_context.load_default_certs() else: ssl_context = None async def _run_backend(): async with backend_app_factory(config=config) as backend: async def _serve_client(stream): if ssl_context: stream = trio.SSLStream(stream, ssl_context, server_side=True) try: await backend.handle_client(stream) except Exception: # If we are here, something unexpected happened... logger.exception("Unexpected crash") await stream.aclose() await trio.serve_tcp(_serve_client, port, host=host) click.echo( f"Starting Parsec Backend on {host}:{port} (db={config.db_type}, " f"blockstore={config.blockstore_config.type})" ) try: trio_run(_run_backend, use_asyncio=True) except KeyboardInterrupt: click.echo("bye ;-)")
def run_cmd( host, port, db, db_min_connections, db_max_connections, db_first_tries_number, db_first_tries_sleep, blockstore, administration_token, spontaneous_organization_bootstrap, organization_bootstrap_webhook, backend_addr, email_host, email_port, email_host_user, email_host_password, email_use_ssl, email_use_tls, email_sender, forward_proto_enforce_https, ssl_keyfile, ssl_certfile, log_level, log_format, log_file, log_filter, sentry_url, debug, dev, ): # Start a local backend configure_logging(log_level, log_format, log_file, log_filter) if sentry_url: configure_sentry_logging(sentry_url) with cli_exception_handler(debug): if ssl_certfile or ssl_keyfile: ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) if ssl_certfile: ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile) else: ssl_context.load_default_certs() else: ssl_context = None if email_host == "MOCKED": tmpdir = tempfile.mkdtemp(prefix="tmp-email-folder-") if email_sender: email_config = MockedEmailConfig(sender=email_sender, tmpdir=tmpdir) else: email_config = MockedEmailConfig(sender=DEFAULT_EMAIL_SENDER, tmpdir=tmpdir) else: if not email_sender: raise ValueError( "--email-sender is required when --email-host is provided") email_config = SmtpEmailConfig( host=email_host, port=email_port, host_user=email_host_user, host_password=email_host_password, use_ssl=email_use_ssl, use_tls=email_use_tls, sender=email_sender, ) config = BackendConfig( administration_token=administration_token, db_url=db, db_min_connections=db_min_connections, db_max_connections=db_max_connections, db_first_tries_number=db_first_tries_number, db_first_tries_sleep=db_first_tries_sleep, spontaneous_organization_bootstrap= spontaneous_organization_bootstrap, organization_bootstrap_webhook_url=organization_bootstrap_webhook, blockstore_config=blockstore, email_config=email_config, ssl_context=True if ssl_context else False, forward_proto_enforce_https=forward_proto_enforce_https, backend_addr=backend_addr, debug=debug, ) async def _run_backend(): async with backend_app_factory(config=config) as backend: async def _serve_client(stream): if ssl_context: stream = trio.SSLStream(stream, ssl_context, server_side=True) try: await backend.handle_client(stream) except Exception: # If we are here, something unexpected happened... logger.exception("Unexpected crash") await stream.aclose() await trio.serve_tcp(_serve_client, port, host=host) click.echo(f"Starting Parsec Backend on {host}:{port}" f" (db={config.db_type}" f" blockstore={config.blockstore_config.type}" f" backend_addr={config.backend_addr}" f" email_config={str(email_config)})") try: trio_run(_run_backend, use_asyncio=True) except KeyboardInterrupt: click.echo("bye ;-)")
def init(config): if config.telemetry_enabled and config.sentry_url: configure_sentry_logging(config.sentry_url) else: disable_sentry_logging()
def init(config: CoreConfig): if config.telemetry_enabled and config.sentry_dsn: configure_sentry_logging(dsn=config.sentry_dsn, environment=config.sentry_environment) else: disable_sentry_logging()
def run_cmd( host, port, db, blockstore, ssl_keyfile, ssl_certfile, log_level, log_format, log_file, log_filter, ): configure_logging(log_level, log_format, log_file, log_filter) debug = "DEBUG" in os.environ with cli_exception_handler(debug): try: config = config_factory(blockstore_type=blockstore, db_url=db, debug=debug, environ=os.environ) except ValueError as exc: raise ValueError(f"Invalid configuration: {exc}") if config.sentry_url: configure_sentry_logging(config.sentry_url) backend = BackendApp(config) if ssl_certfile or ssl_keyfile: ssl_context = trio.ssl.create_default_context( trio.ssl.Purpose.SERVER_AUTH) if ssl_certfile: ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile) else: ssl_context.load_default_certs() else: ssl_context = None async def _serve_client(stream): if ssl_context: stream = trio.ssl.SSLStream(stream, ssl_context, server_side=True) try: await backend.handle_client(stream) except Exception as exc: # If we are here, something unexpected happened... logger.error("Unexpected crash", exc_info=exc) await stream.aclose() async def _run_backend(): async with trio.open_nursery() as nursery: await backend.init(nursery) try: await trio.serve_tcp(_serve_client, port, host=host) finally: await backend.teardown() print( f"Starting Parsec Backend on {host}:{port} (db={config.db_type}, " f"blockstore={config.blockstore_config.type})") try: trio_asyncio.run(_run_backend) except KeyboardInterrupt: print("bye ;-)")
def run_cmd( host, port, db, db_min_connections, db_max_connections, maximum_database_connection_attempts, pause_before_retry_database_connection, blockstore, administration_token, spontaneous_organization_bootstrap, organization_bootstrap_webhook, backend_addr, email_host, email_port, email_host_user, email_host_password, email_use_ssl, email_use_tls, email_sender, forward_proto_enforce_https, ssl_keyfile, ssl_certfile, log_level, log_format, log_file, sentry_url, debug, dev, ): # Start a local backend configure_logging(log_level=log_level, log_format=log_format, log_file=log_file) if sentry_url: configure_sentry_logging(sentry_url) with cli_exception_handler(debug): if ssl_certfile or ssl_keyfile: ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) if ssl_certfile: ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile) else: ssl_context.load_default_certs() else: ssl_context = None if email_host == "MOCKED": tmpdir = tempfile.mkdtemp(prefix="tmp-email-folder-") if email_sender: email_config = MockedEmailConfig(sender=email_sender, tmpdir=tmpdir) else: email_config = MockedEmailConfig(sender=DEFAULT_EMAIL_SENDER, tmpdir=tmpdir) else: if not email_sender: raise ValueError( "--email-sender is required when --email-host is provided") email_config = SmtpEmailConfig( host=email_host, port=email_port, host_user=email_host_user, host_password=email_host_password, use_ssl=email_use_ssl, use_tls=email_use_tls, sender=email_sender, ) app_config = BackendConfig( administration_token=administration_token, db_url=db, db_min_connections=db_min_connections, db_max_connections=db_max_connections, spontaneous_organization_bootstrap= spontaneous_organization_bootstrap, organization_bootstrap_webhook_url=organization_bootstrap_webhook, blockstore_config=blockstore, email_config=email_config, ssl_context=True if ssl_context else False, forward_proto_enforce_https=forward_proto_enforce_https, backend_addr=backend_addr, debug=debug, ) click.echo(f"Starting Parsec Backend on {host}:{port}" f" (db={app_config.db_type}" f" blockstore={app_config.blockstore_config.type}" f" backend_addr={app_config.backend_addr}" f" email_config={str(email_config)})") try: retry_policy = RetryPolicy(maximum_database_connection_attempts, pause_before_retry_database_connection) trio_run(_run_backend, host, port, ssl_context, retry_policy, app_config, use_asyncio=True) except KeyboardInterrupt: click.echo("bye ;-)")