mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Load swift config as global instead of monkey path
This commit is contained in:
parent
ad40f433da
commit
8256fefc93
@ -206,11 +206,6 @@ DATABASES = {
|
|||||||
if STORAGE_BACKEND is not None:
|
if STORAGE_BACKEND is not None:
|
||||||
DEFAULT_FILE_STORAGE = STORAGE_BACKEND
|
DEFAULT_FILE_STORAGE = STORAGE_BACKEND
|
||||||
|
|
||||||
def _setting(name, default=None):
|
|
||||||
if name in STORAGE_CONFIG:
|
|
||||||
return STORAGE_CONFIG[name]
|
|
||||||
return globals().get(name, default)
|
|
||||||
|
|
||||||
# django-storages
|
# django-storages
|
||||||
if STORAGE_BACKEND.startswith('storages.'):
|
if STORAGE_BACKEND.startswith('storages.'):
|
||||||
try:
|
try:
|
||||||
@ -224,11 +219,14 @@ if STORAGE_BACKEND is not None:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Monkey-patch django-storages to fetch settings from STORAGE_CONFIG
|
# Monkey-patch django-storages to fetch settings from STORAGE_CONFIG
|
||||||
|
def _setting(name, default=None):
|
||||||
|
if name in STORAGE_CONFIG:
|
||||||
|
return STORAGE_CONFIG[name]
|
||||||
|
return globals().get(name, default)
|
||||||
storages.utils.setting = _setting
|
storages.utils.setting = _setting
|
||||||
|
|
||||||
# django-storage-swift
|
# django-storage-swift
|
||||||
elif STORAGE_BACKEND == 'swift.storage.SwiftStorage':
|
elif STORAGE_BACKEND == 'swift.storage.SwiftStorage':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import swift.utils # type: ignore
|
import swift.utils # type: ignore
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
@ -239,9 +237,10 @@ if STORAGE_BACKEND is not None:
|
|||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Monkey-patch django-storage-swift to fetch settings from STORAGE_CONFIG
|
# Load all SWIFT_* settings from the user configuration
|
||||||
swift.utils.setting = _setting
|
for param, value in STORAGE_CONFIG.items():
|
||||||
|
if param.startswith('SWIFT_'):
|
||||||
|
globals()[param] = value
|
||||||
|
|
||||||
if STORAGE_CONFIG and STORAGE_BACKEND is None:
|
if STORAGE_CONFIG and STORAGE_BACKEND is None:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
|
Loading…
Reference in New Issue
Block a user