1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/cli/setup/generate_secrets/main.py

23 lines
512 B
Python
Raw Permalink Normal View History

2022-08-14 00:54:22 +00:00
import secrets
import click
2022-08-18 01:20:52 +00:00
from advlabdb import data_dir
2022-08-14 00:54:22 +00:00
def _generate_secrets():
2022-08-18 01:20:52 +00:00
file = data_dir / "secrets.ini"
2022-08-14 00:54:22 +00:00
if file.is_file():
2023-11-03 20:41:28 +00:00
click.echo(f"Skipping secrets generation because the secrets file already exists at {file}.")
2022-08-14 00:54:22 +00:00
return
2023-11-02 18:44:24 +00:00
with file.open("w") as f:
2022-08-14 00:54:22 +00:00
f.write("[Secrets]\n")
key = secrets.SystemRandom().getrandbits(128)
f.write(f"SECRET_KEY = {key}\n")
salt = secrets.token_hex()
f.write(f"SECURITY_PASSWORD_SALT = {salt}\n")