mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-09-19 18:31:16 +00:00
22 lines
506 B
Python
22 lines
506 B
Python
|
import secrets
|
||
|
from pathlib import Path
|
||
|
|
||
|
import click
|
||
|
|
||
|
|
||
|
def _generate_secrets():
|
||
|
file = Path("secrets.ini")
|
||
|
|
||
|
if file.is_file():
|
||
|
click.echo(f"Skipping secrets generation because the secrets file does already exist at {file}.")
|
||
|
return
|
||
|
|
||
|
with open(file, "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")
|