2020-01-06 21:58:38 +00:00
|
|
|
"""
|
|
|
|
Django settings for apiserver project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 3.0.2.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/ref/settings/
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2020-03-08 00:36:16 +00:00
|
|
|
import logging.config
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-01-06 21:58:38 +00:00
|
|
|
|
2020-02-02 04:42:46 +00:00
|
|
|
from . import secrets
|
|
|
|
|
2020-01-06 21:58:38 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
2021-11-26 03:29:30 +00:00
|
|
|
SECRET_KEY = secrets.DJANGO_SECRET_KEY or 'OaOBN2E+brpoRyDMlTD9eTE5PgBtkkl+L7Bzt6pQ5Qr3GS82SH'
|
2020-01-06 21:58:38 +00:00
|
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
2020-01-06 22:10:39 +00:00
|
|
|
DEBUG_ENV = os.environ.get('DEBUG', False)
|
2022-04-06 22:04:56 +00:00
|
|
|
BINDALL_ENV = os.environ.get('BINDALL', False)
|
2020-01-06 22:10:39 +00:00
|
|
|
DEBUG = DEBUG_ENV or False
|
2020-01-06 21:58:38 +00:00
|
|
|
|
2020-02-06 09:14:50 +00:00
|
|
|
|
2020-02-14 22:39:44 +00:00
|
|
|
PRODUCTION_HOST = 'my.protospace.ca'
|
2020-02-06 09:14:50 +00:00
|
|
|
|
|
|
|
|
2020-01-06 22:10:39 +00:00
|
|
|
# production hosts
|
2020-02-02 03:56:56 +00:00
|
|
|
ALLOWED_HOSTS = [
|
2020-02-06 09:14:50 +00:00
|
|
|
'api.' + PRODUCTION_HOST,
|
2020-02-02 03:56:56 +00:00
|
|
|
]
|
2020-01-06 21:58:38 +00:00
|
|
|
|
2020-01-06 22:10:39 +00:00
|
|
|
if DEBUG:
|
|
|
|
ALLOWED_HOSTS += [
|
2020-01-16 23:15:37 +00:00
|
|
|
'localhost',
|
|
|
|
'127.0.0.1',
|
2020-01-11 07:09:24 +00:00
|
|
|
'api.spaceport.dns.t0.vc',
|
2020-01-06 22:10:39 +00:00
|
|
|
]
|
|
|
|
|
2022-04-06 22:04:56 +00:00
|
|
|
if BINDALL_ENV:
|
|
|
|
ALLOWED_HOSTS = ['*']
|
|
|
|
|
|
|
|
|
2020-01-21 05:00:45 +00:00
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
2020-02-21 22:46:26 +00:00
|
|
|
SESSION_COOKIE_SECURE = True
|
|
|
|
CSRF_COOKIE_SECURE = True
|
2020-05-07 04:12:48 +00:00
|
|
|
SECURE_REFERRER_POLICY = 'same-origin'
|
2020-01-21 05:00:45 +00:00
|
|
|
|
2020-01-06 21:58:38 +00:00
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2020-01-07 08:23:06 +00:00
|
|
|
'django.contrib.sites',
|
2020-01-06 22:10:39 +00:00
|
|
|
'rest_framework',
|
2020-01-06 23:05:19 +00:00
|
|
|
'rest_framework.authtoken',
|
2020-01-06 22:10:39 +00:00
|
|
|
'apiserver.api',
|
2020-01-06 23:14:41 +00:00
|
|
|
'rest_auth',
|
2020-01-07 08:23:06 +00:00
|
|
|
'allauth',
|
|
|
|
'allauth.account',
|
2020-01-08 23:43:59 +00:00
|
|
|
'allauth.socialaccount', # to support user deletion
|
2020-01-07 08:23:06 +00:00
|
|
|
'rest_auth.registration',
|
2020-02-05 00:00:33 +00:00
|
|
|
'simple_history',
|
2020-01-06 21:58:38 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
MIDDLEWARE = [
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'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',
|
2020-02-05 00:00:33 +00:00
|
|
|
'simple_history.middleware.HistoryRequestMiddleware',
|
2020-01-06 21:58:38 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'apiserver.urls'
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'apiserver.wsgi.application'
|
|
|
|
|
|
|
|
|
|
|
|
# Database
|
|
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
|
|
|
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
2020-01-16 23:15:37 +00:00
|
|
|
'NAME': os.path.join(BASE_DIR, 'data/db.sqlite3'),
|
2020-11-24 23:00:45 +00:00
|
|
|
'OPTIONS': {
|
|
|
|
'timeout': 20, # increased because generate_backups.py blocks
|
|
|
|
},
|
2020-01-08 23:43:59 +00:00
|
|
|
},
|
2020-01-06 21:58:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 09:06:02 +00:00
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
|
|
|
'LOCATION': '127.0.0.1:11211',
|
|
|
|
'TIMEOUT': None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:58:38 +00:00
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-01-07 08:04:18 +00:00
|
|
|
PASSWORD_HASHERS = [
|
|
|
|
'django.contrib.auth.hashers.Argon2PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-01-06 21:58:38 +00:00
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
|
|
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
|
|
|
|
2020-02-06 09:14:50 +00:00
|
|
|
if DEBUG:
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
else:
|
|
|
|
STATIC_URL = 'https://static.{}/'.format(PRODUCTION_HOST)
|
|
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'data/static')
|
|
|
|
|
2020-01-06 22:10:39 +00:00
|
|
|
|
|
|
|
DEFAULT_RENDERER_CLASSES = (
|
|
|
|
'rest_framework.renderers.JSONRenderer',
|
|
|
|
)
|
|
|
|
|
|
|
|
if DEBUG:
|
|
|
|
DEFAULT_RENDERER_CLASSES += (
|
|
|
|
'rest_framework.renderers.BrowsableAPIRenderer',
|
|
|
|
)
|
|
|
|
|
2020-01-06 23:05:19 +00:00
|
|
|
DEFAULT_AUTHENTICATION_CLASSES = (
|
|
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
|
|
)
|
|
|
|
|
|
|
|
if DEBUG:
|
|
|
|
DEFAULT_AUTHENTICATION_CLASSES += (
|
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
|
|
)
|
|
|
|
|
2020-01-06 22:10:39 +00:00
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
2020-02-22 05:21:33 +00:00
|
|
|
'PAGE_SIZE': 300,
|
2020-01-06 22:10:39 +00:00
|
|
|
'DEFAULT_RENDERER_CLASSES': DEFAULT_RENDERER_CLASSES,
|
2020-01-06 23:05:19 +00:00
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': DEFAULT_AUTHENTICATION_CLASSES,
|
2021-11-29 01:19:01 +00:00
|
|
|
'DEFAULT_THROTTLE_CLASSES': ['apiserver.api.throttles.LoggingThrottle'],
|
2022-01-19 23:58:34 +00:00
|
|
|
'EXCEPTION_HANDLER': 'apiserver.api.utils.custom_exception_handler'
|
2020-01-06 22:10:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 00:36:16 +00:00
|
|
|
#DEFAULT_LOGGING = None
|
2020-01-06 22:10:39 +00:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
2020-03-08 00:36:16 +00:00
|
|
|
'disable_existing_loggers': False,
|
2020-01-06 22:10:39 +00:00
|
|
|
'formatters': {
|
|
|
|
'medium': {
|
2020-03-08 00:36:16 +00:00
|
|
|
'format': '[%(asctime)s] [%(process)d] [%(levelname)7s] %(message)s'
|
2020-01-06 22:10:39 +00:00
|
|
|
},
|
2020-03-08 00:36:16 +00:00
|
|
|
},
|
|
|
|
'filters': {
|
|
|
|
'ignore_stats': {
|
|
|
|
'()': 'apiserver.filters.IgnoreStats',
|
2020-01-06 22:10:39 +00:00
|
|
|
},
|
2020-11-07 21:27:10 +00:00
|
|
|
'ignore_lockout': {
|
|
|
|
'()': 'apiserver.filters.IgnoreLockout',
|
|
|
|
},
|
2020-01-06 22:10:39 +00:00
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
2020-03-08 00:36:16 +00:00
|
|
|
'level': 'DEBUG',
|
2020-11-07 21:27:10 +00:00
|
|
|
'filters': ['ignore_stats', 'ignore_lockout'],
|
2020-01-06 22:10:39 +00:00
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'medium'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'gunicorn': {
|
|
|
|
'handlers': ['console'],
|
2021-11-29 02:42:17 +00:00
|
|
|
'level': 'DEBUG' if DEBUG else 'INFO',
|
2020-03-08 00:36:16 +00:00
|
|
|
'propagate': False,
|
2020-01-06 22:10:39 +00:00
|
|
|
},
|
|
|
|
'': {
|
|
|
|
'handlers': ['console'],
|
2020-03-08 00:36:16 +00:00
|
|
|
'level': 'DEBUG',
|
2020-01-06 22:10:39 +00:00
|
|
|
'propagate': True,
|
|
|
|
},
|
2020-03-08 00:36:16 +00:00
|
|
|
},
|
|
|
|
'root': {
|
2022-01-23 02:33:20 +00:00
|
|
|
'level': 'DEBUG' if DEBUG else 'INFO',
|
2020-03-08 00:36:16 +00:00
|
|
|
'handlers': ['console'],
|
|
|
|
},
|
2020-01-06 22:10:39 +00:00
|
|
|
}
|
2020-03-08 00:36:16 +00:00
|
|
|
logging.config.dictConfig(LOGGING)
|
2020-01-07 08:23:06 +00:00
|
|
|
|
|
|
|
SITE_ID = 1
|
2020-01-08 23:43:59 +00:00
|
|
|
ACCOUNT_EMAIL_REQUIRED = True
|
|
|
|
ACCOUNT_EMAIL_VERIFICATION = 'none'
|
|
|
|
ACCOUNT_USERNAME_MIN_LENGTH = 3
|
2020-01-09 05:21:18 +00:00
|
|
|
ACCOUNT_AUTHENTICATION_METHOD = 'username'
|
2020-01-12 08:54:32 +00:00
|
|
|
OLD_PASSWORD_FIELD_ENABLED = True
|
|
|
|
LOGOUT_ON_PASSWORD_CHANGE = False
|
2020-01-21 23:46:44 +00:00
|
|
|
ACCOUNT_PRESERVE_USERNAME_CASING = False
|
2020-03-08 00:36:16 +00:00
|
|
|
|
2020-06-20 03:48:31 +00:00
|
|
|
if not secrets.EMAIL_USER or not secrets.EMAIL_PASS:
|
|
|
|
logger.info('Logging outgoing emails to console')
|
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
|
|
|
else:
|
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
|
|
|
|
2021-09-26 00:54:25 +00:00
|
|
|
EMAIL_HOST = secrets.EMAIL_HOST
|
2020-06-19 23:49:05 +00:00
|
|
|
EMAIL_PORT = '587'
|
|
|
|
EMAIL_HOST_USER = secrets.EMAIL_USER
|
|
|
|
EMAIL_HOST_PASSWORD = secrets.EMAIL_PASS
|
|
|
|
EMAIL_USE_TLS = True
|
|
|
|
EMAIL_USE_SSL = False
|
2021-09-26 00:54:25 +00:00
|
|
|
DEFAULT_FROM_EMAIL = 'Protospace Portal <portal@mg.protospace.ca>'
|
2020-06-19 23:49:05 +00:00
|
|
|
|
2020-03-08 01:07:09 +00:00
|
|
|
if DEBUG: logger.info('Debug mode ON')
|
2020-03-08 00:36:16 +00:00
|
|
|
logger.info('Test logging for each thread')
|
|
|
|
|
2022-02-05 21:17:43 +00:00
|
|
|
APP_VERSION = 3 # TODO: automate this
|
2022-01-21 22:48:51 +00:00
|
|
|
|
2020-03-08 00:36:16 +00:00
|
|
|
#import logging_tree
|
|
|
|
#logging_tree.printout()
|