mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
added config option to disable plugins
This commit is contained in:
@ -187,6 +187,18 @@ PREFER_IPV4 = False
|
|||||||
# this setting is derived from the installed location.
|
# this setting is derived from the installed location.
|
||||||
# SCRIPTS_ROOT = '/opt/netbox/netbox/scripts'
|
# SCRIPTS_ROOT = '/opt/netbox/netbox/scripts'
|
||||||
|
|
||||||
|
# Enable plugin support in netbox. This setting must be enabled for any installed plugins to function.
|
||||||
|
PLUGINS_ENABLED = False
|
||||||
|
|
||||||
|
# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
|
||||||
|
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
|
||||||
|
# PLUGINS_CONFIG = {
|
||||||
|
# 'my_plugin': {
|
||||||
|
# 'foo': 'bar',
|
||||||
|
# 'buzz': 'bazz'
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
# By default, NetBox will store session data in the database. Alternatively, a file path can be specified here to use
|
# By default, NetBox will store session data in the database. Alternatively, a file path can be specified here to use
|
||||||
# local file storage instead. (This can be useful for enabling authentication on a standby instance with read-only
|
# local file storage instead. (This can be useful for enabling authentication on a standby instance with read-only
|
||||||
# database access.) Note that the user as which NetBox runs must have read and write permissions to this path.
|
# database access.) Note that the user as which NetBox runs must have read and write permissions to this path.
|
||||||
|
@ -95,6 +95,7 @@ NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30)
|
|||||||
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
||||||
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
||||||
PLUGINS_CONFIG = getattr(configuration, 'PLUGINS_CONFIG', {})
|
PLUGINS_CONFIG = getattr(configuration, 'PLUGINS_CONFIG', {})
|
||||||
|
PLUGINS_ENABLED = getattr(configuration, 'PLUGINS_ENABLED', False)
|
||||||
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
||||||
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
|
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
|
||||||
SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/')
|
SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/')
|
||||||
@ -601,48 +602,49 @@ if PAGINATE_COUNT not in PER_PAGE_DEFAULTS:
|
|||||||
#
|
#
|
||||||
|
|
||||||
PLUGINS = []
|
PLUGINS = []
|
||||||
for entry_point in iter_entry_points(group='netbox.plugin', name=None):
|
if PLUGINS_ENABLED:
|
||||||
plugin = entry_point.module_name
|
for entry_point in iter_entry_points(group='netbox.plugin', name=None):
|
||||||
PLUGINS.append(plugin)
|
plugin = entry_point.module_name
|
||||||
INSTALLED_APPS.append(plugin)
|
PLUGINS.append(plugin)
|
||||||
|
INSTALLED_APPS.append(plugin)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(plugin)
|
module = importlib.import_module(plugin)
|
||||||
default_app_config = getattr(module, 'default_app_config')
|
default_app_config = getattr(module, 'default_app_config')
|
||||||
module, app_config = default_app_config.rsplit('.', 1)
|
module, app_config = default_app_config.rsplit('.', 1)
|
||||||
app_config = getattr(importlib.import_module(module), app_config)
|
app_config = getattr(importlib.import_module(module), app_config)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImproperlyConfigured('Plugin config for {} could not be imported!'.format(plugin))
|
raise ImproperlyConfigured('Plugin config for {} could not be imported!'.format(plugin))
|
||||||
|
|
||||||
app_config_meta = getattr(app_config, 'NetBoxPluginMeta', None)
|
app_config_meta = getattr(app_config, 'NetBoxPluginMeta', None)
|
||||||
if not app_config_meta:
|
if not app_config_meta:
|
||||||
raise ImproperlyConfigured(
|
|
||||||
'The app config for plugin {} does not contain an inner meta class'.format(plugin)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add middleware
|
|
||||||
plugin_middleware = getattr(app_config_meta, 'middleware', [])
|
|
||||||
if plugin_middleware and isinstance(plugin_middleware, list):
|
|
||||||
MIDDLEWARE.extend(plugin_middleware)
|
|
||||||
|
|
||||||
# Add installed apps
|
|
||||||
plugin_installed_apps = getattr(app_config_meta, 'installed_apps', [])
|
|
||||||
if plugin_installed_apps and isinstance(plugin_installed_apps, list):
|
|
||||||
INSTALLED_APPS.extend(plugin_installed_apps)
|
|
||||||
|
|
||||||
# Verify required configuration settings
|
|
||||||
if plugin not in PLUGINS_CONFIG:
|
|
||||||
PLUGINS_CONFIG[plugin] = {}
|
|
||||||
for setting in getattr(app_config_meta, 'required_settings', []):
|
|
||||||
if setting not in PLUGINS_CONFIG[plugin]:
|
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"Plugin {} requires '{}' to be present in the PLUGINS_CONFIG section of configuration.py.".format(
|
'The app config for plugin {} does not contain an inner meta class'.format(plugin)
|
||||||
plugin,
|
|
||||||
setting
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set defined default setting values
|
# Add middleware
|
||||||
for setting, value in getattr(app_config_meta, 'default_settings', {}).items():
|
plugin_middleware = getattr(app_config_meta, 'middleware', [])
|
||||||
if setting not in PLUGINS_CONFIG[plugin]:
|
if plugin_middleware and isinstance(plugin_middleware, list):
|
||||||
PLUGINS_CONFIG[plugin][setting] = value
|
MIDDLEWARE.extend(plugin_middleware)
|
||||||
|
|
||||||
|
# Add installed apps
|
||||||
|
plugin_installed_apps = getattr(app_config_meta, 'installed_apps', [])
|
||||||
|
if plugin_installed_apps and isinstance(plugin_installed_apps, list):
|
||||||
|
INSTALLED_APPS.extend(plugin_installed_apps)
|
||||||
|
|
||||||
|
# Verify required configuration settings
|
||||||
|
if plugin not in PLUGINS_CONFIG:
|
||||||
|
PLUGINS_CONFIG[plugin] = {}
|
||||||
|
for setting in getattr(app_config_meta, 'required_settings', []):
|
||||||
|
if setting not in PLUGINS_CONFIG[plugin]:
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"Plugin {} requires '{}' to be present in the PLUGINS_CONFIG section of configuration.py.".format(
|
||||||
|
plugin,
|
||||||
|
setting
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set defined default setting values
|
||||||
|
for setting, value in getattr(app_config_meta, 'default_settings', {}).items():
|
||||||
|
if setting not in PLUGINS_CONFIG[plugin]:
|
||||||
|
PLUGINS_CONFIG[plugin][setting] = value
|
||||||
|
Reference in New Issue
Block a user