mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
18423 review changes
This commit is contained in:
parent
65e6e3c87a
commit
1a1b39d11c
@ -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.
|
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
|
## SEARCH_BACKEND
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -20,8 +21,6 @@ logger = logging.getLogger('netbox.core.files')
|
|||||||
|
|
||||||
|
|
||||||
class ManagedFile(SyncedDataMixin, models.Model):
|
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)
|
Database representation for a file on disk. This class is typically wrapped by a proxy class (e.g. ScriptModule)
|
||||||
to provide additional functionality.
|
to provide additional functionality.
|
||||||
@ -101,11 +100,9 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
|||||||
with storage.open(path, 'wb+') as new_file:
|
with storage.open(path, 'wb+') as new_file:
|
||||||
new_file.write(self.data)
|
new_file.write(self.data)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
def get_storage(self):
|
def get_storage(self):
|
||||||
if self.storage is None:
|
return storages.create_storage(storages.backends["scripts"])
|
||||||
self.storage = storages.create_storage(storages.backends["scripts"])
|
|
||||||
|
|
||||||
return self.storage
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
@ -10,6 +10,9 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class CustomStoragesLoader(importlib.abc.Loader):
|
class CustomStoragesLoader(importlib.abc.Loader):
|
||||||
|
"""
|
||||||
|
Custom loader for exec_module to use django-storages instead of the file system.
|
||||||
|
"""
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
|
@ -4,7 +4,11 @@ from django.utils.functional import cached_property
|
|||||||
|
|
||||||
|
|
||||||
class ScriptFileSystemStorage(FileSystemStorage):
|
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
|
@cached_property
|
||||||
def base_location(self):
|
def base_location(self):
|
||||||
return settings.SCRIPTS_ROOT
|
return settings.SCRIPTS_ROOT
|
||||||
|
@ -236,13 +236,18 @@ DATABASES = {
|
|||||||
#
|
#
|
||||||
|
|
||||||
if STORAGE_BACKEND is not None:
|
if STORAGE_BACKEND is not None:
|
||||||
warnings.warn(
|
if STORAGES is not None:
|
||||||
"STORAGE_BACKEND is deprecated, use the new STORAGES setting instead."
|
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:
|
if STORAGE_CONFIG is not None:
|
||||||
raise ImproperlyConfigured(
|
warnings.warn(
|
||||||
"STORAGE_BACKEND and STORAGES are both set, remove the deprecated STORAGE_BACKEND setting."
|
"STORAGE_CONFIG is deprecated, use the new STORAGES setting instead."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Default STORAGES for Django
|
# Default STORAGES for Django
|
||||||
@ -287,7 +292,7 @@ if STORAGE_BACKEND == 'swift.storage.SwiftStorage':
|
|||||||
for param, value in STORAGE_CONFIG.items():
|
for param, value in STORAGE_CONFIG.items():
|
||||||
if param.startswith('SWIFT_'):
|
if param.startswith('SWIFT_'):
|
||||||
globals()[param] = value
|
globals()[param] = value
|
||||||
|
# TODO: End of deprecated code
|
||||||
|
|
||||||
#
|
#
|
||||||
# Redis
|
# Redis
|
||||||
|
Loading…
Reference in New Issue
Block a user