Loading the rest of this comparison.

Doppler Open edX integration

Created Diff never expires
16 removals
586 lines
17 additions
588 lines
"""
"""
This is the default template for our main set of AWS servers.
This is the default template for our main set of AWS servers.


Common traits:
Common traits:
* Use memcached, and cache-backed sessions
* Use memcached, and cache-backed sessions
* Use a MySQL 5.1 database
* Use a MySQL 5.1 database
"""
"""


# We intentionally define lots of variables that aren't used, and
# We intentionally define lots of variables that aren't used, and
# want to import all variables from base settings files
# want to import all variables from base settings files
# pylint: disable=wildcard-import, unused-wildcard-import
# pylint: disable=wildcard-import, unused-wildcard-import


# Pylint gets confused by path.py instances, which report themselves as class
# Pylint gets confused by path.py instances, which report themselves as class
# objects. As a result, pylint applies the wrong regex in validating names,
# objects. As a result, pylint applies the wrong regex in validating names,
# and throws spurious errors. Therefore, we disable invalid-name checking.
# and throws spurious errors. Therefore, we disable invalid-name checking.
# pylint: disable=invalid-name
# pylint: disable=invalid-name




import codecs
import codecs
import copy
import copy
import datetime
import datetime
import os
import os
import requests


import dateutil
import dateutil
import yaml
import yaml
from corsheaders.defaults import default_headers as corsheaders_default_headers
from corsheaders.defaults import default_headers as corsheaders_default_headers
from django.core.exceptions import ImproperlyConfigured
from django.core.exceptions import ImproperlyConfigured
from edx_django_utils.plugins import add_plugins
from edx_django_utils.plugins import add_plugins
from path import Path as path
from path import Path as path


from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType
from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType
from openedx.core.lib.derived import derive_settings
from openedx.core.lib.derived import derive_settings
from openedx.core.lib.logsettings import get_logger_config
from openedx.core.lib.logsettings import get_logger_config
from xmodule.modulestore.modulestore_settings import convert_module_store_setting_if_needed
from xmodule.modulestore.modulestore_settings import convert_module_store_setting_if_needed


from .common import *
from .common import *




def get_env_setting(setting):
def get_env_setting(setting):
""" Get the environment setting or return exception """
""" Get the environment setting or return exception """
try:
try:
return os.environ[setting]
return os.environ[setting]
except KeyError:
except KeyError:
error_msg = "Set the %s env variable" % setting
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg) # lint-amnesty, pylint: disable=raise-missing-from
raise ImproperlyConfigured(error_msg) # lint-amnesty, pylint: disable=raise-missing-from


################################ ALWAYS THE SAME ##############################
################################ ALWAYS THE SAME ##############################


DEBUG = False
DEBUG = False
DEFAULT_TEMPLATE_ENGINE['OPTIONS']['debug'] = False
DEFAULT_TEMPLATE_ENGINE['OPTIONS']['debug'] = False


SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'


# IMPORTANT: With this enabled, the server must always be behind a proxy that
# IMPORTANT: With this enabled, the server must always be behind a proxy that
# strips the header HTTP_X_FORWARDED_PROTO from client requests. Otherwise,
# strips the header HTTP_X_FORWARDED_PROTO from client requests. Otherwise,
# a user can fool our server into thinking it was an https connection.
# a user can fool our server into thinking it was an https connection.
# See
# See
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
# for other warnings.
# for other warnings.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
################################ END ALWAYS THE SAME ##############################
################################ END ALWAYS THE SAME ##############################


################################### Getting Environment Variables From Doppler ###################################
url = "https://api.doppler.com/v3/configs/config/secrets"

querystring = {"project": "openedx", "config": "dev"}
DOPPLER_TOKEN = AUTH_TOKENS.get('DOPPLER_TOKEN', '')
Authorization = "Basic {DOPPLER_TOKEN}".format(DOPPLER_TOKEN=DOPPLER_TOKEN)
headers = {
"Accept": "application/json",
"accepts": "application/json",
"Authorization": Authorization
}
doppler_response = requests.request("GET", url, headers=headers, params=querystring)
EMAIL_HOST_PASSWORD = doppler_response.json()['secrets']['EMAIL_HOST_PASSWORD']['raw']
################################### END Getting Environment Variables From Doppler ###############################


# A file path to a YAML file from which to load all the configuration for the edx platform
# A file path to a YAML file from which to load all the configuration for the edx platform
CONFIG_FILE = get_env_setting('LMS_CFG')
CONFIG_FILE = get_env_setting('LMS_CFG')


with codecs.open(CONFIG_FILE, encoding='utf-8') as f:
with codecs.open(CONFIG_FILE, encoding='utf-8') as f:
__config__ = yaml.safe_load(f)
__config__ = yaml.safe_load(f)


# ENV_TOKENS and AUTH_TOKENS are included for reverse compatibility.
# ENV_TOKENS and AUTH_TOKENS are included for reverse compatibility.
# Removing them may break plugins that rely on them.
# Removing them may break plugins that rely on them.
ENV_TOKENS = __config__
ENV_TOKENS = __config__
AUTH_TOKENS = __config__
AUTH_TOKENS = __config__


# Add the key/values from config into the global namespace of this module.
# 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.
# But don't override the FEATURES dict because we do that in an additive way.
__config_copy__ = copy.deepcopy(__config__)
__config_copy__ = copy.deepcopy(__config__)


KEYS_WITH_MERGED_VALUES = [
KEYS_WITH_MERGED_VALUES = [
'FEATURES',
'FEATURES',
'TRACKING_BACKENDS',
'TRACKING_BACKENDS',
'EVENT_TRACKING_BACKENDS',
'EVENT_TRACKING_BACKENDS',
'JWT_AUTH',
'JWT_AUTH',
'CELERY_QUEUES',
'CELERY_QUEUES',
'MKTG_URL_LINK_MAP',
'MKTG_URL_LINK_MAP',
'MKTG_URL_OVERRIDES',
'MKTG_URL_OVERRIDES',
]
]
for key in KEYS_WITH_MERGED_VALUES:
for key in KEYS_WITH_MERGED_VALUES:
if key in __config_copy__:
if key in __config_copy__:
del __config_copy__[key]
del __config_copy__[key]


vars().update(__config_copy__)
vars().update(__config_copy__)




try:
try:
# A file path to a YAML file from which to load all the code revisions currently deployed
# 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')
REVISION_CONFIG_FILE = get_env_setting('REVISION_CFG')


with codecs.open(REVISION_CONFIG_FILE, encoding='utf-8') as f:
with codecs.open(REVISION_CONFIG_FILE, encoding='utf-8') as f: