From 532294b7a5575a2d07b20a11b2e65f0d619bb919 Mon Sep 17 00:00:00 2001 From: type-two Date: Thu, 16 Jul 2026 22:29:08 +1000 Subject: [PATCH] =?UTF-8?q?users.py:=20'token=20'=20subcommand=20?= =?UTF-8?q?=E2=80=94=20mint=20named=20API=20keys=20from=20the=20CLI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- scripts/users.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/users.py b/scripts/users.py index 1e7c54b..3efd993 100644 --- a/scripts/users.py +++ b/scripts/users.py @@ -24,6 +24,9 @@ def main(): p.add_argument("username") d = sub.add_parser("delete") d.add_argument("username") + t = sub.add_parser("token", help="mint a named API token (printed ONCE — store it in a .env)") + t.add_argument("name", help="what this key is for, e.g. m1ultra, deadstock-agent") + t.add_argument("--user", default=None, help="username to bind to (default: the owner)") args = ap.parse_args() if args.cmd == "add": @@ -47,6 +50,16 @@ def main(): sys.exit("no such user") auth.delete_user(con, u["id"]) print("deleted") + elif args.cmd == "token": + if args.user: + u = auth.get_user_by_name(con, args.user) + else: + u = next((x for x in auth.list_users(con) if x["role"] == "owner"), None) + if not u: + sys.exit("no such user") + raw = auth.create_token(con, u["id"], name=args.name) + print(f"# token '{args.name}' for {u['username']} — shown once, goes in a .env:") + print(f"MB_TOKEN={raw}") if __name__ == "__main__":