diff --git a/etesync_server/settings.py b/etesync_server/settings.py index ad433cb..fe65225 100644 --- a/etesync_server/settings.py +++ b/etesync_server/settings.py @@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/1.10/ref/settings/ """ import os -from django.core.management import utils +from .utils import get_secret_from_file # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -21,15 +21,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY_FILE = os.path.join(BASE_DIR, "secret.txt") - -try: - with open(SECRET_KEY_FILE, "r") as f: - SECRET_KEY = f.read().strip() -except EnvironmentError: - with open(SECRET_KEY_FILE, "w") as f: - SECRET_KEY = utils.get_random_secret_key() - f.write(SECRET_KEY) +# See secret.py for how this is generated; uses a file 'secret.txt' in the root +# directory +SECRET_KEY = get_secret_from_file(os.path.join(BASE_DIR, "secret.txt")) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False diff --git a/etesync_server/utils.py b/etesync_server/utils.py new file mode 100644 index 0000000..8f85f10 --- /dev/null +++ b/etesync_server/utils.py @@ -0,0 +1,11 @@ +from django.core.management import utils + +def get_secret_from_file(path): + try: + with open(path, "r") as f: + return f.read().strip() + except EnvironmentError: + with open(path, "w") as f: + secret_key = utils.get_random_secret_key() + f.write(secret_key) + return secret_key