diff --git a/docs/configuration/system.md b/docs/configuration/system.md index a1e0ebb17..f3c68db1b 100644 --- a/docs/configuration/system.md +++ b/docs/configuration/system.md @@ -177,7 +177,7 @@ The dotted path to the desired search backend class. `CachedValueSearchBackend` Default: None (local storage) -The backend storage engine for handling uploaded files (e.g. image attachments). NetBox supports integration with the [`django-storages`](https://django-storages.readthedocs.io/en/stable/) package, which provides backends for several popular file storage services. If not configured, local filesystem storage will be used. +The backend storage engine for handling uploaded files (e.g. image attachments). NetBox supports integration with the [`django-storages`](https://django-storages.readthedocs.io/en/stable/) and [`django-storage-swift`](https://github.com/dennisv/django-storage-swift) packages, which provide backends for several popular file storage services. If not configured, local filesystem storage will be used. The configuration parameters for the specified storage backend are defined under the `STORAGE_CONFIG` setting. @@ -187,7 +187,7 @@ The configuration parameters for the specified storage backend are defined under Default: Empty -A dictionary of configuration parameters for the storage backend configured as `STORAGE_BACKEND`. The specific parameters to be used here are specific to each backend; see the [`django-storages` documentation](https://django-storages.readthedocs.io/en/stable/) for more detail. +A dictionary of configuration parameters for the storage backend configured as `STORAGE_BACKEND`. The specific parameters to be used here are specific to each backend; see the documentation for your selected backend ([`django-storages`](https://django-storages.readthedocs.io/en/stable/) or [`django-storage-swift`](https://github.com/dennisv/django-storage-swift)) for more detail. If `STORAGE_BACKEND` is not defined, this setting will be ignored. diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 3a8e51e05..7a248c875 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -225,6 +225,23 @@ if STORAGE_BACKEND is not None: return globals().get(name, default) storages.utils.setting = _setting + # django-storage-swift + elif STORAGE_BACKEND == 'swift.storage.SwiftStorage': + try: + import swift.utils # type: ignore + except ModuleNotFoundError as e: + if getattr(e, 'name') == 'swift': + raise ImproperlyConfigured( + f"STORAGE_BACKEND is set to {STORAGE_BACKEND} but django-storage-swift is not present. " + "It can be installed by running 'pip install django-storage-swift'." + ) + raise e + + # Load all SWIFT_* settings from the user configuration + for param, value in STORAGE_CONFIG.items(): + if param.startswith('SWIFT_'): + globals()[param] = value + if STORAGE_CONFIG and STORAGE_BACKEND is None: warnings.warn( "STORAGE_CONFIG has been set in configuration.py but STORAGE_BACKEND is not defined. STORAGE_CONFIG will be "