Skip to content

Commit b234834

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

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-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: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,31 @@
4343
vars()[key].update(value)
4444

4545
if "DEFAULT_FILE_STORAGE" in config_from_yaml:
46-
STORAGES["default"] = {"BACKEND": config_from_yaml.pop("DEFAULT_FILE_STORAGE")}
47-
vars().update(STORAGES)
46+
STORAGES["default"] = {
47+
"BACKEND": config_from_yaml.pop("DEFAULT_FILE_STORAGE"),
48+
}
4849

4950
if "STATICFILES_STORAGE" in config_from_yaml:
50-
STORAGES["staticfiles"] = {"BACKEND": config_from_yaml.pop("STATICFILES_STORAGE")}
51-
vars().update(STORAGES)
51+
STORAGES["staticfiles"] = {
52+
"BACKEND": config_from_yaml.pop("STATICFILES_STORAGE"),
53+
}
5254

5355
vars().update(config_from_yaml)
5456

55-
if "DEFAULT_FILE_STORAGE" in FILE_STORAGE_BACKEND:
56-
FILE_STORAGE_BACKEND["STORAGES"] = {"default": {"BACKEND": FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE")}}
57-
5857
# Load the files storage backend settings for django storages
59-
vars().update(FILE_STORAGE_BACKEND)
58+
if "DEFAULT_FILE_STORAGE" in FILE_STORAGE_BACKEND:
59+
default_file_storage = FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE") or STORAGES["default"]["BACKEND"]
60+
vars().update(FILE_STORAGE_BACKEND)
61+
62+
FILE_STORAGE_BACKEND.update(
63+
{
64+
"STORAGES": {
65+
"default": {"BACKEND": default_file_storage},
66+
}
67+
}
68+
)
69+
else:
70+
vars().update(FILE_STORAGE_BACKEND)
6071

6172
# make sure this happens after the configuration file overrides so format string can be overridden
6273
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)