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
2023-11-03 21:41:28 +01:00

22 lines
512 B
Python

import secrets
import click
from advlabdb import data_dir
def _generate_secrets():
file = data_dir / "secrets.ini"
if file.is_file():
click.echo(f"Skipping secrets generation because the secrets file already exists at {file}.")
return
with file.open("w") as f:
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")