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)
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)
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)
def main(**kwargs): """Create a temporary environment and initialize a test setup for guardata. WARNING: it also leaves an in-memory backend running in the background on port 6888. It is typically a good idea to source this script in order to export the XDG variables so the upcoming guardata commands point to the test environment: \b $ source tests/scripts/run_testenv.sh This scripts create two users, Alice and Bob who both own two devices, laptop and pc. They each have their workspace, respectively alice_workspace and bob_workspace, that their sharing with each other. The --empty (or -e) argument may be used to bypass the initialization of the test environment: \b $ source tests/scripts/run_testenv.sh --empty This can be used to perform a user or device enrollment on the same machine. For instance, consider the following scenario: \b $ source tests/scripts/run_testenv.sh $ guardata client gui # Connect as bob@laptop and register a new device called pc # Copy the URL Then, in a second terminal: \b $ source tests/scripts/run_testenv.sh --empty $ xdg-open "<paste the URL here>" # Or $ firefox --no-remote "<paste the URL here>" # A second instance of guardata pops-up # Enter the token to complete the registration """ trio_run(lambda: amain(**kwargs))
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)
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)
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)
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)
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)
def invite_device(config, device, **kwargs): """ Create new device invitation """ with cli_exception_handler(config.debug): trio_run(_invite_device, config, device)
def cancel_invitation(config, device, token, **kwargs): """ Cancel invitation """ with cli_exception_handler(config.debug): trio_run(_cancel_invitation, config, device, token)
def list_invitations(config, device, **kwargs): """ List invitations """ with cli_exception_handler(config.debug): trio_run(_list_invitations, config, device)
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)
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")