Spaces:
Running
Running
File size: 1,312 Bytes
d65a9ae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """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()
|