Files
licensing/manage.py
T
2026-10-19 17:08:07 -05:00

26 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Provision an administrator without exposing a password in shell history."""
import argparse
import getpass
from amnesia_licensing.app import Application, Settings, USERNAME
def main():
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["create-admin"])
parser.add_argument("--username", required=True)
args = parser.parse_args()
if not USERNAME.fullmatch(args.username):
parser.error("username must contain 3–24 letters, digits or underscores")
password = getpass.getpass("Password (12–128 characters): ")
if not 12 <= len(password) <= 128 or password != getpass.getpass("Confirm password: "):
parser.error("password length invalid or confirmation did not match")
app = Application(Settings.environment())
with app.connect() as db:
db.execute("BEGIN IMMEDIATE")
account = app.create_account(db, args.username, password, "admin")
print(f"Administrator {account['username']} created with UID {account['uid']}.")
if __name__ == "__main__":
main()