2020-02-29 02:23:01 -05:00
|
|
|
import importlib
|
2016-07-08 17:09:35 -04:00
|
|
|
import logging
|
2016-03-01 11:23:03 -05:00
|
|
|
import os
|
2019-04-22 16:33:28 -04:00
|
|
|
import platform
|
2020-01-24 00:15:32 +01:00
|
|
|
import re
|
2016-03-01 11:23:03 -05:00
|
|
|
import socket
|
2017-11-14 15:07:13 -05:00
|
|
|
import warnings
|
2020-01-26 16:50:15 +01:00
|
|
|
from urllib.parse import urlsplit
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
from django.contrib.messages import constants as messages
|
2020-03-13 10:20:09 -04:00
|
|
|
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
|
|
|
from django.core.validators import URLValidator
|
2020-03-18 18:28:27 -04:00
|
|
|
from pkg_resources import iter_entry_points, parse_version
|
2016-05-24 11:46:55 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Environment setup
|
|
|
|
#
|
|
|
|
|
2020-01-29 16:46:44 -05:00
|
|
|
VERSION = '2.8.0-dev'
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
# Hostname
|
|
|
|
HOSTNAME = platform.node()
|
|
|
|
|
|
|
|
# Set the base directory two levels up
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2019-12-10 13:44:45 -05:00
|
|
|
# Validate Python version
|
2020-03-12 11:46:11 -04:00
|
|
|
if platform.python_version_tuple() < ('3', '6'):
|
2018-08-14 11:47:54 -04:00
|
|
|
raise RuntimeError(
|
2020-03-12 11:46:11 -04:00
|
|
|
"NetBox requires Python 3.6 or higher (current: Python {})".format(platform.python_version())
|
2019-12-10 13:44:45 -05:00
|
|
|
)
|
2018-08-14 11:47:54 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Configuration import
|
|
|
|
#
|
|
|
|
|
|
|
|
# Import configuration parameters
|
2016-05-24 11:46:55 -04:00
|
|
|
try:
|
2017-01-23 22:44:29 +01:00
|
|
|
from netbox import configuration
|
2016-05-24 11:46:55 -04:00
|
|
|
except ImportError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"Configuration file is not present. Please define netbox/netbox/configuration.py per the documentation."
|
|
|
|
)
|
2016-05-24 11:46:55 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
# Enforce required configuration parameters
|
|
|
|
for parameter in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY', 'REDIS']:
|
|
|
|
if not hasattr(configuration, parameter):
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
2019-04-22 16:33:28 -04:00
|
|
|
"Required parameter {} is missing from configuration.py.".format(parameter)
|
2017-03-21 13:53:07 -04:00
|
|
|
)
|
2016-05-24 11:46:55 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
# Set required parameters
|
|
|
|
ALLOWED_HOSTS = getattr(configuration, 'ALLOWED_HOSTS')
|
|
|
|
DATABASE = getattr(configuration, 'DATABASE')
|
|
|
|
REDIS = getattr(configuration, 'REDIS')
|
|
|
|
SECRET_KEY = getattr(configuration, 'SECRET_KEY')
|
|
|
|
|
|
|
|
# Set optional parameters
|
2016-05-24 14:24:35 -04:00
|
|
|
ADMINS = getattr(configuration, 'ADMINS', [])
|
2017-09-15 15:28:09 -04:00
|
|
|
BANNER_BOTTOM = getattr(configuration, 'BANNER_BOTTOM', '')
|
|
|
|
BANNER_LOGIN = getattr(configuration, 'BANNER_LOGIN', '')
|
|
|
|
BANNER_TOP = getattr(configuration, 'BANNER_TOP', '')
|
2016-09-29 16:32:16 -04:00
|
|
|
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
|
|
|
if BASE_PATH:
|
|
|
|
BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only
|
2019-04-15 03:55:33 -04:00
|
|
|
CACHE_TIMEOUT = getattr(configuration, 'CACHE_TIMEOUT', 900)
|
2018-06-22 16:18:41 -04:00
|
|
|
CHANGELOG_RETENTION = getattr(configuration, 'CHANGELOG_RETENTION', 90)
|
2017-06-09 15:03:10 -04:00
|
|
|
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
|
|
|
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])
|
|
|
|
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
|
|
|
|
DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y')
|
|
|
|
DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a')
|
|
|
|
DEBUG = getattr(configuration, 'DEBUG', False)
|
2020-01-30 10:12:53 -05:00
|
|
|
DEVELOPER = getattr(configuration, 'DEVELOPER', False)
|
2020-03-06 09:35:58 -05:00
|
|
|
DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs'))
|
2017-06-09 15:03:10 -04:00
|
|
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
2019-04-11 22:01:26 -04:00
|
|
|
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
|
|
|
|
EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
|
2017-06-09 15:03:10 -04:00
|
|
|
LOGGING = getattr(configuration, 'LOGGING', {})
|
|
|
|
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
|
2018-11-14 14:18:32 -05:00
|
|
|
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)
|
2016-05-24 12:52:05 -04:00
|
|
|
MAINTENANCE_MODE = getattr(configuration, 'MAINTENANCE_MODE', False)
|
2017-06-09 15:03:10 -04:00
|
|
|
MAX_PAGE_SIZE = getattr(configuration, 'MAX_PAGE_SIZE', 1000)
|
2017-08-30 11:11:59 -04:00
|
|
|
MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/')
|
2019-12-11 16:09:32 +01:00
|
|
|
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
|
|
|
|
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
|
2019-06-17 16:37:38 -04:00
|
|
|
METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False)
|
2019-04-22 16:33:28 -04:00
|
|
|
NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {})
|
2017-07-26 11:24:19 -04:00
|
|
|
NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '')
|
2017-07-26 11:47:59 -04:00
|
|
|
NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30)
|
2019-04-22 16:33:28 -04:00
|
|
|
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
2017-08-30 11:11:59 -04:00
|
|
|
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
2020-02-29 02:23:01 -05:00
|
|
|
PLUGINS_CONFIG = getattr(configuration, 'PLUGINS_CONFIG', {})
|
2020-03-01 03:42:05 -05:00
|
|
|
PLUGINS_ENABLED = getattr(configuration, 'PLUGINS_ENABLED', False)
|
2017-08-30 11:11:59 -04:00
|
|
|
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
2020-02-28 15:07:59 -05:00
|
|
|
REMOTE_AUTH_AUTO_CREATE_USER = getattr(configuration, 'REMOTE_AUTH_AUTO_CREATE_USER', False)
|
|
|
|
REMOTE_AUTH_BACKEND = getattr(configuration, 'REMOTE_AUTH_BACKEND', 'utilities.auth_backends.RemoteUserBackend')
|
|
|
|
REMOTE_AUTH_DEFAULT_GROUPS = getattr(configuration, 'REMOTE_AUTH_DEFAULT_GROUPS', [])
|
|
|
|
REMOTE_AUTH_DEFAULT_PERMISSIONS = getattr(configuration, 'REMOTE_AUTH_DEFAULT_PERMISSIONS', [])
|
|
|
|
REMOTE_AUTH_ENABLED = getattr(configuration, 'REMOTE_AUTH_ENABLED', False)
|
|
|
|
REMOTE_AUTH_HEADER = getattr(configuration, 'REMOTE_AUTH_HEADER', 'HTTP_REMOTE_USER')
|
2020-03-18 13:46:47 -04:00
|
|
|
RELEASE_CHECK_URL = getattr(configuration, 'RELEASE_CHECK_URL', None)
|
|
|
|
RELEASE_CHECK_TIMEOUT = getattr(configuration, 'RELEASE_CHECK_TIMEOUT', 24 * 3600)
|
2017-10-11 14:03:35 -04:00
|
|
|
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
|
2019-08-09 12:33:33 -04:00
|
|
|
SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/')
|
2018-11-13 10:31:44 -05:00
|
|
|
SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None)
|
2016-06-22 13:22:59 -04:00
|
|
|
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
|
|
|
|
SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
|
2017-06-09 15:03:10 -04:00
|
|
|
SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s')
|
|
|
|
TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a')
|
|
|
|
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
|
|
|
|
2020-03-13 10:20:09 -04:00
|
|
|
# Validate update repo URL and timeout
|
2020-03-18 13:46:47 -04:00
|
|
|
if RELEASE_CHECK_URL:
|
2020-03-13 10:20:09 -04:00
|
|
|
try:
|
2020-03-18 13:46:47 -04:00
|
|
|
URLValidator(RELEASE_CHECK_URL)
|
2020-03-13 10:20:09 -04:00
|
|
|
except ValidationError:
|
|
|
|
raise ImproperlyConfigured(
|
2020-03-18 13:46:47 -04:00
|
|
|
"RELEASE_CHECK_URL must be a valid API URL. Example: "
|
2020-03-13 10:20:09 -04:00
|
|
|
"https://api.github.com/repos/netbox-community/netbox"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Enforce a minimum cache timeout for update checks
|
2020-03-18 13:46:47 -04:00
|
|
|
if RELEASE_CHECK_TIMEOUT < 3600:
|
|
|
|
raise ImproperlyConfigured("RELEASE_CHECK_TIMEOUT has to be at least 3600 seconds (1 hour)")
|
2017-06-09 15:03:10 -04:00
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
# Database
|
|
|
|
#
|
2016-07-08 17:09:35 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
# Only PostgreSQL is supported
|
2019-04-25 01:09:19 -04:00
|
|
|
if METRICS_ENABLED:
|
|
|
|
DATABASE.update({
|
|
|
|
'ENGINE': 'django_prometheus.db.backends.postgresql'
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
DATABASE.update({
|
|
|
|
'ENGINE': 'django.db.backends.postgresql'
|
|
|
|
})
|
2016-07-08 17:09:35 -04:00
|
|
|
|
2016-05-24 11:46:55 -04:00
|
|
|
DATABASES = {
|
2019-04-22 16:33:28 -04:00
|
|
|
'default': DATABASE,
|
2016-05-24 11:46:55 -04:00
|
|
|
}
|
|
|
|
|
2019-12-11 10:51:32 -05:00
|
|
|
|
2019-11-03 14:16:12 +03:00
|
|
|
#
|
|
|
|
# Media storage
|
|
|
|
#
|
|
|
|
|
2019-12-11 16:09:32 +01:00
|
|
|
if STORAGE_BACKEND is not None:
|
|
|
|
DEFAULT_FILE_STORAGE = STORAGE_BACKEND
|
2019-11-03 14:16:12 +03:00
|
|
|
|
2019-12-11 10:51:32 -05:00
|
|
|
# django-storages
|
2019-12-11 16:09:32 +01:00
|
|
|
if STORAGE_BACKEND.startswith('storages.'):
|
|
|
|
|
2019-12-11 10:51:32 -05:00
|
|
|
try:
|
|
|
|
import storages.utils
|
|
|
|
except ImportError:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"STORAGE_BACKEND is set to {} but django-storages is not present. It can be installed by running 'pip "
|
|
|
|
"install django-storages'.".format(STORAGE_BACKEND)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Monkey-patch django-storages to fetch settings from STORAGE_CONFIG
|
2019-12-11 16:09:32 +01:00
|
|
|
def _setting(name, default=None):
|
|
|
|
if name in STORAGE_CONFIG:
|
|
|
|
return STORAGE_CONFIG[name]
|
|
|
|
return globals().get(name, default)
|
|
|
|
storages.utils.setting = _setting
|
2018-11-13 10:31:44 -05:00
|
|
|
|
2019-12-11 10:51:32 -05:00
|
|
|
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 "
|
|
|
|
"ignored."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
2018-05-30 11:19:10 -04:00
|
|
|
# Redis
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
|
2020-03-17 10:22:56 -04:00
|
|
|
# Background task queuing
|
|
|
|
if 'tasks' in REDIS:
|
|
|
|
TASKS_REDIS = REDIS['tasks']
|
|
|
|
elif 'webhooks' in REDIS:
|
|
|
|
# TODO: Remove support for 'webhooks' name in v2.9
|
|
|
|
warnings.warn(
|
|
|
|
"The 'webhooks' REDIS configuration section has been renamed to 'tasks'. Please update your configuration as "
|
|
|
|
"support for the old name will be removed in a future release."
|
2019-10-13 02:49:54 -04:00
|
|
|
)
|
2020-03-17 10:22:56 -04:00
|
|
|
TASKS_REDIS = REDIS['webhooks']
|
|
|
|
else:
|
2019-10-13 02:49:54 -04:00
|
|
|
raise ImproperlyConfigured(
|
2020-03-17 10:22:56 -04:00
|
|
|
"REDIS section in configuration.py is missing the 'tasks' subsection."
|
2019-10-13 02:49:54 -04:00
|
|
|
)
|
2020-03-17 10:22:56 -04:00
|
|
|
TASKS_REDIS_HOST = TASKS_REDIS.get('HOST', 'localhost')
|
|
|
|
TASKS_REDIS_PORT = TASKS_REDIS.get('PORT', 6379)
|
|
|
|
TASKS_REDIS_SENTINELS = TASKS_REDIS.get('SENTINELS', [])
|
|
|
|
TASKS_REDIS_USING_SENTINEL = all([
|
|
|
|
isinstance(TASKS_REDIS_SENTINELS, (list, tuple)),
|
|
|
|
len(TASKS_REDIS_SENTINELS) > 0
|
2020-02-13 08:53:46 -05:00
|
|
|
])
|
2020-03-17 10:22:56 -04:00
|
|
|
TASKS_REDIS_SENTINEL_SERVICE = TASKS_REDIS.get('SENTINEL_SERVICE', 'default')
|
|
|
|
TASKS_REDIS_PASSWORD = TASKS_REDIS.get('PASSWORD', '')
|
|
|
|
TASKS_REDIS_DATABASE = TASKS_REDIS.get('DATABASE', 0)
|
|
|
|
TASKS_REDIS_DEFAULT_TIMEOUT = TASKS_REDIS.get('DEFAULT_TIMEOUT', 300)
|
|
|
|
TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False)
|
2020-02-13 08:53:46 -05:00
|
|
|
|
2020-03-17 10:22:56 -04:00
|
|
|
# Caching
|
|
|
|
if 'caching' in REDIS:
|
|
|
|
CACHING_REDIS = REDIS['caching']
|
|
|
|
else:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"REDIS section in configuration.py is missing caching subsection."
|
|
|
|
)
|
2020-02-13 08:26:47 -06:00
|
|
|
CACHING_REDIS_HOST = CACHING_REDIS.get('HOST', 'localhost')
|
|
|
|
CACHING_REDIS_PORT = CACHING_REDIS.get('PORT', 6379)
|
2020-02-13 08:53:46 -05:00
|
|
|
CACHING_REDIS_SENTINELS = CACHING_REDIS.get('SENTINELS', [])
|
|
|
|
CACHING_REDIS_USING_SENTINEL = all([
|
|
|
|
isinstance(CACHING_REDIS_SENTINELS, (list, tuple)),
|
|
|
|
len(CACHING_REDIS_SENTINELS) > 0
|
|
|
|
])
|
|
|
|
CACHING_REDIS_SENTINEL_SERVICE = CACHING_REDIS.get('SENTINEL_SERVICE', 'default')
|
2020-02-13 08:26:47 -06:00
|
|
|
CACHING_REDIS_PASSWORD = CACHING_REDIS.get('PASSWORD', '')
|
|
|
|
CACHING_REDIS_DATABASE = CACHING_REDIS.get('DATABASE', 0)
|
|
|
|
CACHING_REDIS_DEFAULT_TIMEOUT = CACHING_REDIS.get('DEFAULT_TIMEOUT', 300)
|
|
|
|
CACHING_REDIS_SSL = CACHING_REDIS.get('SSL', False)
|
2018-05-30 14:51:59 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Sessions
|
|
|
|
#
|
|
|
|
|
|
|
|
if LOGIN_TIMEOUT is not None:
|
|
|
|
# Django default is 1209600 seconds (14 days)
|
|
|
|
SESSION_COOKIE_AGE = LOGIN_TIMEOUT
|
|
|
|
if SESSION_FILE_PATH is not None:
|
|
|
|
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
|
|
|
|
|
|
|
|
|
|
|
|
#
|
2016-05-24 14:24:35 -04:00
|
|
|
# Email
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
|
2016-05-24 14:24:35 -04:00
|
|
|
EMAIL_HOST = EMAIL.get('SERVER')
|
|
|
|
EMAIL_PORT = EMAIL.get('PORT', 25)
|
2016-05-24 14:37:50 -04:00
|
|
|
EMAIL_HOST_USER = EMAIL.get('USERNAME')
|
2016-05-24 14:24:35 -04:00
|
|
|
EMAIL_HOST_PASSWORD = EMAIL.get('PASSWORD')
|
|
|
|
EMAIL_TIMEOUT = EMAIL.get('TIMEOUT', 10)
|
|
|
|
SERVER_EMAIL = EMAIL.get('FROM_EMAIL')
|
|
|
|
EMAIL_SUBJECT_PREFIX = '[NetBox] '
|
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Django
|
|
|
|
#
|
|
|
|
|
2018-05-30 11:19:10 -04:00
|
|
|
INSTALLED_APPS = [
|
2016-03-01 11:23:03 -05:00
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2016-05-26 15:35:48 -04:00
|
|
|
'django.contrib.humanize',
|
2019-04-17 12:29:21 -04:00
|
|
|
'cacheops',
|
2017-03-21 13:53:07 -04:00
|
|
|
'corsheaders',
|
2016-03-01 11:23:03 -05:00
|
|
|
'debug_toolbar',
|
2017-05-24 09:40:24 -04:00
|
|
|
'django_filters',
|
2016-03-01 11:23:03 -05:00
|
|
|
'django_tables2',
|
2019-04-25 01:09:19 -04:00
|
|
|
'django_prometheus',
|
2017-02-28 16:10:53 -05:00
|
|
|
'mptt',
|
2016-03-01 11:23:03 -05:00
|
|
|
'rest_framework',
|
2018-05-08 16:28:26 -04:00
|
|
|
'taggit',
|
2018-08-03 09:43:03 -04:00
|
|
|
'taggit_serializer',
|
2017-12-19 17:24:14 -05:00
|
|
|
'timezone_field',
|
2016-03-01 11:23:03 -05:00
|
|
|
'circuits',
|
|
|
|
'dcim',
|
|
|
|
'ipam',
|
|
|
|
'extras',
|
|
|
|
'secrets',
|
2016-07-26 14:58:37 -04:00
|
|
|
'tenancy',
|
2016-03-01 11:23:03 -05:00
|
|
|
'users',
|
|
|
|
'utilities',
|
2017-08-04 17:02:52 -04:00
|
|
|
'virtualization',
|
2020-03-17 11:22:56 -04:00
|
|
|
'django_rq', # Must come after extras to allow overriding management commands
|
2018-02-22 17:46:50 -05:00
|
|
|
'drf_yasg',
|
2018-05-30 11:19:10 -04:00
|
|
|
]
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Middleware
|
2020-03-01 03:24:17 -05:00
|
|
|
MIDDLEWARE = [
|
2016-12-29 13:45:57 -05:00
|
|
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
2019-04-25 01:09:19 -04:00
|
|
|
'django_prometheus.middleware.PrometheusBeforeMiddleware',
|
2017-03-21 13:53:07 -04:00
|
|
|
'corsheaders.middleware.CorsMiddleware',
|
2016-03-01 11:23:03 -05:00
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
2017-11-03 13:24:31 -04:00
|
|
|
'utilities.middleware.ExceptionHandlingMiddleware',
|
2020-03-11 11:10:26 -04:00
|
|
|
'utilities.middleware.RemoteUserMiddleware',
|
2016-03-01 11:23:03 -05:00
|
|
|
'utilities.middleware.LoginRequiredMiddleware',
|
2017-03-21 13:23:56 -04:00
|
|
|
'utilities.middleware.APIVersionMiddleware',
|
2018-07-30 14:23:49 -04:00
|
|
|
'extras.middleware.ObjectChangeMiddleware',
|
2019-04-25 01:09:19 -04:00
|
|
|
'django_prometheus.middleware.PrometheusAfterMiddleware',
|
2020-03-01 03:24:17 -05:00
|
|
|
]
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
ROOT_URLCONF = 'netbox.urls'
|
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
TEMPLATES_DIR = BASE_DIR + '/templates'
|
2016-03-01 11:23:03 -05:00
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2019-04-22 16:33:28 -04:00
|
|
|
'DIRS': [TEMPLATES_DIR],
|
2016-03-01 11:23:03 -05:00
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
2017-03-30 21:55:57 -04:00
|
|
|
'django.template.context_processors.media',
|
2016-03-01 11:23:03 -05:00
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
'utilities.context_processors.settings',
|
2020-03-26 12:25:36 -04:00
|
|
|
'extras.plugins.context_processors.plugin_menu_items',
|
2016-03-01 11:23:03 -05:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-02-28 15:07:59 -05:00
|
|
|
# Set up authentication backends
|
2019-04-22 16:33:28 -04:00
|
|
|
AUTHENTICATION_BACKENDS = [
|
2020-03-11 11:10:26 -04:00
|
|
|
REMOTE_AUTH_BACKEND,
|
2019-04-22 16:33:28 -04:00
|
|
|
'utilities.auth_backends.ViewExemptModelBackend',
|
|
|
|
]
|
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
# WSGI
|
|
|
|
WSGI_APPLICATION = 'netbox.wsgi.application'
|
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
|
|
USE_X_FORWARDED_HOST = True
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
STATIC_ROOT = BASE_DIR + '/static'
|
|
|
|
STATIC_URL = '/{}static/'.format(BASE_PATH)
|
|
|
|
STATICFILES_DIRS = (
|
|
|
|
os.path.join(BASE_DIR, "project-static"),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Media
|
|
|
|
MEDIA_URL = '/{}media/'.format(BASE_PATH)
|
|
|
|
|
|
|
|
# Disable default limit of 1000 fields per request. Needed for bulk deletion of objects. (Added in Django 1.10.)
|
|
|
|
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
|
|
|
|
|
|
|
|
# Messages
|
|
|
|
MESSAGE_TAGS = {
|
|
|
|
messages.ERROR: 'danger',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Authentication URLs
|
|
|
|
LOGIN_URL = '/{}login/'.format(BASE_PATH)
|
|
|
|
|
|
|
|
CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# LDAP authentication (optional)
|
|
|
|
#
|
|
|
|
|
|
|
|
try:
|
|
|
|
from netbox import ldap_config as LDAP_CONFIG
|
|
|
|
except ImportError:
|
|
|
|
LDAP_CONFIG = None
|
|
|
|
|
|
|
|
if LDAP_CONFIG is not None:
|
|
|
|
|
|
|
|
# Check that django_auth_ldap is installed
|
|
|
|
try:
|
|
|
|
import ldap
|
|
|
|
import django_auth_ldap
|
|
|
|
except ImportError:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"LDAP authentication has been configured, but django-auth-ldap is not installed. Remove "
|
|
|
|
"netbox/ldap_config.py to disable LDAP."
|
|
|
|
)
|
|
|
|
|
|
|
|
# Required configuration parameters
|
|
|
|
try:
|
|
|
|
AUTH_LDAP_SERVER_URI = getattr(LDAP_CONFIG, 'AUTH_LDAP_SERVER_URI')
|
|
|
|
except AttributeError:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"Required parameter AUTH_LDAP_SERVER_URI is missing from ldap_config.py."
|
|
|
|
)
|
|
|
|
|
|
|
|
# Optional configuration parameters
|
|
|
|
AUTH_LDAP_ALWAYS_UPDATE_USER = getattr(LDAP_CONFIG, 'AUTH_LDAP_ALWAYS_UPDATE_USER', True)
|
|
|
|
AUTH_LDAP_AUTHORIZE_ALL_USERS = getattr(LDAP_CONFIG, 'AUTH_LDAP_AUTHORIZE_ALL_USERS', False)
|
|
|
|
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = getattr(LDAP_CONFIG, 'AUTH_LDAP_BIND_AS_AUTHENTICATING_USER', False)
|
|
|
|
AUTH_LDAP_BIND_DN = getattr(LDAP_CONFIG, 'AUTH_LDAP_BIND_DN', '')
|
|
|
|
AUTH_LDAP_BIND_PASSWORD = getattr(LDAP_CONFIG, 'AUTH_LDAP_BIND_PASSWORD', '')
|
|
|
|
AUTH_LDAP_CACHE_TIMEOUT = getattr(LDAP_CONFIG, 'AUTH_LDAP_CACHE_TIMEOUT', 0)
|
|
|
|
AUTH_LDAP_CONNECTION_OPTIONS = getattr(LDAP_CONFIG, 'AUTH_LDAP_CONNECTION_OPTIONS', {})
|
|
|
|
AUTH_LDAP_DENY_GROUP = getattr(LDAP_CONFIG, 'AUTH_LDAP_DENY_GROUP', None)
|
|
|
|
AUTH_LDAP_FIND_GROUP_PERMS = getattr(LDAP_CONFIG, 'AUTH_LDAP_FIND_GROUP_PERMS', False)
|
|
|
|
AUTH_LDAP_GLOBAL_OPTIONS = getattr(LDAP_CONFIG, 'AUTH_LDAP_GLOBAL_OPTIONS', {})
|
|
|
|
AUTH_LDAP_GROUP_SEARCH = getattr(LDAP_CONFIG, 'AUTH_LDAP_GROUP_SEARCH', None)
|
|
|
|
AUTH_LDAP_GROUP_TYPE = getattr(LDAP_CONFIG, 'AUTH_LDAP_GROUP_TYPE', None)
|
|
|
|
AUTH_LDAP_MIRROR_GROUPS = getattr(LDAP_CONFIG, 'AUTH_LDAP_MIRROR_GROUPS', None)
|
|
|
|
AUTH_LDAP_MIRROR_GROUPS_EXCEPT = getattr(LDAP_CONFIG, 'AUTH_LDAP_MIRROR_GROUPS_EXCEPT', None)
|
|
|
|
AUTH_LDAP_PERMIT_EMPTY_PASSWORD = getattr(LDAP_CONFIG, 'AUTH_LDAP_PERMIT_EMPTY_PASSWORD', False)
|
|
|
|
AUTH_LDAP_REQUIRE_GROUP = getattr(LDAP_CONFIG, 'AUTH_LDAP_REQUIRE_GROUP', None)
|
|
|
|
AUTH_LDAP_NO_NEW_USERS = getattr(LDAP_CONFIG, 'AUTH_LDAP_NO_NEW_USERS', False)
|
|
|
|
AUTH_LDAP_START_TLS = getattr(LDAP_CONFIG, 'AUTH_LDAP_START_TLS', False)
|
|
|
|
AUTH_LDAP_USER_QUERY_FIELD = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_QUERY_FIELD', None)
|
|
|
|
AUTH_LDAP_USER_ATTRLIST = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_ATTRLIST', None)
|
|
|
|
AUTH_LDAP_USER_ATTR_MAP = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_ATTR_MAP', {})
|
|
|
|
AUTH_LDAP_USER_DN_TEMPLATE = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_DN_TEMPLATE', None)
|
|
|
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_FLAGS_BY_GROUP', {})
|
|
|
|
AUTH_LDAP_USER_SEARCH = getattr(LDAP_CONFIG, 'AUTH_LDAP_USER_SEARCH', None)
|
|
|
|
|
|
|
|
# Optionally disable strict certificate checking
|
|
|
|
if getattr(LDAP_CONFIG, 'LDAP_IGNORE_CERT_ERRORS', False):
|
|
|
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
|
|
|
|
|
|
|
# Prepend LDAPBackend to the authentication backends list
|
|
|
|
AUTHENTICATION_BACKENDS.insert(0, 'django_auth_ldap.backend.LDAPBackend')
|
|
|
|
|
|
|
|
# Enable logging for django_auth_ldap
|
|
|
|
ldap_logger = logging.getLogger('django_auth_ldap')
|
|
|
|
ldap_logger.addHandler(logging.StreamHandler())
|
|
|
|
ldap_logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
2019-04-15 03:55:33 -04:00
|
|
|
# Caching
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
2020-02-13 08:53:46 -05:00
|
|
|
if CACHING_REDIS_USING_SENTINEL:
|
|
|
|
CACHEOPS_SENTINEL = {
|
2020-02-13 10:27:56 -05:00
|
|
|
'locations': CACHING_REDIS_SENTINELS,
|
2020-02-13 08:53:46 -05:00
|
|
|
'service_name': CACHING_REDIS_SENTINEL_SERVICE,
|
|
|
|
'db': CACHING_REDIS_DATABASE,
|
|
|
|
}
|
2019-04-15 03:55:33 -04:00
|
|
|
else:
|
2020-02-13 08:53:46 -05:00
|
|
|
if CACHING_REDIS_SSL:
|
|
|
|
REDIS_CACHE_CON_STRING = 'rediss://'
|
|
|
|
else:
|
|
|
|
REDIS_CACHE_CON_STRING = 'redis://'
|
|
|
|
|
|
|
|
if CACHING_REDIS_PASSWORD:
|
|
|
|
REDIS_CACHE_CON_STRING = '{}:{}@'.format(REDIS_CACHE_CON_STRING, CACHING_REDIS_PASSWORD)
|
|
|
|
|
|
|
|
REDIS_CACHE_CON_STRING = '{}{}:{}/{}'.format(
|
|
|
|
REDIS_CACHE_CON_STRING,
|
|
|
|
CACHING_REDIS_HOST,
|
|
|
|
CACHING_REDIS_PORT,
|
|
|
|
CACHING_REDIS_DATABASE
|
|
|
|
)
|
|
|
|
CACHEOPS_REDIS = REDIS_CACHE_CON_STRING
|
2019-04-17 12:29:21 -04:00
|
|
|
|
|
|
|
if not CACHE_TIMEOUT:
|
|
|
|
CACHEOPS_ENABLED = False
|
|
|
|
else:
|
|
|
|
CACHEOPS_ENABLED = True
|
|
|
|
|
2020-02-13 08:53:46 -05:00
|
|
|
|
2019-04-17 12:29:21 -04:00
|
|
|
CACHEOPS_DEFAULTS = {
|
|
|
|
'timeout': CACHE_TIMEOUT
|
|
|
|
}
|
|
|
|
CACHEOPS = {
|
2019-04-17 12:38:54 -04:00
|
|
|
'auth.user': {'ops': 'get', 'timeout': 60 * 15},
|
2019-04-17 12:29:21 -04:00
|
|
|
'auth.*': {'ops': ('fetch', 'get')},
|
|
|
|
'auth.permission': {'ops': 'all'},
|
2019-10-25 00:46:05 +02:00
|
|
|
'circuits.*': {'ops': 'all'},
|
2019-04-17 12:29:21 -04:00
|
|
|
'dcim.*': {'ops': 'all'},
|
|
|
|
'ipam.*': {'ops': 'all'},
|
|
|
|
'extras.*': {'ops': 'all'},
|
|
|
|
'secrets.*': {'ops': 'all'},
|
|
|
|
'users.*': {'ops': 'all'},
|
|
|
|
'tenancy.*': {'ops': 'all'},
|
|
|
|
'virtualization.*': {'ops': 'all'},
|
2019-04-15 03:55:33 -04:00
|
|
|
}
|
2019-04-17 12:29:21 -04:00
|
|
|
CACHEOPS_DEGRADE_ON_FAILURE = True
|
2019-04-15 03:55:33 -04:00
|
|
|
|
2019-01-04 11:07:55 -05:00
|
|
|
|
2019-04-25 01:09:19 -04:00
|
|
|
#
|
|
|
|
# Django Prometheus
|
|
|
|
#
|
2019-06-17 16:37:38 -04:00
|
|
|
|
2019-04-25 01:09:19 -04:00
|
|
|
PROMETHEUS_EXPORT_MIGRATIONS = False
|
|
|
|
|
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
2017-10-30 17:20:22 -04:00
|
|
|
# Django filters
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
|
2017-10-30 17:20:22 -04:00
|
|
|
FILTERS_NULL_CHOICE_LABEL = 'None'
|
2018-12-04 15:09:07 -05:00
|
|
|
FILTERS_NULL_CHOICE_VALUE = 'null'
|
2017-10-30 17:20:22 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
2017-01-27 14:54:12 -05:00
|
|
|
# Django REST framework (API)
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
|
2017-03-21 12:59:44 -04:00
|
|
|
REST_FRAMEWORK_VERSION = VERSION[0:3] # Use major.minor as API version
|
2016-03-01 11:23:03 -05:00
|
|
|
REST_FRAMEWORK = {
|
2017-08-15 15:30:45 -04:00
|
|
|
'ALLOWED_VERSIONS': [REST_FRAMEWORK_VERSION],
|
2017-03-07 17:17:39 -05:00
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
2017-10-10 14:21:20 -04:00
|
|
|
'netbox.api.TokenAuthentication',
|
2017-03-07 17:17:39 -05:00
|
|
|
),
|
|
|
|
'DEFAULT_FILTER_BACKENDS': (
|
2017-10-06 15:26:56 -04:00
|
|
|
'django_filters.rest_framework.DjangoFilterBackend',
|
2017-03-07 17:17:39 -05:00
|
|
|
),
|
2017-10-10 14:21:20 -04:00
|
|
|
'DEFAULT_PAGINATION_CLASS': 'netbox.api.OptionalLimitOffsetPagination',
|
2017-03-07 17:17:39 -05:00
|
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
2017-10-10 14:21:20 -04:00
|
|
|
'netbox.api.TokenPermissions',
|
2017-03-07 17:17:39 -05:00
|
|
|
),
|
2017-09-20 16:54:27 -04:00
|
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
|
|
'rest_framework.renderers.JSONRenderer',
|
2017-10-10 14:21:20 -04:00
|
|
|
'netbox.api.FormlessBrowsableAPIRenderer',
|
2017-09-20 16:54:27 -04:00
|
|
|
),
|
2017-03-20 12:33:42 -04:00
|
|
|
'DEFAULT_VERSION': REST_FRAMEWORK_VERSION,
|
2017-03-02 16:20:16 -05:00
|
|
|
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
2017-01-27 14:54:12 -05:00
|
|
|
'PAGE_SIZE': PAGINATE_COUNT,
|
2017-10-10 14:21:20 -04:00
|
|
|
'VIEW_NAME_FUNCTION': 'netbox.api.get_view_name',
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
|
2018-05-30 11:19:10 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
# drf_yasg (OpenAPI/Swagger)
|
|
|
|
#
|
|
|
|
|
2018-02-22 17:46:50 -05:00
|
|
|
SWAGGER_SETTINGS = {
|
Fix type mismatches in API view (#2429)
* Fix tags field to be shown as array in API view
`tags` field in serializers is defineded as `TagListSerializerField`.
It should be shown as an array value in API view but actually, it is a
simple string value.
This fixes it by introducing a new `FieldInspector` to handle
`TagListSerializerField` type field as an array. It doesn't affects any
other type fields.
* Fix SerializedPKRelatedField type API expression
A field definded as `SerializedPKRelatedField` should be shown as an
array of child serializer objects in a response value definition in API
view but it is shown as an array of primary key values (usually
`integer` type) of a child serializer.
This fixes it by introducing a new `FieldInspector` to handle the field.
It doesn't affect any other type fields.
* Fix request parameter representation in API view
In API view, representation of a parameter defined as a sub class of
`WritableNestedSerializer` should be vary between a request and a
response. For example, `tenant` field in `IPAddressSerializer` should be
shown like following as a request body:
```
tenant: integer ...
```
while it should be shown like following as a response body:
```
tenant: {
id: integer ...,
url: string ...,
name: string ...,
slug: string ...
}
```
But in both cases, it is shown as a response body type expression. This
causes an error at sending an API request with that type value.
It is only an API view issue, API can handle a request if a request
parameter is structured as an expected request body by ignoring the
wrong expression.
This fixes the issue by replacing an implicitly used default auto schema
generator class by its sub class and returning a pseudo serializer with
'Writable' prefix at generating a request body. The reason to introduce
a new generator class is that there is no other point which can
distinguish a request and a response. It is not enough to distinguish
POST, PUT, PATCH methods from GET because former cases may return a JSON
object as a response but it is also represented as same as a request
body, causes another mismatch.
This also fixes `SerializedPKRelatedField` type field representation. It
should be shown as an array of primary keys in a request body.
Fixed #2400
2018-11-28 06:14:45 +09:00
|
|
|
'DEFAULT_AUTO_SCHEMA_CLASS': 'utilities.custom_inspectors.NetBoxSwaggerAutoSchema',
|
2018-02-22 17:46:50 -05:00
|
|
|
'DEFAULT_FIELD_INSPECTORS': [
|
2020-03-03 12:04:46 -05:00
|
|
|
'utilities.custom_inspectors.JSONFieldInspector',
|
2018-02-22 17:46:50 -05:00
|
|
|
'utilities.custom_inspectors.NullableBooleanFieldInspector',
|
|
|
|
'utilities.custom_inspectors.CustomChoiceFieldInspector',
|
Fix type mismatches in API view (#2429)
* Fix tags field to be shown as array in API view
`tags` field in serializers is defineded as `TagListSerializerField`.
It should be shown as an array value in API view but actually, it is a
simple string value.
This fixes it by introducing a new `FieldInspector` to handle
`TagListSerializerField` type field as an array. It doesn't affects any
other type fields.
* Fix SerializedPKRelatedField type API expression
A field definded as `SerializedPKRelatedField` should be shown as an
array of child serializer objects in a response value definition in API
view but it is shown as an array of primary key values (usually
`integer` type) of a child serializer.
This fixes it by introducing a new `FieldInspector` to handle the field.
It doesn't affect any other type fields.
* Fix request parameter representation in API view
In API view, representation of a parameter defined as a sub class of
`WritableNestedSerializer` should be vary between a request and a
response. For example, `tenant` field in `IPAddressSerializer` should be
shown like following as a request body:
```
tenant: integer ...
```
while it should be shown like following as a response body:
```
tenant: {
id: integer ...,
url: string ...,
name: string ...,
slug: string ...
}
```
But in both cases, it is shown as a response body type expression. This
causes an error at sending an API request with that type value.
It is only an API view issue, API can handle a request if a request
parameter is structured as an expected request body by ignoring the
wrong expression.
This fixes the issue by replacing an implicitly used default auto schema
generator class by its sub class and returning a pseudo serializer with
'Writable' prefix at generating a request body. The reason to introduce
a new generator class is that there is no other point which can
distinguish a request and a response. It is not enough to distinguish
POST, PUT, PATCH methods from GET because former cases may return a JSON
object as a response but it is also represented as same as a request
body, causes another mismatch.
This also fixes `SerializedPKRelatedField` type field representation. It
should be shown as an array of primary keys in a request body.
Fixed #2400
2018-11-28 06:14:45 +09:00
|
|
|
'utilities.custom_inspectors.TagListFieldInspector',
|
|
|
|
'utilities.custom_inspectors.SerializedPKRelatedFieldInspector',
|
2018-02-22 17:46:50 -05:00
|
|
|
'drf_yasg.inspectors.CamelCaseJSONFilter',
|
|
|
|
'drf_yasg.inspectors.ReferencingSerializerInspector',
|
|
|
|
'drf_yasg.inspectors.RelatedFieldInspector',
|
|
|
|
'drf_yasg.inspectors.ChoiceFieldInspector',
|
|
|
|
'drf_yasg.inspectors.FileFieldInspector',
|
|
|
|
'drf_yasg.inspectors.DictFieldInspector',
|
2019-03-08 10:25:09 -05:00
|
|
|
'drf_yasg.inspectors.SerializerMethodFieldInspector',
|
2018-02-22 17:46:50 -05:00
|
|
|
'drf_yasg.inspectors.SimpleFieldInspector',
|
|
|
|
'drf_yasg.inspectors.StringDefaultFieldInspector',
|
|
|
|
],
|
2018-03-15 16:51:57 -04:00
|
|
|
'DEFAULT_FILTER_INSPECTORS': [
|
|
|
|
'drf_yasg.inspectors.CoreAPICompatInspector',
|
|
|
|
],
|
2020-01-23 14:26:04 +00:00
|
|
|
'DEFAULT_INFO': 'netbox.urls.openapi_info',
|
2019-03-08 10:28:11 -05:00
|
|
|
'DEFAULT_MODEL_DEPTH': 1,
|
2018-02-22 17:46:50 -05:00
|
|
|
'DEFAULT_PAGINATOR_INSPECTORS': [
|
|
|
|
'utilities.custom_inspectors.NullablePaginatorInspector',
|
|
|
|
'drf_yasg.inspectors.DjangoRestResponsePagination',
|
|
|
|
'drf_yasg.inspectors.CoreAPICompatInspector',
|
2018-06-29 22:01:01 +02:00
|
|
|
],
|
|
|
|
'SECURITY_DEFINITIONS': {
|
|
|
|
'Bearer': {
|
|
|
|
'type': 'apiKey',
|
|
|
|
'name': 'Authorization',
|
|
|
|
'in': 'header',
|
|
|
|
}
|
2018-07-02 15:45:36 -04:00
|
|
|
},
|
2018-07-02 14:39:32 -04:00
|
|
|
'VALIDATOR_URL': None,
|
2018-02-22 17:46:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
# Django RQ (Webhooks backend)
|
|
|
|
#
|
|
|
|
|
2020-03-18 13:46:47 -04:00
|
|
|
if TASKS_REDIS_USING_SENTINEL:
|
2020-03-17 11:22:56 -04:00
|
|
|
RQ_PARAMS = {
|
2020-03-17 10:22:56 -04:00
|
|
|
'SENTINELS': TASKS_REDIS_SENTINELS,
|
|
|
|
'MASTER_NAME': TASKS_REDIS_SENTINEL_SERVICE,
|
|
|
|
'DB': TASKS_REDIS_DATABASE,
|
|
|
|
'PASSWORD': TASKS_REDIS_PASSWORD,
|
2020-02-13 08:53:46 -05:00
|
|
|
'SOCKET_TIMEOUT': None,
|
|
|
|
'CONNECTION_KWARGS': {
|
2020-03-17 10:22:56 -04:00
|
|
|
'socket_connect_timeout': TASKS_REDIS_DEFAULT_TIMEOUT
|
2020-02-13 08:53:46 -05:00
|
|
|
},
|
2019-04-22 16:33:28 -04:00
|
|
|
}
|
2020-03-18 13:46:47 -04:00
|
|
|
else:
|
|
|
|
RQ_PARAMS = {
|
|
|
|
'HOST': TASKS_REDIS_HOST,
|
|
|
|
'PORT': TASKS_REDIS_PORT,
|
|
|
|
'DB': TASKS_REDIS_DATABASE,
|
|
|
|
'PASSWORD': TASKS_REDIS_PASSWORD,
|
|
|
|
'DEFAULT_TIMEOUT': TASKS_REDIS_DEFAULT_TIMEOUT,
|
|
|
|
'SSL': TASKS_REDIS_SSL,
|
|
|
|
}
|
2019-04-22 16:33:28 -04:00
|
|
|
|
2020-03-17 11:22:56 -04:00
|
|
|
RQ_QUEUES = {
|
|
|
|
'default': RQ_PARAMS, # Webhooks
|
|
|
|
'check_releases': RQ_PARAMS,
|
|
|
|
}
|
2019-04-22 16:33:28 -04:00
|
|
|
|
|
|
|
#
|
2016-12-26 12:15:14 -05:00
|
|
|
# Django debug toolbar
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
|
2016-12-26 12:15:14 -05:00
|
|
|
INTERNAL_IPS = (
|
|
|
|
'127.0.0.1',
|
|
|
|
'::1',
|
|
|
|
)
|
|
|
|
|
2016-05-24 15:09:17 -04:00
|
|
|
|
2019-04-22 16:33:28 -04:00
|
|
|
#
|
|
|
|
# NetBox internal settings
|
|
|
|
#
|
|
|
|
|
|
|
|
# Secrets
|
|
|
|
SECRETS_MIN_PUBKEY_SIZE = 2048
|
|
|
|
|
|
|
|
# Pagination
|
|
|
|
PER_PAGE_DEFAULTS = [
|
|
|
|
25, 50, 100, 250, 500, 1000
|
|
|
|
]
|
|
|
|
if PAGINATE_COUNT not in PER_PAGE_DEFAULTS:
|
|
|
|
PER_PAGE_DEFAULTS.append(PAGINATE_COUNT)
|
|
|
|
PER_PAGE_DEFAULTS = sorted(PER_PAGE_DEFAULTS)
|
2020-02-29 02:23:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Plugins
|
|
|
|
#
|
|
|
|
|
2020-03-20 20:10:02 -04:00
|
|
|
PLUGINS = set()
|
2020-03-01 03:42:05 -05:00
|
|
|
if PLUGINS_ENABLED:
|
2020-03-20 14:35:54 -04:00
|
|
|
for entry_point in iter_entry_points(group='netbox_plugins', name=None):
|
2020-03-23 12:01:24 -04:00
|
|
|
# Append plugin name to PLUGINS
|
2020-03-01 03:42:05 -05:00
|
|
|
plugin = entry_point.module_name
|
2020-03-20 20:10:02 -04:00
|
|
|
PLUGINS.add(plugin)
|
2020-03-23 12:01:24 -04:00
|
|
|
|
|
|
|
# Append plugin to INSTALLED_APPS. Specify the path to the PluginConfig so that we don't
|
|
|
|
# have to define default_app_config.
|
|
|
|
app_config = entry_point.load()
|
|
|
|
INSTALLED_APPS.append('{}.{}'.format(app_config.__module__, app_config.__name__))
|
2020-02-29 02:23:01 -05:00
|
|
|
|
2020-03-20 15:13:25 -04:00
|
|
|
# Check version constraints
|
|
|
|
parsed_min_version = parse_version(app_config.min_version or VERSION)
|
|
|
|
parsed_max_version = parse_version(app_config.max_version or VERSION)
|
|
|
|
if app_config.min_version and app_config.max_version and parsed_min_version > parsed_max_version:
|
|
|
|
raise ImproperlyConfigured(f"Plugin {plugin} specifies invalid version constraints!")
|
|
|
|
if app_config.min_version and parsed_min_version > parse_version(VERSION):
|
|
|
|
raise ImproperlyConfigured(f"Plugin {plugin} requires NetBox minimum version {app_config.min_version}!")
|
|
|
|
if app_config.max_version and parsed_max_version < parse_version(VERSION):
|
|
|
|
raise ImproperlyConfigured(f"Plugin {plugin} requires NetBox maximum version {app_config.max_version}!")
|
2020-03-18 18:28:27 -04:00
|
|
|
|
2020-03-01 03:42:05 -05:00
|
|
|
# Add middleware
|
2020-03-20 15:13:25 -04:00
|
|
|
plugin_middleware = app_config.middleware
|
2020-03-01 03:42:05 -05:00
|
|
|
if plugin_middleware and isinstance(plugin_middleware, list):
|
|
|
|
MIDDLEWARE.extend(plugin_middleware)
|
|
|
|
|
|
|
|
# Verify required configuration settings
|
|
|
|
if plugin not in PLUGINS_CONFIG:
|
|
|
|
PLUGINS_CONFIG[plugin] = {}
|
2020-03-20 15:13:25 -04:00
|
|
|
for setting in app_config.required_settings:
|
2020-03-01 03:42:05 -05:00
|
|
|
if setting not in PLUGINS_CONFIG[plugin]:
|
|
|
|
raise ImproperlyConfigured(
|
2020-03-20 15:13:25 -04:00
|
|
|
f"Plugin {plugin} requires '{setting}' to be present in the PLUGINS_CONFIG section of "
|
|
|
|
f"configuration.py."
|
2020-03-01 03:42:05 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# Set defined default setting values
|
2020-03-20 15:13:25 -04:00
|
|
|
for setting, value in app_config.default_settings.items():
|
2020-03-01 03:42:05 -05:00
|
|
|
if setting not in PLUGINS_CONFIG[plugin]:
|
|
|
|
PLUGINS_CONFIG[plugin][setting] = value
|
2020-03-18 18:28:27 -04:00
|
|
|
|
|
|
|
# Apply cacheops config
|
2020-03-20 15:13:25 -04:00
|
|
|
plugin_cacheops = app_config.caching_config
|
2020-03-18 18:28:27 -04:00
|
|
|
if plugin_cacheops and isinstance(plugin_cacheops, dict):
|
|
|
|
for key in plugin_cacheops.keys():
|
|
|
|
# Validate config is only being set for the given plugin
|
|
|
|
try:
|
|
|
|
app = key.split('.')[0]
|
|
|
|
except IndexError:
|
2020-03-20 15:13:25 -04:00
|
|
|
raise ImproperlyConfigured(f"Plugin {plugin} caching_config is invalid!")
|
2020-03-18 18:28:27 -04:00
|
|
|
if app != plugin:
|
2020-03-20 15:13:25 -04:00
|
|
|
raise ImproperlyConfigured(f"Plugin {plugin} may not modify caching config for another app!")
|
2020-03-20 20:10:02 -04:00
|
|
|
else:
|
|
|
|
# Apply the default config like all other core apps
|
|
|
|
plugin_cacheops = {f"{plugin}.*": {'ops': 'all'}}
|
2020-03-18 18:28:27 -04:00
|
|
|
CACHEOPS.update(plugin_cacheops)
|