18423 review changes

This commit is contained in:
Arthur 2025-03-05 14:41:27 -08:00
parent 65e6e3c87a
commit 1a1b39d11c
5 changed files with 23 additions and 16 deletions

View File

@ -186,8 +186,6 @@ Default: `$INSTALL_ROOT/netbox/scripts/`
The file path to the location where [custom scripts](../customization/custom-scripts.md) will be kept. By default, this is the `netbox/scripts/` directory within the base NetBox installation path.
**Note:** If configuring STORAGES to use AWS S3 set SCRIPTS_ROOT to the prefix (or folder) you want scripts stored in, for example: `scripts`
---
## SEARCH_BACKEND

View File

@ -1,5 +1,6 @@
import logging
import os
from functools import cached_property
from django.conf import settings
from django.core.exceptions import ValidationError
@ -20,8 +21,6 @@ logger = logging.getLogger('netbox.core.files')
class ManagedFile(SyncedDataMixin, models.Model):
storage = None
"""
Database representation for a file on disk. This class is typically wrapped by a proxy class (e.g. ScriptModule)
to provide additional functionality.
@ -101,11 +100,9 @@ class ManagedFile(SyncedDataMixin, models.Model):
with storage.open(path, 'wb+') as new_file:
new_file.write(self.data)
@cached_property
def get_storage(self):
if self.storage is None:
self.storage = storages.create_storage(storages.backends["scripts"])
return self.storage
return storages.create_storage(storages.backends["scripts"])
def clean(self):
super().clean()

View File

@ -10,6 +10,9 @@ __all__ = (
class CustomStoragesLoader(importlib.abc.Loader):
"""
Custom loader for exec_module to use django-storages instead of the file system.
"""
def __init__(self, filename):
self.filename = filename

View File

@ -4,7 +4,11 @@ from django.utils.functional import cached_property
class ScriptFileSystemStorage(FileSystemStorage):
"""
Custom storage for scripts - for django-storages as the default one will
go off media-root and raise security errors as the scripts can be outside
the media-root directory.
"""
@cached_property
def base_location(self):
return settings.SCRIPTS_ROOT

View File

@ -236,13 +236,18 @@ DATABASES = {
#
if STORAGE_BACKEND is not None:
if STORAGES is not None:
raise ImproperlyConfigured(
"STORAGE_BACKEND and STORAGES are both set, remove the deprecated STORAGE_BACKEND setting."
)
else:
warnings.warn(
"STORAGE_BACKEND is deprecated, use the new STORAGES setting instead."
)
if STORAGE_BACKEND is not None and STORAGES is not None:
raise ImproperlyConfigured(
"STORAGE_BACKEND and STORAGES are both set, remove the deprecated STORAGE_BACKEND setting."
if STORAGE_CONFIG is not None:
warnings.warn(
"STORAGE_CONFIG is deprecated, use the new STORAGES setting instead."
)
# Default STORAGES for Django
@ -287,7 +292,7 @@ if STORAGE_BACKEND == 'swift.storage.SwiftStorage':
for param, value in STORAGE_CONFIG.items():
if param.startswith('SWIFT_'):
globals()[param] = value
# TODO: End of deprecated code
#
# Redis