Skip to content

Commit

Permalink
feat: Update how some settings are read in production.py settings files.
Browse files Browse the repository at this point in the history
Most settings in the production.py files fall back to their values in
common.py if they aren't set in the yaml config files but some
historically didn't.  Update them so that they are more in-line with the
rest of the settings in this file.
  • Loading branch information
Feanil Patel committed Mar 24, 2022
1 parent 4dc34c6 commit 7d2a834
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions cms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ def get_env_setting(setting):
# Studio. Only applies to IDA for which the social auth flow uses DOT (Django OAuth Toolkit).
IDA_LOGOUT_URI_LIST = ENV_TOKENS.get('IDA_LOGOUT_URI_LIST', [])

SITE_NAME = ENV_TOKENS['SITE_NAME']
SITE_NAME = ENV_TOKENS.get('SITE_NAME', SITE_NAME)

ALLOWED_HOSTS = [
# TODO: bbeggs remove this before prod, temp fix to get load testing running
"*",
CMS_BASE,
]

LOG_DIR = ENV_TOKENS['LOG_DIR']
LOG_DIR = ENV_TOKENS.get('LOG_DIR', LOG_DIR)
DATA_DIR = path(ENV_TOKENS.get('DATA_DIR', DATA_DIR))

CACHES = ENV_TOKENS['CACHES']
CACHES = ENV_TOKENS.get('CACHES', CACHES)
# Cache used for location mapping -- called many times with the same key/value
# in a given request.
if 'loc_cache' not in CACHES:
Expand Down Expand Up @@ -274,7 +274,7 @@ def get_env_setting(setting):
INSTALLED_APPS.append(app)

LOGGING = get_logger_config(LOG_DIR,
logging_env=ENV_TOKENS['LOGGING_ENV'],
logging_env=ENV_TOKENS.get('LOGGING_ENV', LOGGING_ENV),
service_variant=SERVICE_VARIANT)

# The following variables use (or) instead of the default value inside (get). This is to enforce using the Lazy Text
Expand Down Expand Up @@ -315,11 +315,11 @@ def get_env_setting(setting):

SECRET_KEY = AUTH_TOKENS['SECRET_KEY']

AWS_ACCESS_KEY_ID = AUTH_TOKENS["AWS_ACCESS_KEY_ID"]
AWS_ACCESS_KEY_ID = AUTH_TOKENS.get("AWS_ACCESS_KEY_ID", AWS_ACCESS_KEY_ID)
if AWS_ACCESS_KEY_ID == "":
AWS_ACCESS_KEY_ID = None

AWS_SECRET_ACCESS_KEY = AUTH_TOKENS["AWS_SECRET_ACCESS_KEY"]
AWS_SECRET_ACCESS_KEY = AUTH_TOKENS.get("AWS_SECRET_ACCESS_KEY", AWS_SECRET_ACCESS_KEY)
if AWS_SECRET_ACCESS_KEY == "":
AWS_SECRET_ACCESS_KEY = None

Expand Down Expand Up @@ -357,7 +357,7 @@ def get_env_setting(setting):
else:
COURSE_METADATA_EXPORT_STORAGE = DEFAULT_FILE_STORAGE

DATABASES = AUTH_TOKENS['DATABASES']
DATABASES = AUTH_TOKENS.get('DATABASES', DATABASES)

# The normal database user does not have enough permissions to run migrations.
# Migrations are run with separate credentials, given as DB_MIGRATION_*
Expand Down Expand Up @@ -385,8 +385,8 @@ def get_env_setting(setting):
XBLOCK_FIELD_DATA_WRAPPERS
)

CONTENTSTORE = AUTH_TOKENS['CONTENTSTORE']
DOC_STORE_CONFIG = AUTH_TOKENS['DOC_STORE_CONFIG']
CONTENTSTORE = AUTH_TOKENS.get('CONTENTSTORE', CONTENTSTORE)
DOC_STORE_CONFIG = AUTH_TOKENS.get('DOC_STORE_CONFIG', DOC_STORE_CONFIG)

############################### BLOCKSTORE #####################################
BLOCKSTORE_API_URL = ENV_TOKENS.get('BLOCKSTORE_API_URL', None) # e.g. "https://blockstore.example.com/api/v1/"
Expand Down
16 changes: 8 additions & 8 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_env_setting(setting):
EMAIL_HOST = ENV_TOKENS.get('EMAIL_HOST', 'localhost') # django default is localhost
EMAIL_PORT = ENV_TOKENS.get('EMAIL_PORT', 25) # django default is 25
EMAIL_USE_TLS = ENV_TOKENS.get('EMAIL_USE_TLS', False) # django default is False
SITE_NAME = ENV_TOKENS['SITE_NAME']
SITE_NAME = ENV_TOKENS.get('SITE_NAME', SITE_NAME)
SESSION_COOKIE_DOMAIN = ENV_TOKENS.get('SESSION_COOKIE_DOMAIN')
SESSION_COOKIE_HTTPONLY = ENV_TOKENS.get('SESSION_COOKIE_HTTPONLY', True)

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_env_setting(setting):
# By default, it's set to the same thing as the SESSION_COOKIE_DOMAIN, but we want to make it overrideable.
SHARED_COOKIE_DOMAIN = ENV_TOKENS.get('SHARED_COOKIE_DOMAIN', SESSION_COOKIE_DOMAIN)

CACHES = ENV_TOKENS['CACHES']
CACHES = ENV_TOKENS.get('CACHES', CACHES)
# Cache used for location mapping -- called many times with the same key/value
# in a given request.
if 'loc_cache' not in CACHES:
Expand Down Expand Up @@ -315,11 +315,11 @@ def get_env_setting(setting):


local_loglevel = ENV_TOKENS.get('LOCAL_LOGLEVEL', 'INFO')
LOG_DIR = ENV_TOKENS['LOG_DIR']
LOG_DIR = ENV_TOKENS.get('LOG_DIR', LOG_DIR)
DATA_DIR = path(ENV_TOKENS.get('DATA_DIR', DATA_DIR))

LOGGING = get_logger_config(LOG_DIR,
logging_env=ENV_TOKENS['LOGGING_ENV'],
logging_env=ENV_TOKENS.get('LOGGING_ENV', LOGGING_ENV),
local_loglevel=local_loglevel,
service_variant=SERVICE_VARIANT)

Expand Down Expand Up @@ -444,11 +444,11 @@ def get_env_setting(setting):

SECRET_KEY = AUTH_TOKENS['SECRET_KEY']

AWS_ACCESS_KEY_ID = AUTH_TOKENS["AWS_ACCESS_KEY_ID"]
AWS_ACCESS_KEY_ID = AUTH_TOKENS.get("AWS_ACCESS_KEY_ID", AWS_ACCESS_KEY_ID)
if AWS_ACCESS_KEY_ID == "":
AWS_ACCESS_KEY_ID = None

AWS_SECRET_ACCESS_KEY = AUTH_TOKENS["AWS_SECRET_ACCESS_KEY"]
AWS_SECRET_ACCESS_KEY = AUTH_TOKENS.get("AWS_SECRET_ACCESS_KEY", AWS_SECRET_ACCESS_KEY)
if AWS_SECRET_ACCESS_KEY == "":
AWS_SECRET_ACCESS_KEY = None

Expand All @@ -468,7 +468,7 @@ def get_env_setting(setting):

# If there is a database called 'read_replica', you can use the use_read_replica_if_available
# function in util/query.py, which is useful for very large database reads
DATABASES = AUTH_TOKENS['DATABASES']
DATABASES = AUTH_TOKENS.get('DATABASES', DATABASES)

# The normal database user does not have enough permissions to run migrations.
# Migrations are run with separate credentials, given as DB_MIGRATION_*
Expand All @@ -484,7 +484,7 @@ def get_env_setting(setting):
'PORT': os.environ.get('DB_MIGRATION_PORT', database['PORT']),
})

XQUEUE_INTERFACE = AUTH_TOKENS['XQUEUE_INTERFACE']
XQUEUE_INTERFACE = AUTH_TOKENS.get('XQUEUE_INTERFACE', XQUEUE_INTERFACE)

# Get the MODULESTORE from auth.json, but if it doesn't exist,
# use the one from common.py
Expand Down

0 comments on commit 7d2a834

Please sign in to comment.