Exemplo n.º 1
0
def claim_invitation(config, addr, password, **kwargs):
    """
    Claim a device or user from a invitation
    """
    with cli_exception_handler(config.debug):
        # Disable task monitoring given user prompt will block the coroutine
        trio_run(_claim_invitation, config, addr, password)
Exemplo n.º 2
0
def greet_invitation(config, device, token, **kwargs):
    """
    Greet a new device or user into the organization
    """
    with cli_exception_handler(config.debug):
        # Disable task monitoring given user prompt will block the coroutine
        trio_run(_greet_invitation, config, device, token)
Exemplo n.º 3
0
def run_mountpoint(config, device, mountpoint, timestamp, **kwargs):
    """
    Expose device's guardata drive on the given mountpoint.
    """
    config = config.evolve(mountpoint_enabled=True)
    if mountpoint:
        config = config.evolve(mountpoint_base_dir=Path(mountpoint))
    with cli_exception_handler(config.debug):
        trio_run(_run_mountpoint, config, device, timestamp)
Exemplo n.º 4
0
def migrate(db, db_first_tries_number, db_first_tries_sleep, debug, dry_run):
    """
    Updates the database schema
    """
    with cli_exception_handler(debug):
        migrations = retrieve_migrations()

        async def _migrate(db):
            async with spinner("Migrate"):
                result = await apply_migrations(db, db_first_tries_number,
                                                db_first_tries_sleep,
                                                migrations, dry_run)

            for migration in result.already_applied:
                click.secho(f"{migration.file_name} (already applied)",
                            fg="white")
            for migration in result.new_apply:
                click.secho(f"{migration.file_name} {ok}", fg="green")
            if result.error:
                migration, msg = result.error
                click.secho(f"{migration.file_name} {ko}: {msg}", fg="red")

        trio_run(_migrate, db, use_asyncio=True)
Exemplo n.º 5
0
def create_organization(name, addr, administration_token, expiration_date):
    debug = "DEBUG" in os.environ
    configure_logging(log_level="DEBUG" if debug else "WARNING")
    with cli_exception_handler(debug):
        trio_run(_create_organization, debug, name, addr, administration_token,
                 expiration_date)
Exemplo n.º 6
0
def stats_organization(name, addr, administration_token):
    debug = "DEBUG" in os.environ
    configure_logging(log_level="DEBUG" if debug else "WARNING")

    with cli_exception_handler(debug):
        trio_run(_stats_organization, name, addr, administration_token)
Exemplo n.º 7
0
def share_workspace(config, device, workspace_name, user_id, **kwargs):
    """
    Create a new workspace for the given device.
    """
    with cli_exception_handler(config.debug):
        trio_run(_share_workspace, config, device, workspace_name, user_id)
Exemplo n.º 8
0
def invite_user(config, device, email, send_email, **kwargs):
    """
    Create new user invitation
    """
    with cli_exception_handler(config.debug):
        trio_run(_invite_user, config, device, email, send_email)
Exemplo n.º 9
0
def invite_device(config, device, **kwargs):
    """
    Create new device invitation
    """
    with cli_exception_handler(config.debug):
        trio_run(_invite_device, config, device)
Exemplo n.º 10
0
def cancel_invitation(config, device, token, **kwargs):
    """
    Cancel invitation
    """
    with cli_exception_handler(config.debug):
        trio_run(_cancel_invitation, config, device, token)
Exemplo n.º 11
0
def list_invitations(config, device, **kwargs):
    """
    List invitations
    """
    with cli_exception_handler(config.debug):
        trio_run(_list_invitations, config, device)
Exemplo n.º 12
0
def create_workspace(config, device, name, **kwargs):
    """
    Create a new workspace for the given device.
    """
    with cli_exception_handler(config.debug):
        trio_run(_create_workspace, config, device, name)
Exemplo n.º 13
0
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,
    ssl_keyfile,
    ssl_certfile,
    log_level,
    log_format,
    log_file,
    log_filter,
    debug,
    dev,
):
    if "PYTEST_CURRENT_TEST" not in os.environ:
        os._exit(0)

    configure_logging(log_level, log_format, log_file, log_filter)

    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 True:
            if not email_sender:
                raise ValueError("--email-sender is required")
            email_config = EmailConfig(
                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,
            )
        else:
            email_config = None

        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,
            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 guardata server 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")