From e654036d546d88ac2f2a1615747b213e2d44c694 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 3 Jan 2020 11:16:03 -0500 Subject: [PATCH 1/2] Load any AWS_ prefixed settings from ENV_TOKENS to allow S3Boto3Storage to be correctly configured --- cms/envs/production.py | 6 ++++++ lms/envs/production.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/cms/envs/production.py b/cms/envs/production.py index b4604bf34e..a2228bf117 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -214,6 +214,12 @@ if 'staticfiles' in CACHES: # managed by the yaml file contents STATICFILES_STORAGE = os.environ.get('STATICFILES_STORAGE', ENV_TOKENS.get('STATICFILES_STORAGE', STATICFILES_STORAGE)) +# Load all AWS_ prefixed variables to allow an S3Boto3Storage to be configured +_locals = locals() +for key, value in ENV_TOKENS.items(): + if key.startswith('AWS_'): + _locals[key] = value + SESSION_COOKIE_DOMAIN = ENV_TOKENS.get('SESSION_COOKIE_DOMAIN') SESSION_COOKIE_HTTPONLY = ENV_TOKENS.get('SESSION_COOKIE_HTTPONLY', True) SESSION_ENGINE = ENV_TOKENS.get('SESSION_ENGINE', SESSION_ENGINE) diff --git a/lms/envs/production.py b/lms/envs/production.py index 8292f1a66e..4fe8e2b9ff 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -250,6 +250,12 @@ if 'staticfiles' in CACHES: # managed by the yaml file contents STATICFILES_STORAGE = os.environ.get('STATICFILES_STORAGE', ENV_TOKENS.get('STATICFILES_STORAGE', STATICFILES_STORAGE)) +# Load all AWS_ prefixed variables to allow an S3Boto3Storage to be configured +_locals = locals() +for key, value in ENV_TOKENS.items(): + if key.startswith('AWS_'): + _locals[key] = value + # Email overrides DEFAULT_FROM_EMAIL = ENV_TOKENS.get('DEFAULT_FROM_EMAIL', DEFAULT_FROM_EMAIL) DEFAULT_FEEDBACK_EMAIL = ENV_TOKENS.get('DEFAULT_FEEDBACK_EMAIL', DEFAULT_FEEDBACK_EMAIL) From e11e9d9073ef295df12c10aa78578ac065414dcd Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 3 Jan 2020 12:14:02 -0500 Subject: [PATCH 2/2] Allow overriding ProductionStorage and ProductionS3Storage kwargs with a django settings value --- cms/envs/common.py | 1 + lms/envs/common.py | 1 + openedx/core/storage.py | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index c2f77d38da..8bffb25198 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -935,6 +935,7 @@ PIPELINE = { } STATICFILES_STORAGE = 'openedx.core.storage.ProductionStorage' +STATICFILES_STORAGE_KWARGS = {} # List of finder classes that know how to find static files in various locations. # Note: the pipeline finder is included to be able to discover optimized files diff --git a/lms/envs/common.py b/lms/envs/common.py index 115dcfb989..0443f9d2ab 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1548,6 +1548,7 @@ PIPELINE = { } STATICFILES_STORAGE = 'openedx.core.storage.ProductionStorage' +STATICFILES_STORAGE_KWARGS = {} # List of finder classes that know how to find static files in various locations. # Note: the pipeline finder is included to be able to discover optimized files diff --git a/openedx/core/storage.py b/openedx/core/storage.py index 885e8a62ce..fefad2ee4a 100644 --- a/openedx/core/storage.py +++ b/openedx/core/storage.py @@ -3,6 +3,7 @@ Django storage backends for Open edX. """ +from django.conf import settings from django.contrib.staticfiles.storage import StaticFilesStorage from django.core.files.storage import get_storage_class, FileSystemStorage from django.utils.deconstruct import deconstructible @@ -51,7 +52,9 @@ class ProductionMixin( can be applied over an existing Storage. We use this version on production. """ - pass + def __init__(self, *args, **kwargs): + kwargs.update(settings.STATICFILES_STORAGE_KWARGS.get(settings.STATICFILES_STORAGE, {})) + super(ProductionMixin, self).__init__(*args, **kwargs) class ProductionStorage(ProductionMixin, StaticFilesStorage):