2016-07-08 17:09:35 -04:00
|
|
|
import logging
|
2016-03-01 11:23:03 -05:00
|
|
|
import os
|
|
|
|
|
import socket
|
2017-11-14 15:07:13 -05:00
|
|
|
import sys
|
|
|
|
|
import warnings
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
from django.contrib.messages import constants as messages
|
2016-05-24 11:46:55 -04:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
|
|
2018-12-07 14:44:36 -05:00
|
|
|
# Django 2.1 requires Python 3.5+
|
|
|
|
|
if sys.version_info < (3, 5):
|
2018-08-14 11:47:54 -04:00
|
|
|
raise RuntimeError(
|
2018-12-07 14:44:36 -05:00
|
|
|
"NetBox requires Python 3.5 or higher (current: Python {})".format(sys.version.split()[0])
|
2018-08-14 11:47:54 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check for configuration file
|
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-02-21 14:45:23 -05:00
|
|
|
VERSION = '2.5.8-dev'
|
2016-06-29 14:05:01 -04:00
|
|
|
|
2017-08-30 11:11:59 -04:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
2016-06-29 14:05:01 -04:00
|
|
|
|
2017-06-09 15:03:10 -04:00
|
|
|
# Import required configuration parameters
|
2017-03-21 13:53:07 -04:00
|
|
|
ALLOWED_HOSTS = DATABASE = SECRET_KEY = None
|
2016-05-24 14:24:35 -04:00
|
|
|
for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:
|
2016-05-24 11:46:55 -04:00
|
|
|
try:
|
|
|
|
|
globals()[setting] = getattr(configuration, setting)
|
|
|
|
|
except AttributeError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
|
"Mandatory setting {} is missing from configuration.py.".format(setting)
|
|
|
|
|
)
|
2016-05-24 11:46:55 -04:00
|
|
|
|
2017-06-09 15:03:10 -04:00
|
|
|
# Import optional configuration 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
|
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)
|
|
|
|
|
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
|
|
|
|
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
|
|
|
|
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('/')
|
2017-07-26 11:24:19 -04:00
|
|
|
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
|
|
|
|
NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '')
|
2017-07-26 11:47:59 -04:00
|
|
|
NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30)
|
|
|
|
|
NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {})
|
2017-08-30 11:11:59 -04:00
|
|
|
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
|
|
|
|
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
2017-10-11 14:03:35 -04:00
|
|
|
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
|
2018-05-30 11:19:10 -04:00
|
|
|
REDIS = getattr(configuration, 'REDIS', {})
|
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')
|
2018-05-30 14:51:59 -04:00
|
|
|
WEBHOOKS_ENABLED = getattr(configuration, 'WEBHOOKS_ENABLED', False)
|
2017-06-09 15:03:10 -04:00
|
|
|
|
2016-07-11 13:29:58 -04:00
|
|
|
CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
|
2016-05-23 12:55:03 -04:00
|
|
|
|
2016-07-08 17:09:35 -04:00
|
|
|
# Attempt to import LDAP configuration if it has been defined
|
|
|
|
|
LDAP_IGNORE_CERT_ERRORS = False
|
|
|
|
|
try:
|
2017-01-23 22:44:29 +01:00
|
|
|
from netbox.ldap_config import *
|
2016-07-08 17:09:35 -04:00
|
|
|
LDAP_CONFIGURED = True
|
|
|
|
|
except ImportError:
|
|
|
|
|
LDAP_CONFIGURED = False
|
|
|
|
|
|
|
|
|
|
# LDAP configuration (optional)
|
|
|
|
|
if LDAP_CONFIGURED:
|
|
|
|
|
try:
|
2016-07-08 22:56:54 -04:00
|
|
|
import ldap
|
|
|
|
|
import django_auth_ldap
|
2016-07-08 17:09:35 -04:00
|
|
|
# Prepend LDAPBackend to the default ModelBackend
|
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
|
|
|
'django_auth_ldap.backend.LDAPBackend',
|
|
|
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
|
|
|
]
|
|
|
|
|
# Optionally disable strict certificate checking
|
|
|
|
|
if LDAP_IGNORE_CERT_ERRORS:
|
|
|
|
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
|
|
|
|
# Enable logging for django_auth_ldap
|
2017-07-26 11:24:19 -04:00
|
|
|
ldap_logger = logging.getLogger('django_auth_ldap')
|
|
|
|
|
ldap_logger.addHandler(logging.StreamHandler())
|
|
|
|
|
ldap_logger.setLevel(logging.DEBUG)
|
2016-07-08 17:09:35 -04:00
|
|
|
except ImportError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
|
"LDAP authentication has been configured, but django-auth-ldap is not installed. You can remove "
|
|
|
|
|
"netbox/ldap_config.py to disable LDAP."
|
|
|
|
|
)
|
2016-07-08 17:09:35 -04:00
|
|
|
|
2016-05-24 11:46:55 -04:00
|
|
|
# Database
|
|
|
|
|
configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'})
|
|
|
|
|
DATABASES = {
|
|
|
|
|
'default': configuration.DATABASE,
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 10:31:44 -05:00
|
|
|
# Sessions
|
2018-11-14 14:18:32 -05:00
|
|
|
if LOGIN_TIMEOUT is not None:
|
|
|
|
|
if type(LOGIN_TIMEOUT) is not int or LOGIN_TIMEOUT < 0:
|
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
|
"LOGIN_TIMEOUT must be a positive integer (value: {})".format(LOGIN_TIMEOUT)
|
|
|
|
|
)
|
|
|
|
|
# Django default is 1209600 seconds (14 days)
|
|
|
|
|
SESSION_COOKIE_AGE = LOGIN_TIMEOUT
|
2018-11-13 10:31:44 -05:00
|
|
|
if SESSION_FILE_PATH is not None:
|
|
|
|
|
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
|
|
|
|
|
|
2018-05-30 11:19:10 -04:00
|
|
|
# Redis
|
2018-05-30 14:51:59 -04:00
|
|
|
REDIS_HOST = REDIS.get('HOST', 'localhost')
|
|
|
|
|
REDIS_PORT = REDIS.get('PORT', 6379)
|
|
|
|
|
REDIS_PASSWORD = REDIS.get('PASSWORD', '')
|
|
|
|
|
REDIS_DATABASE = REDIS.get('DATABASE', 0)
|
|
|
|
|
REDIS_DEFAULT_TIMEOUT = REDIS.get('DEFAULT_TIMEOUT', 300)
|
|
|
|
|
|
2016-05-24 14:24:35 -04:00
|
|
|
# Email
|
|
|
|
|
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] '
|
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Installed applications
|
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',
|
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',
|
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',
|
2018-02-22 17:46:50 -05:00
|
|
|
'drf_yasg',
|
2018-05-30 11:19:10 -04:00
|
|
|
]
|
|
|
|
|
|
2018-05-30 14:51:59 -04:00
|
|
|
# Only load django-rq if the webhook backend is enabled
|
|
|
|
|
if WEBHOOKS_ENABLED:
|
2018-05-30 11:19:10 -04:00
|
|
|
INSTALLED_APPS.append('django_rq')
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Middleware
|
2016-12-26 10:48:15 -05:00
|
|
|
MIDDLEWARE = (
|
2016-12-29 13:45:57 -05:00
|
|
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
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',
|
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',
|
2016-03-01 11:23:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'netbox.urls'
|
|
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
|
{
|
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2019-03-04 03:20:47 +02:00
|
|
|
'DIRS': [BASE_DIR + '/templates'],
|
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',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# WSGI
|
2016-03-01 11:23:03 -05:00
|
|
|
WSGI_APPLICATION = 'netbox.wsgi.application'
|
|
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
2016-05-24 14:24:35 -04:00
|
|
|
USE_X_FORWARDED_HOST = True
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
2019-03-04 03:20:47 +02:00
|
|
|
STATIC_ROOT = BASE_DIR + '/static'
|
2016-10-13 16:27:09 -04:00
|
|
|
STATIC_URL = '/{}static/'.format(BASE_PATH)
|
2016-03-01 11:23:03 -05:00
|
|
|
STATICFILES_DIRS = (
|
|
|
|
|
os.path.join(BASE_DIR, "project-static"),
|
|
|
|
|
)
|
|
|
|
|
|
2017-03-30 21:55:57 -04:00
|
|
|
# Media
|
2017-05-24 10:34:01 -04:00
|
|
|
MEDIA_URL = '/{}media/'.format(BASE_PATH)
|
2017-03-30 21:55:57 -04:00
|
|
|
|
2016-08-18 10:12:43 -04:00
|
|
|
# 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
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
# Messages
|
|
|
|
|
MESSAGE_TAGS = {
|
|
|
|
|
messages.ERROR: 'danger',
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Authentication URLs
|
2016-10-13 16:27:09 -04:00
|
|
|
LOGIN_URL = '/{}login/'.format(BASE_PATH)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
# Secrets
|
|
|
|
|
SECRETS_MIN_PUBKEY_SIZE = 2048
|
|
|
|
|
|
2019-01-04 11:07:55 -05:00
|
|
|
# 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)
|
|
|
|
|
|
2017-10-30 17:20:22 -04:00
|
|
|
# Django filters
|
|
|
|
|
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
|
|
|
|
2017-01-27 14:54:12 -05:00
|
|
|
# Django REST framework (API)
|
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 14:51:59 -04:00
|
|
|
# Django RQ (Webhooks backend)
|
2018-05-30 11:19:10 -04:00
|
|
|
RQ_QUEUES = {
|
|
|
|
|
'default': {
|
|
|
|
|
'HOST': REDIS_HOST,
|
|
|
|
|
'PORT': REDIS_PORT,
|
2018-05-30 14:51:59 -04:00
|
|
|
'DB': REDIS_DATABASE,
|
2018-05-30 11:19:10 -04:00
|
|
|
'PASSWORD': REDIS_PASSWORD,
|
|
|
|
|
'DEFAULT_TIMEOUT': REDIS_DEFAULT_TIMEOUT,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 17:46:50 -05:00
|
|
|
# drf_yasg settings for Swagger
|
|
|
|
|
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': [
|
|
|
|
|
'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',
|
|
|
|
|
'drf_yasg.inspectors.SimpleFieldInspector',
|
|
|
|
|
'drf_yasg.inspectors.StringDefaultFieldInspector',
|
|
|
|
|
],
|
2018-03-15 16:51:57 -04:00
|
|
|
'DEFAULT_FILTER_INSPECTORS': [
|
|
|
|
|
'utilities.custom_inspectors.IdInFilterInspector',
|
|
|
|
|
'drf_yasg.inspectors.CoreAPICompatInspector',
|
|
|
|
|
],
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-26 12:15:14 -05:00
|
|
|
# Django debug toolbar
|
|
|
|
|
INTERNAL_IPS = (
|
|
|
|
|
'127.0.0.1',
|
|
|
|
|
'::1',
|
|
|
|
|
)
|
|
|
|
|
|
2016-05-24 15:09:17 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
try:
|
|
|
|
|
HOSTNAME = socket.gethostname()
|
2018-06-27 17:23:32 +02:00
|
|
|
except Exception:
|
2016-03-01 11:23:03 -05:00
|
|
|
HOSTNAME = 'localhost'
|