Skip to content

Commit c919ce7

Browse files
committed
fix: address review comments
1 parent 7ab9ce3 commit c919ce7

File tree

5 files changed

+49
-20
lines changed

5 files changed

+49
-20
lines changed

credentials/settings/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,12 @@
457457
EXTRA_APPS = []
458458
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
459459
STORAGES = {
460-
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
461-
"staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"},
460+
"default": {
461+
"BACKEND": "django.core.files.storage.FileSystemStorage",
462+
},
463+
"staticfiles": {
464+
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
465+
},
462466
}
463467
CACHES = {
464468
"default": {

credentials/settings/devstack.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@
4343
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
4444
EMAIL_FILE_PATH = "/tmp/credentials-emails"
4545

46-
STORAGES["default"]["BACKEND"] = os.environ.get(
47-
STORAGES["default"]["BACKEND"], "django.core.files.storage.FileSystemStorage"
48-
)
49-
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
46+
STORAGES = {
47+
"default": {
48+
"BACKEND": "django.core.files.storage.FileSystemStorage",
49+
},
50+
"staticfiles": {
51+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
52+
},
53+
}
5054

51-
STORAGES["staticfiles"]["BACKEND"] = "django.contrib.staticfiles.storage.StaticFilesStorage"
55+
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
5256
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5357

5458
# OAuth2 variables specific to social-auth/SSO login use case.

credentials/settings/production.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# be here as a default.
2424
FILE_STORAGE_BACKEND = {}
2525

26+
STORAGES = {}
27+
2628
EMAIL_BACKEND = "django_ses.SESBackend"
2729
AWS_SES_REGION_NAME = environ.get("AWS_SES_REGION_NAME", "us-east-1")
2830
AWS_SES_REGION_ENDPOINT = environ.get("AWS_SES_REGION_ENDPOINT", "email.us-east-1.amazonaws.com")
@@ -43,20 +45,33 @@
4345
vars()[key].update(value)
4446

4547
if "DEFAULT_FILE_STORAGE" in config_from_yaml:
46-
STORAGES["default"] = {"BACKEND": config_from_yaml.pop("DEFAULT_FILE_STORAGE")}
47-
vars().update(STORAGES)
48+
STORAGES.update({
49+
"default": {
50+
"BACKEND": config_from_yaml.pop("DEFAULT_FILE_STORAGE"),
51+
}
52+
})
4853

4954
if "STATICFILES_STORAGE" in config_from_yaml:
50-
STORAGES["staticfiles"] = {"BACKEND": config_from_yaml.pop("STATICFILES_STORAGE")}
51-
vars().update(STORAGES)
55+
STORAGES.update({
56+
"staticfiles": {
57+
"BACKEND": config_from_yaml.pop("STATICFILES_STORAGE"),
58+
}
59+
})
5260

5361
vars().update(config_from_yaml)
5462

55-
if "DEFAULT_FILE_STORAGE" in FILE_STORAGE_BACKEND:
56-
FILE_STORAGE_BACKEND["STORAGES"] = {"default": {"BACKEND": FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE")}}
57-
5863
# Load the files storage backend settings for django storages
59-
vars().update(FILE_STORAGE_BACKEND)
64+
if "DEFAULT_FILE_STORAGE" in FILE_STORAGE_BACKEND:
65+
default_file_storage = FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE")
66+
vars().update(FILE_STORAGE_BACKEND)
67+
68+
FILE_STORAGE_BACKEND.update({
69+
"STORAGES": {
70+
"default": {"BACKEND": default_file_storage},
71+
}
72+
})
73+
else:
74+
vars().update(FILE_STORAGE_BACKEND)
6075

6176
# make sure this happens after the configuration file overrides so format string can be overridden
6277
LOGGING = get_logger_config(format_string=LOGGING_FORMAT_STRING)

credentials/settings/test.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@
3535

3636
# Local Directories
3737
TEST_ROOT = path("test_root")
38-
STORAGES["default"]["BACKEND"] = os.environ.get(
39-
STORAGES["default"]["BACKEND"], "django.core.files.storage.FileSystemStorage"
40-
)
38+
39+
STORAGES = {
40+
"default": {
41+
"BACKEND": "django.core.files.storage.FileSystemStorage",
42+
},
43+
"staticfiles": {
44+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
45+
},
46+
}
47+
4148
MEDIA_ROOT = str(TEST_ROOT / "uploads")
4249
MEDIA_URL = "/static/uploads/"
4350

@@ -51,7 +58,6 @@
5158
"JWT_AUDIENCE": SOCIAL_AUTH_EDX_OAUTH2_KEY,
5259
}
5360
)
54-
STORAGES["staticfiles"]["BACKEND"] = "django.contrib.staticfiles.storage.StaticFilesStorage"
5561

5662
# Verifiable Credentials
5763
ENABLE_VERIFIABLE_CREDENTIALS = True

credentials/tests/test_production.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def test_production_storage_from_yaml(monkeypatch):
9-
"""Test that YAML config correctly populates STORAGES and FILE_STORAGE_BACKEND."""
9+
"""Test that YAML config correctly populates STORAGES without leaking globals."""
1010

1111
def fake_get_env_setting(key):
1212
if key == "CREDENTIALS_CFG":

0 commit comments

Comments
 (0)