nova / scripts /make_passcode.py
Senthi1Kumar's picture
Upload folder using huggingface_hub
d65a9ae verified
Raw History Blame
1.31 kB
"""Create the passcode for the Nova page and the hash to store as a secret.
python scripts/make_passcode.py # generates a random passcode
python scripts/make_passcode.py --ask # type your own (not echoed)
Paste the printed hash into the Space secret NOVA_PASSCODE_HASH. The passcode
itself is shown once and stored nowhere -- share it only with people who
should be able to talk to the Pi.
"""
from __future__ import annotations
import argparse
import getpass
import secrets
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import token_service # noqa: E402
def main() -> None:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--ask", action="store_true", help="type a passcode instead of generating one")
args = ap.parse_args()
if args.ask:
passcode = getpass.getpass("Passcode: ")
if passcode != getpass.getpass("Again: "):
sys.exit("passcodes differ")
if len(passcode) < 8:
sys.exit("use at least 8 characters")
else:
passcode = secrets.token_urlsafe(9)
print(f"Passcode (shown once): {passcode}")
print(f"NOVA_PASSCODE_HASH={token_service.hash_passcode(passcode)}")
if __name__ == "__main__":
main()