From f0bb633eee66692b77a0cc99f35b4134e4e8dd49 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 2 Jun 2018 21:49:58 -0400 Subject: [PATCH] Move secret key and media root calculation code to the top of the settings file. Signed-off-by: Roberto Rosario --- mayan/settings/base.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index 9fd6726097..455c024a12 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -31,8 +31,20 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ +MEDIA_ROOT = os.environ.get( + 'MAYAN_MEDIA_ROOT', os.path.join(BASE_DIR, 'media') +) + # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = DEFAULT_SECRET_KEY +environment_secret_key = os.environ.get('MAYAN_SECRET_KEY') +if environment_secret_key: + SECRET_KEY = environment_secret_key +else: + try: + with open(os.path.join(MEDIA_ROOT, SYSTEM_DIR, SECRET_KEY_FILENAME)) as file_object: + SECRET_KEY = file_object.read().strip() + except IOError: + SECRET_KEY = DEFAULT_SECRET_KEY # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False @@ -154,13 +166,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'mayan.wsgi.application' -# Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases - -MEDIA_ROOT = os.environ.get( - 'MAYAN_MEDIA_ROOT', os.path.join(BASE_DIR, 'media') -) - # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators @@ -318,18 +323,6 @@ SWAGGER_SETTINGS = { AJAX_REDIRECT_CODE = 278 -# ----- Secret key ------ - -environment_secret_key = os.environ.get('MAYAN_SECRET_KEY') -if environment_secret_key: - SECRET_KEY = environment_secret_key -else: - try: - with open(os.path.join(MEDIA_ROOT, SYSTEM_DIR, SECRET_KEY_FILENAME)) as file_object: - SECRET_KEY = file_object.read().strip() - except IOError: - pass - # ----- Celery ----- BROKER_URL = os.environ.get('MAYAN_BROKER_URL')