hi
This commit is contained in:
commit
2a63bc4e50
14 files changed
+1104
No files matched your search
@@ -0,0 +1,25 @@
|
||||
"""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()
|
||||
Reference in new issue
Block a user