From 7c0c71ca6904d819b35a803184340b35f424fbd0 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 7 Feb 2020 15:33:06 -0500 Subject: [PATCH 1/3] Auto load any keys/values from the yaml config file. This should allow us to remove all the boilerplate code in this file where a name is pulled from the config dict and put into the top level namespace of the settings module. We do this first so that any logic that adds more complex or dynamic keys will still run and is safe. Now that this is here we can start removing any simple boilerplate. --- cms/envs/production.py | 3 +++ lms/envs/production.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cms/envs/production.py b/cms/envs/production.py index 0b5302de7e..1bd8581cc4 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -38,6 +38,9 @@ CONFIG_FILE = get_env_setting('STUDIO_CFG') with codecs.open(CONFIG_FILE, encoding='utf-8') as f: __config__ = yaml.safe_load(f) + # Add the key/values from config into the global namespace of this module. + vars().update(__config__) + # ENV_TOKENS and AUTH_TOKENS are included for reverse compatability. # Removing them may break plugins that rely on them. ENV_TOKENS = __config__ diff --git a/lms/envs/production.py b/lms/envs/production.py index dcf8a4592d..56dccb4c21 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -50,6 +50,9 @@ CONFIG_FILE = get_env_setting('LMS_CFG') with codecs.open(CONFIG_FILE, encoding='utf-8') as f: __config__ = yaml.safe_load(f) + # Add the key/values from config into the global namespace of this module. + vars().update(__config__) + # ENV_TOKENS and AUTH_TOKENS are included for reverse compatability. # Removing them may break plugins that rely on them. ENV_TOKENS = __config__ From 75f663791e75641a5e325464b1064902b6e5630c Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Mon, 2 Mar 2020 14:26:47 -0500 Subject: [PATCH 2/3] Account for dicts that don't get replaced wholesale. Right now we have a few settings that are not whoesale replaced but piecemeal updated. So we remove them from the mass update. --- cms/envs/production.py | 14 +++++++++++--- lms/envs/production.py | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cms/envs/production.py b/cms/envs/production.py index 1bd8581cc4..75e4d73a75 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -8,6 +8,7 @@ This is the default template for our main set of AWS servers. import codecs +import copy import os import yaml @@ -38,14 +39,21 @@ CONFIG_FILE = get_env_setting('STUDIO_CFG') with codecs.open(CONFIG_FILE, encoding='utf-8') as f: __config__ = yaml.safe_load(f) - # Add the key/values from config into the global namespace of this module. - vars().update(__config__) - # ENV_TOKENS and AUTH_TOKENS are included for reverse compatability. # Removing them may break plugins that rely on them. ENV_TOKENS = __config__ AUTH_TOKENS = __config__ + # Add the key/values from config into the global namespace of this module. + # But don't override the FEATURES dict because we do that in an additive way. + __config_copy__ = copy.deepcopy(__config__) + if 'FEATURES' in __config_copy__: + del __config_copy__['FEATURES'] + + if 'EVENT_TRACKING_BACKENDS' in __config_copy__: + del __config_copy__['EVENT_TRACKING_BACKENDS'] + vars().update(__config_copy__) + # A file path to a YAML file from which to load all the code revisions currently deployed REVISION_CONFIG_FILE = get_env_setting('REVISION_CFG') diff --git a/lms/envs/production.py b/lms/envs/production.py index 56dccb4c21..c7fc40ade2 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -19,6 +19,7 @@ Common traits: import codecs +import copy import datetime import os @@ -50,14 +51,22 @@ CONFIG_FILE = get_env_setting('LMS_CFG') with codecs.open(CONFIG_FILE, encoding='utf-8') as f: __config__ = yaml.safe_load(f) - # Add the key/values from config into the global namespace of this module. - vars().update(__config__) - # ENV_TOKENS and AUTH_TOKENS are included for reverse compatability. # Removing them may break plugins that rely on them. ENV_TOKENS = __config__ AUTH_TOKENS = __config__ + # Add the key/values from config into the global namespace of this module. + # But don't override the FEATURES dict because we do that in an additive way. + __config_copy__ = copy.deepcopy(__config__) + if 'FEATURES' in __config_copy__: + del __config_copy__['FEATURES'] + + if 'EVENT_TRACKING_BACKENDS' in __config_copy__: + del __config_copy__['EVENT_TRACKING_BACKENDS'] + vars().update(__config_copy__) + + # A file path to a YAML file from which to load all the code revisions currently deployed REVISION_CONFIG_FILE = get_env_setting('REVISION_CFG') From bf320f038b27e999eb083f0b1415d8530159eed6 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Thu, 9 Apr 2020 15:18:57 -0400 Subject: [PATCH 3/3] Find more vars that are partially updated. --- cms/envs/production.py | 17 +++++++++++++---- lms/envs/production.py | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cms/envs/production.py b/cms/envs/production.py index 75e4d73a75..98fee62bf8 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -47,11 +47,20 @@ with codecs.open(CONFIG_FILE, encoding='utf-8') as f: # Add the key/values from config into the global namespace of this module. # But don't override the FEATURES dict because we do that in an additive way. __config_copy__ = copy.deepcopy(__config__) - if 'FEATURES' in __config_copy__: - del __config_copy__['FEATURES'] - if 'EVENT_TRACKING_BACKENDS' in __config_copy__: - del __config_copy__['EVENT_TRACKING_BACKENDS'] + KEYS_WITH_MERGED_VALUES = [ + 'FEATURES', + 'TRACKING_BACKENDS', + 'EVENT_TRACKING_BACKENDS', + 'JWT_AUTH', + 'CELERY_QUEUES', + 'MKTG_URL_LINK_MAP', + 'MKTG_URL_OVERRIDES', + ] + for key in KEYS_WITH_MERGED_VALUES: + if key in __config_copy__: + del __config_copy__[key] + vars().update(__config_copy__) diff --git a/lms/envs/production.py b/lms/envs/production.py index c7fc40ade2..c8a1164db2 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -59,11 +59,20 @@ with codecs.open(CONFIG_FILE, encoding='utf-8') as f: # Add the key/values from config into the global namespace of this module. # But don't override the FEATURES dict because we do that in an additive way. __config_copy__ = copy.deepcopy(__config__) - if 'FEATURES' in __config_copy__: - del __config_copy__['FEATURES'] - if 'EVENT_TRACKING_BACKENDS' in __config_copy__: - del __config_copy__['EVENT_TRACKING_BACKENDS'] + KEYS_WITH_MERGED_VALUES = [ + 'FEATURES', + 'TRACKING_BACKENDS', + 'EVENT_TRACKING_BACKENDS', + 'JWT_AUTH', + 'CELERY_QUEUES', + 'MKTG_URL_LINK_MAP', + 'MKTG_URL_OVERRIDES', + ] + for key in KEYS_WITH_MERGED_VALUES: + if key in __config_copy__: + del __config_copy__[key] + vars().update(__config_copy__)