Verified Commit b7faf282 authored by Jakob Moser's avatar Jakob Moser
Browse files

Handle showing admin interface if vault is open

parent a09985a7
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -25,24 +25,30 @@ def parse_args() -> argparse.Namespace:
    return parser.parse_args()


def run_app() -> None:
    try:
        db.open(paths.db_file)
        app.run()
    finally:
        db.close()


args = parse_args()
vault = Vault(paths.vault_file, paths.instance_dir)

if not vault.is_open:
    # Vault was not open, so we get the password, and in case the action was "unlock", we unlock it
    password = get_password()
    if args.action == "unlock":
        with Client(socket_path) as c:
            c.send({"action": "unlock", "password": password})
else:
    print("🔓 The PoolPay database is already [green]unlocked[/green].")
    password = None

match args.action:
    case "ui":
if args.action == "ui":
    if password:
        with vault.open(password):
            try:
                db.open(paths.db_file)
                app.run()
            finally:
                db.close()
    case "unlock":
        if password is not None:
            with Client(socket_path) as c:
                c.send({"action": "unlock", "password": password})
            run_app()
    else:
        run_app()