auto generate secret_key

This commit is contained in:
grimhilt 2023-09-11 21:25:55 +02:00
parent 9d388cd0c5
commit dcdf82cade
2 changed files with 20 additions and 0 deletions

1
src/config/SECRET_KEY Normal file
View File

@ -0,0 +1 @@
b'Dn\xe2\x96\xd9\xe7Z;\xd7;\x03\xbe\xa8J\xc7\xda\xd2\xe6\xfa\xe6HU( '

19
src/config/config.py Normal file
View File

@ -0,0 +1,19 @@
import os
import random
import string
SECRET_KEY_FILE = './src/config/SECRET_KEY'
def get_secret_key():
if os.path.isfile(SECRET_KEY_FILE):
# read the secret key from the file
with open(SECRET_KEY_FILE, 'r') as file:
secret_key = file.read().strip()
return secret_key
else:
# generate a new secret key
secret_key = os.urandom(24)
# save it to the file
with open(SECRET_KEY_FILE, 'w') as file:
file.write(str(secret_key))
return secret_key