From dcdf82cade0aec9c6256baa6bc7f06aaf994a708 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Mon, 11 Sep 2023 21:25:55 +0200 Subject: [PATCH] auto generate secret_key --- src/config/SECRET_KEY | 1 + src/config/config.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/config/SECRET_KEY create mode 100644 src/config/config.py diff --git a/src/config/SECRET_KEY b/src/config/SECRET_KEY new file mode 100644 index 0000000..0fabffb --- /dev/null +++ b/src/config/SECRET_KEY @@ -0,0 +1 @@ +b'Dn\xe2\x96\xd9\xe7Z;\xd7;\x03\xbe\xa8J\xc7\xda\xd2\xe6\xfa\xe6HU( ' \ No newline at end of file diff --git a/src/config/config.py b/src/config/config.py new file mode 100644 index 0000000..5fdab08 --- /dev/null +++ b/src/config/config.py @@ -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