Files
tabby-web/tabby/settings.py

247 lines
6.4 KiB
Python
Raw Normal View History

2021-06-17 23:28:03 +02:00
import os
2021-07-06 23:45:52 +02:00
import dj_database_url
2021-06-17 23:28:03 +02:00
from dotenv import load_dotenv
2021-05-31 20:13:09 +02:00
from pathlib import Path
2021-06-17 23:28:03 +02:00
load_dotenv()
2021-05-31 20:13:09 +02:00
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-jw3fshufj(1$iv+&9bie=r%27+^e2sz0!_gq38*5p5!csrm&#s'
# SECURITY WARNING: don't run with debug turned on in production!
2021-07-07 01:08:58 +02:00
DEBUG = bool(os.getenv('DEBUG', False))
2021-05-31 20:13:09 +02:00
2021-06-17 23:28:03 +02:00
ALLOWED_HOSTS = ['*']
2021-07-11 22:58:03 +02:00
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
2021-05-31 20:13:09 +02:00
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
2021-06-12 13:05:35 +02:00
'channels',
'rest_framework',
2021-06-16 23:49:44 +02:00
'social_django',
2021-07-25 14:00:22 +02:00
'corsheaders',
2021-07-06 23:45:52 +02:00
'tabby.app',
2021-05-31 20:13:09 +02: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',
2021-07-25 14:00:22 +02:00
'corsheaders.middleware.CorsMiddleware',
2021-07-24 15:48:12 +02:00
'tabby.middleware.TokenMiddleware',
2021-07-16 20:25:00 +02:00
'tabby.middleware.GAMiddleware',
2021-05-31 20:13:09 +02:00
]
2021-07-06 23:45:52 +02:00
ROOT_URLCONF = 'tabby.urls'
2021-05-31 20:13:09 +02:00
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',
],
},
},
]
2021-07-06 23:45:52 +02:00
ASGI_APPLICATION = 'tabby.asgi.application'
WSGI_APPLICATION = 'tabby.wsgi.application'
2021-05-31 20:13:09 +02:00
DATABASES = {
2021-07-06 23:45:52 +02:00
'default': dj_database_url.config(conn_max_age=600)
2021-05-31 20:13:09 +02:00
}
2021-07-22 21:34:05 +02:00
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
2021-05-31 20:13:09 +02:00
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',
},
]
2021-06-12 13:05:35 +02:00
AUTH_USER_MODEL = 'app.User'
2021-05-31 20:13:09 +02:00
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
2021-07-11 16:13:18 +02:00
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'': {
'handlers': ['console'],
'propagate': False,
'level': 'INFO',
},
},
}
2021-05-31 20:13:09 +02:00
STATIC_URL = '/static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
2021-06-14 23:00:05 +02:00
CSRF_USE_SESSIONS = False
CSRF_COOKIE_HTTPONLY = False
CSRF_COOKIE_NAME = 'XSRF-TOKEN'
CSRF_HEADER_NAME = 'HTTP_X_XSRF_TOKEN'
2021-06-15 23:43:23 +02:00
2021-06-17 23:28:03 +02:00
AUTHENTICATION_BACKENDS = (
'social_core.backends.github.GithubOAuth2',
'social_core.backends.gitlab.GitLabOAuth2',
'social_core.backends.azuread.AzureADOAuth2',
'social_core.backends.microsoft.MicrosoftOAuth2',
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
2021-06-25 21:55:40 +02:00
SOCIAL_AUTH_GITHUB_SCOPE = ['read:user', 'user:email']
2021-07-22 21:34:05 +02:00
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
2021-06-25 21:55:40 +02:00
2021-07-11 16:13:18 +02:00
APP_DIST_PATH = Path(os.getenv('APP_DIST_PATH', BASE_DIR / 'app-dist'))
NPM_REGISTRY = os.getenv('NPM_REGISTRY', 'https://registry.npmjs.org').rstrip('/')
2021-06-17 23:28:03 +02:00
2021-07-25 14:00:22 +02:00
FRONTEND_URL = None
2021-07-24 15:48:12 +02:00
GITHUB_ELIGIBLE_SPONSORSHIPS = None
2021-06-17 23:28:03 +02:00
for key in [
2021-07-25 14:00:22 +02:00
'FRONTEND_URL',
2021-06-17 23:28:03 +02:00
'SOCIAL_AUTH_GITHUB_KEY',
'SOCIAL_AUTH_GITHUB_SECRET',
'SOCIAL_AUTH_GITLAB_KEY',
'SOCIAL_AUTH_GITLAB_SECRET',
'SOCIAL_AUTH_GOOGLE_OAUTH2_KEY',
'SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET',
'SOCIAL_AUTH_MICROSOFT_GRAPH_KEY',
'SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET',
2021-06-20 22:42:58 +02:00
'CONNECTION_GATEWAY_AUTH_CA',
'CONNECTION_GATEWAY_AUTH_CERTIFICATE',
'CONNECTION_GATEWAY_AUTH_KEY',
2021-07-24 15:48:12 +02:00
'GITHUB_ELIGIBLE_SPONSORSHIPS',
2021-06-25 21:55:40 +02:00
'GITHUB_SPONSORS_MIN_PAYMENT',
2021-06-28 09:32:13 +02:00
'ENABLE_LOGIN',
2021-07-16 20:25:00 +02:00
'GA_ID',
'GA_DOMAIN',
2021-06-17 23:28:03 +02:00
]:
globals()[key] = os.getenv(key)
2021-06-20 22:42:58 +02:00
2021-06-25 21:55:40 +02:00
for key in [
'GITHUB_SPONSORS_MIN_PAYMENT',
]:
globals()[key] = int(globals()[key]) if globals()[key] else None
2021-07-11 16:13:18 +02:00
for key in [
'ENABLE_LOGIN',
]:
2021-07-16 20:25:00 +02:00
globals()[key] = bool(globals()[key]) if globals()[key] else None
2021-07-11 16:13:18 +02:00
2021-06-20 22:42:58 +02:00
for key in [
'CONNECTION_GATEWAY_AUTH_CA',
'CONNECTION_GATEWAY_AUTH_CERTIFICATE',
'CONNECTION_GATEWAY_AUTH_KEY',
]:
v = globals()[key]
if v and not os.path.exists(v):
raise ValueError(f'{v} does not exist')
2021-07-24 15:48:12 +02:00
if GITHUB_ELIGIBLE_SPONSORSHIPS:
GITHUB_ELIGIBLE_SPONSORSHIPS = GITHUB_ELIGIBLE_SPONSORSHIPS.split(',')
else:
GITHUB_ELIGIBLE_SPONSORSHIPS = []
2021-07-25 14:00:22 +02:00
if FRONTEND_URL:
CORS_ALLOWED_ORIGINS = [FRONTEND_URL]
2021-07-25 14:38:14 +02:00
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-xsrf-token',
'x-requested-with',
]
CSRF_TRUSTED_ORIGINS = [FRONTEND_URL]
FRONTEND_URL = FRONTEND_URL.rstrip('/')
else:
FRONTEND_URL = ''
LOGIN_REDIRECT_URL = FRONTEND_URL + '/app'