2018-11-11 12:41:48 +00:00
|
|
|
"""
|
|
|
|
Django settings for passbook project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 2.1.3.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/2.1/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/2.1/ref/settings/
|
|
|
|
"""
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
import importlib
|
2018-11-11 12:41:48 +00:00
|
|
|
import os
|
2020-09-17 19:16:31 +00:00
|
|
|
import sys
|
2020-09-06 13:52:48 +00:00
|
|
|
from json import dumps
|
2020-11-16 00:41:33 +00:00
|
|
|
from time import time
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-09-30 16:04:04 +00:00
|
|
|
import structlog
|
2019-10-08 12:30:17 +00:00
|
|
|
from celery.schedules import crontab
|
2019-04-04 19:48:50 +00:00
|
|
|
from sentry_sdk import init as sentry_init
|
|
|
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
|
|
|
from sentry_sdk.integrations.django import DjangoIntegration
|
2020-10-18 20:58:05 +00:00
|
|
|
from sentry_sdk.integrations.redis import RedisIntegration
|
2018-11-23 08:44:22 +00:00
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
from passbook import __version__
|
2020-09-21 17:31:01 +00:00
|
|
|
from passbook.core.middleware import structlog_add_request_id
|
2018-11-16 08:10:35 +00:00
|
|
|
from passbook.lib.config import CONFIG
|
2020-09-21 17:31:01 +00:00
|
|
|
from passbook.lib.logging import add_common_fields, add_process_id
|
2019-04-29 17:16:49 +00:00
|
|
|
from passbook.lib.sentry import before_send
|
2018-11-16 08:10:35 +00:00
|
|
|
|
2020-09-16 19:54:35 +00:00
|
|
|
|
|
|
|
def j_print(event: str, log_level: str = "info", **kwargs):
|
|
|
|
"""Print event in the same format as structlog with JSON.
|
|
|
|
Used before structlog is configured."""
|
|
|
|
data = {
|
|
|
|
"event": event,
|
|
|
|
"level": log_level,
|
|
|
|
"logger": __name__,
|
2020-11-16 00:41:33 +00:00
|
|
|
"timestamp": time(),
|
2020-09-16 19:54:35 +00:00
|
|
|
}
|
|
|
|
data.update(**kwargs)
|
2020-09-17 19:16:31 +00:00
|
|
|
print(dumps(data), file=sys.stderr)
|
2020-09-16 19:54:35 +00:00
|
|
|
|
|
|
|
|
2019-10-15 11:52:33 +00:00
|
|
|
LOGGER = structlog.get_logger()
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2019-12-31 11:51:16 +00:00
|
|
|
STATIC_ROOT = BASE_DIR + "/static"
|
2020-11-23 19:50:19 +00:00
|
|
|
MEDIA_ROOT = BASE_DIR + "/media"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
2019-12-31 11:51:16 +00:00
|
|
|
SECRET_KEY = CONFIG.y(
|
|
|
|
"secret_key", "9$@r!d^1^jrn#fk#1#@ks#9&i$^s#1)_13%$rwjrhd=e8jfi_s"
|
|
|
|
) # noqa Debug
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
DEBUG = CONFIG.y_bool("debug")
|
|
|
|
INTERNAL_IPS = ["127.0.0.1"]
|
|
|
|
ALLOWED_HOSTS = ["*"]
|
|
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-05-12 12:49:47 +00:00
|
|
|
LOGIN_URL = "passbook_flows:default-authentication"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Custom user model
|
2019-12-31 11:51:16 +00:00
|
|
|
AUTH_USER_MODEL = "passbook_core.User"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-05-13 21:20:27 +00:00
|
|
|
_cookie_suffix = "_debug" if DEBUG else ""
|
2020-10-16 12:17:47 +00:00
|
|
|
CSRF_COOKIE_NAME = "passbook_csrf"
|
2020-05-13 21:20:27 +00:00
|
|
|
LANGUAGE_COOKIE_NAME = f"passbook_language{_cookie_suffix}"
|
|
|
|
SESSION_COOKIE_NAME = f"passbook_session{_cookie_suffix}"
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
AUTHENTICATION_BACKENDS = [
|
2019-12-31 11:51:16 +00:00
|
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
|
|
"guardian.backends.ObjectPermissionBackend",
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
2019-12-31 11:51:16 +00:00
|
|
|
"django.contrib.admin",
|
|
|
|
"django.contrib.auth",
|
|
|
|
"django.contrib.contenttypes",
|
|
|
|
"django.contrib.sessions",
|
|
|
|
"django.contrib.messages",
|
|
|
|
"django.contrib.staticfiles",
|
2020-05-10 18:16:58 +00:00
|
|
|
"django.contrib.humanize",
|
2019-12-31 11:51:16 +00:00
|
|
|
"passbook.admin.apps.PassbookAdminConfig",
|
|
|
|
"passbook.api.apps.PassbookAPIConfig",
|
|
|
|
"passbook.audit.apps.PassbookAuditConfig",
|
2020-03-03 22:35:25 +00:00
|
|
|
"passbook.crypto.apps.PassbookCryptoConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.flows.apps.PassbookFlowsConfig",
|
2020-09-02 22:04:12 +00:00
|
|
|
"passbook.outposts.apps.PassbookOutpostConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.lib.apps.PassbookLibConfig",
|
|
|
|
"passbook.policies.apps.PassbookPoliciesConfig",
|
|
|
|
"passbook.policies.dummy.apps.PassbookPolicyDummyConfig",
|
|
|
|
"passbook.policies.expiry.apps.PassbookPolicyExpiryConfig",
|
|
|
|
"passbook.policies.expression.apps.PassbookPolicyExpressionConfig",
|
|
|
|
"passbook.policies.hibp.apps.PassbookPolicyHIBPConfig",
|
|
|
|
"passbook.policies.password.apps.PassbookPoliciesPasswordConfig",
|
2020-07-01 19:18:05 +00:00
|
|
|
"passbook.policies.group_membership.apps.PassbookPoliciesGroupMembershipConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.policies.reputation.apps.PassbookPolicyReputationConfig",
|
2020-08-19 08:32:44 +00:00
|
|
|
"passbook.providers.proxy.apps.PassbookProviderProxyConfig",
|
|
|
|
"passbook.providers.oauth2.apps.PassbookProviderOAuth2Config",
|
2019-12-31 11:51:16 +00:00
|
|
|
"passbook.providers.saml.apps.PassbookProviderSAMLConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.recovery.apps.PassbookRecoveryConfig",
|
|
|
|
"passbook.sources.ldap.apps.PassbookSourceLDAPConfig",
|
|
|
|
"passbook.sources.oauth.apps.PassbookSourceOAuthConfig",
|
|
|
|
"passbook.sources.saml.apps.PassbookSourceSAMLConfig",
|
|
|
|
"passbook.stages.captcha.apps.PassbookStageCaptchaConfig",
|
2020-06-07 14:35:08 +00:00
|
|
|
"passbook.stages.consent.apps.PassbookStageConsentConfig",
|
2020-05-10 11:06:38 +00:00
|
|
|
"passbook.stages.dummy.apps.PassbookStageDummyConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.stages.email.apps.PassbookStageEmailConfig",
|
|
|
|
"passbook.stages.prompt.apps.PassbookStagPromptConfig",
|
2020-05-09 18:53:47 +00:00
|
|
|
"passbook.stages.identification.apps.PassbookStageIdentificationConfig",
|
2020-05-11 19:58:02 +00:00
|
|
|
"passbook.stages.invitation.apps.PassbookStageUserInvitationConfig",
|
2020-05-12 12:50:00 +00:00
|
|
|
"passbook.stages.user_delete.apps.PassbookStageUserDeleteConfig",
|
2020-05-10 14:20:44 +00:00
|
|
|
"passbook.stages.user_login.apps.PassbookStageUserLoginConfig",
|
2020-05-10 23:12:14 +00:00
|
|
|
"passbook.stages.user_logout.apps.PassbookStageUserLogoutConfig",
|
2020-05-10 21:38:15 +00:00
|
|
|
"passbook.stages.user_write.apps.PassbookStageUserWriteConfig",
|
2020-06-30 11:49:23 +00:00
|
|
|
"passbook.stages.otp_static.apps.PassbookStageOTPStaticConfig",
|
2020-06-28 08:30:35 +00:00
|
|
|
"passbook.stages.otp_time.apps.PassbookStageOTPTimeConfig",
|
|
|
|
"passbook.stages.otp_validate.apps.PassbookStageOTPValidateConfig",
|
2020-05-08 17:46:39 +00:00
|
|
|
"passbook.stages.password.apps.PassbookStagePasswordConfig",
|
2020-05-10 14:20:17 +00:00
|
|
|
"passbook.static.apps.PassbookStaticConfig",
|
2020-10-03 21:20:33 +00:00
|
|
|
"rest_framework",
|
|
|
|
"django_filters",
|
2020-10-16 20:54:14 +00:00
|
|
|
"drf_yasg2",
|
2020-10-03 21:20:33 +00:00
|
|
|
"guardian",
|
|
|
|
"django_prometheus",
|
|
|
|
"channels",
|
|
|
|
"dbbackup",
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
2019-10-10 08:45:51 +00:00
|
|
|
GUARDIAN_MONKEY_PATCH = False
|
|
|
|
|
2019-10-28 16:40:57 +00:00
|
|
|
SWAGGER_SETTINGS = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"DEFAULT_INFO": "passbook.api.v2.urls.info",
|
2020-07-05 21:15:07 +00:00
|
|
|
"SECURITY_DEFINITIONS": {
|
|
|
|
"token": {"type": "apiKey", "name": "Authorization", "in": "header"}
|
|
|
|
},
|
2019-10-28 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
REST_FRAMEWORK = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
|
|
|
|
"PAGE_SIZE": 100,
|
|
|
|
"DEFAULT_FILTER_BACKENDS": [
|
2020-09-02 22:04:12 +00:00
|
|
|
"rest_framework_guardian.filters.ObjectPermissionsFilter",
|
2019-12-31 11:51:16 +00:00
|
|
|
"django_filters.rest_framework.DjangoFilterBackend",
|
|
|
|
"rest_framework.filters.OrderingFilter",
|
|
|
|
"rest_framework.filters.SearchFilter",
|
2019-10-28 16:40:57 +00:00
|
|
|
],
|
2020-07-07 12:02:20 +00:00
|
|
|
"DEFAULT_PERMISSION_CLASSES": (
|
|
|
|
"rest_framework.permissions.DjangoObjectPermissions",
|
|
|
|
),
|
2019-12-31 11:51:16 +00:00
|
|
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
2020-07-05 21:15:07 +00:00
|
|
|
"passbook.api.auth.PassbookTokenAuthentication",
|
2019-12-31 11:51:16 +00:00
|
|
|
"rest_framework.authentication.SessionAuthentication",
|
2019-10-28 16:40:57 +00:00
|
|
|
),
|
2018-11-16 08:10:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 10:08:08 +00:00
|
|
|
CACHES = {
|
|
|
|
"default": {
|
2019-11-08 12:56:09 +00:00
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
2019-12-31 11:51:16 +00:00
|
|
|
"LOCATION": (
|
|
|
|
f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}:6379"
|
|
|
|
f"/{CONFIG.y('redis.cache_db')}"
|
|
|
|
),
|
2020-05-27 09:26:48 +00:00
|
|
|
"OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
|
2019-03-21 10:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-30 16:04:04 +00:00
|
|
|
DJANGO_REDIS_IGNORE_EXCEPTIONS = True
|
|
|
|
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
|
2019-10-14 13:00:20 +00:00
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
2019-09-30 16:04:04 +00:00
|
|
|
SESSION_CACHE_ALIAS = "default"
|
2020-09-11 21:21:11 +00:00
|
|
|
SESSION_COOKIE_SAMESITE = "lax"
|
2019-03-21 10:08:08 +00:00
|
|
|
|
2020-11-26 16:08:26 +00:00
|
|
|
MESSAGE_STORAGE = "passbook.root.messages.storage.ChannelsStorage"
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
MIDDLEWARE = [
|
2019-12-31 11:51:16 +00:00
|
|
|
"django_prometheus.middleware.PrometheusBeforeMiddleware",
|
|
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
2020-09-21 17:31:01 +00:00
|
|
|
"passbook.core.middleware.RequestIDMiddleware",
|
2020-09-21 18:16:14 +00:00
|
|
|
"passbook.audit.middleware.AuditMiddleware",
|
2019-12-31 11:51:16 +00:00
|
|
|
"django.middleware.security.SecurityMiddleware",
|
|
|
|
"django.middleware.common.CommonMiddleware",
|
|
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
2020-09-17 14:24:53 +00:00
|
|
|
"passbook.core.middleware.ImpersonateMiddleware",
|
2019-12-31 11:51:16 +00:00
|
|
|
"django_prometheus.middleware.PrometheusAfterMiddleware",
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
ROOT_URLCONF = "passbook.root.urls"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
2019-12-31 11:51:16 +00:00
|
|
|
"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",
|
2020-07-08 11:18:33 +00:00
|
|
|
"passbook.lib.config.context_processor",
|
2018-11-11 12:41:48 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-11-11 13:48:19 +00:00
|
|
|
ASGI_APPLICATION = "passbook.root.asgi.application"
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
CHANNEL_LAYERS = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
2020-09-14 12:21:43 +00:00
|
|
|
"CONFIG": {
|
|
|
|
"hosts": [
|
|
|
|
f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}:6379"
|
|
|
|
f"/{CONFIG.y('redis.ws_db')}"
|
|
|
|
],
|
|
|
|
},
|
2020-09-02 22:04:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Database
|
|
|
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
|
|
|
|
2019-09-30 16:04:04 +00:00
|
|
|
DATABASES = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"default": {
|
2020-06-15 10:12:32 +00:00
|
|
|
"ENGINE": "django.db.backends.postgresql",
|
2019-12-31 11:51:16 +00:00
|
|
|
"HOST": CONFIG.y("postgresql.host"),
|
|
|
|
"NAME": CONFIG.y("postgresql.name"),
|
|
|
|
"USER": CONFIG.y("postgresql.user"),
|
|
|
|
"PASSWORD": CONFIG.y("postgresql.password"),
|
2018-11-11 12:41:48 +00:00
|
|
|
}
|
2019-09-30 16:04:04 +00:00
|
|
|
}
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
|
|
{
|
2019-12-31 11:51:16 +00:00
|
|
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
2018-11-11 12:41:48 +00:00
|
|
|
},
|
2020-05-27 09:26:48 +00:00
|
|
|
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
|
|
|
|
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
|
|
|
|
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
LANGUAGE_CODE = "en-us"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
TIME_ZONE = "UTC"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
2018-11-27 15:23:29 +00:00
|
|
|
|
|
|
|
# Celery settings
|
|
|
|
# Add a 10 minute timeout to all Celery tasks.
|
|
|
|
CELERY_TASK_SOFT_TIME_LIMIT = 600
|
2019-10-08 12:30:17 +00:00
|
|
|
CELERY_BEAT_SCHEDULE = {
|
2020-08-20 19:53:20 +00:00
|
|
|
"clean_expired_models": {
|
|
|
|
"task": "passbook.core.tasks.clean_expired_models",
|
2020-10-19 20:17:47 +00:00
|
|
|
"schedule": crontab(minute="*/5"),
|
2020-09-02 22:04:12 +00:00
|
|
|
"options": {"queue": "passbook_scheduled"},
|
2020-10-19 20:17:47 +00:00
|
|
|
},
|
|
|
|
"db_backup": {
|
2020-10-23 16:32:28 +00:00
|
|
|
"task": "passbook.core.tasks.backup_database",
|
2020-10-19 20:17:47 +00:00
|
|
|
"schedule": crontab(minute=0, hour=0),
|
|
|
|
"options": {"queue": "passbook_scheduled"},
|
|
|
|
},
|
2019-10-08 12:30:17 +00:00
|
|
|
}
|
2020-10-03 18:36:36 +00:00
|
|
|
CELERY_TASK_CREATE_MISSING_QUEUES = True
|
2019-12-31 11:51:16 +00:00
|
|
|
CELERY_TASK_DEFAULT_QUEUE = "passbook"
|
|
|
|
CELERY_BROKER_URL = (
|
|
|
|
f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}"
|
|
|
|
f":6379/{CONFIG.y('redis.message_queue_db')}"
|
|
|
|
)
|
|
|
|
CELERY_RESULT_BACKEND = (
|
|
|
|
f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}"
|
|
|
|
f":6379/{CONFIG.y('redis.message_queue_db')}"
|
|
|
|
)
|
2019-03-03 19:48:31 +00:00
|
|
|
|
2019-10-15 11:52:33 +00:00
|
|
|
# Database backup
|
2020-10-03 18:36:36 +00:00
|
|
|
DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage"
|
|
|
|
DBBACKUP_STORAGE_OPTIONS = {"location": "./backups" if DEBUG else "/backups"}
|
|
|
|
DBBACKUP_CONNECTOR_MAPPING = {
|
|
|
|
"django_prometheus.db.backends.postgresql": "dbbackup.db.postgresql.PgDumpConnector"
|
|
|
|
}
|
|
|
|
if CONFIG.y("postgresql.s3_backup"):
|
2019-12-31 11:51:16 +00:00
|
|
|
DBBACKUP_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
|
2020-10-03 18:36:36 +00:00
|
|
|
DBBACKUP_STORAGE_OPTIONS = {
|
|
|
|
"access_key": CONFIG.y("postgresql.s3_backup.access_key"),
|
|
|
|
"secret_key": CONFIG.y("postgresql.s3_backup.secret_key"),
|
|
|
|
"bucket_name": CONFIG.y("postgresql.s3_backup.bucket"),
|
|
|
|
"region_name": CONFIG.y("postgresql.s3_backup.region", "eu-central-1"),
|
|
|
|
"default_acl": "private",
|
|
|
|
"endpoint_url": CONFIG.y("postgresql.s3_backup.host"),
|
2019-11-19 17:08:25 +00:00
|
|
|
}
|
2020-10-01 11:41:40 +00:00
|
|
|
j_print(
|
2020-10-03 18:36:36 +00:00
|
|
|
"Database backup to S3 is configured.",
|
|
|
|
host=CONFIG.y("postgresql.s3_backup.host"),
|
2020-10-01 11:41:40 +00:00
|
|
|
)
|
2019-04-11 13:30:42 +00:00
|
|
|
|
2019-10-15 11:52:33 +00:00
|
|
|
# Sentry integration
|
2020-08-20 18:39:21 +00:00
|
|
|
_ERROR_REPORTING = CONFIG.y_bool("error_reporting.enabled", False)
|
2019-11-20 12:12:37 +00:00
|
|
|
if not DEBUG and _ERROR_REPORTING:
|
2019-04-11 13:30:42 +00:00
|
|
|
sentry_init(
|
2019-07-03 15:35:54 +00:00
|
|
|
dsn="https://33cdbcb23f8b436dbe0ee06847410b67@sentry.beryju.org/3",
|
2020-08-20 21:12:54 +00:00
|
|
|
integrations=[
|
|
|
|
DjangoIntegration(transaction_style="function_name"),
|
|
|
|
CeleryIntegration(),
|
2020-10-18 20:39:13 +00:00
|
|
|
RedisIntegration(),
|
2020-08-20 21:12:54 +00:00
|
|
|
],
|
2019-04-29 17:16:49 +00:00
|
|
|
before_send=before_send,
|
2019-12-31 11:51:16 +00:00
|
|
|
release="passbook@%s" % __version__,
|
2020-11-03 21:53:24 +00:00
|
|
|
traces_sample_rate=0.6,
|
2020-08-20 18:39:21 +00:00
|
|
|
environment=CONFIG.y("error_reporting.environment", "customer"),
|
2020-08-20 20:19:49 +00:00
|
|
|
send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False),
|
2019-04-11 13:30:42 +00:00
|
|
|
)
|
2020-09-16 19:54:35 +00:00
|
|
|
j_print(
|
|
|
|
"Error reporting is enabled.",
|
|
|
|
env=CONFIG.y("error_reporting.environment", "customer"),
|
|
|
|
)
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-07-07 15:53:35 +00:00
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
STATIC_URL = "/static/"
|
2020-11-24 10:50:27 +00:00
|
|
|
MEDIA_URL = "/media/"
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-09-30 16:04:04 +00:00
|
|
|
|
|
|
|
structlog.configure_once(
|
|
|
|
processors=[
|
|
|
|
structlog.stdlib.add_log_level,
|
2020-02-20 12:52:14 +00:00
|
|
|
structlog.stdlib.add_logger_name,
|
2020-02-24 12:16:05 +00:00
|
|
|
add_process_id,
|
2020-09-21 17:31:01 +00:00
|
|
|
add_common_fields(CONFIG.y("error_reporting.environment", "customer")),
|
|
|
|
structlog_add_request_id,
|
2019-09-30 16:04:04 +00:00
|
|
|
structlog.stdlib.PositionalArgumentsFormatter(),
|
|
|
|
structlog.processors.TimeStamper(),
|
|
|
|
structlog.processors.StackInfoRenderer(),
|
2020-02-18 09:57:30 +00:00
|
|
|
structlog.processors.format_exc_info,
|
2019-09-30 16:04:04 +00:00
|
|
|
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
|
|
|
|
],
|
|
|
|
context_class=structlog.threadlocal.wrap_dict(dict),
|
|
|
|
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
|
|
wrapper_class=structlog.stdlib.BoundLogger,
|
|
|
|
cache_logger_on_first_use=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
LOG_PRE_CHAIN = [
|
|
|
|
# Add the log level and a timestamp to the event_dict if the log entry
|
|
|
|
# is not from structlog.
|
|
|
|
structlog.stdlib.add_log_level,
|
2020-07-16 15:21:46 +00:00
|
|
|
structlog.stdlib.add_logger_name,
|
2019-09-30 16:04:04 +00:00
|
|
|
structlog.processors.TimeStamper(),
|
2020-07-20 14:55:55 +00:00
|
|
|
structlog.processors.StackInfoRenderer(),
|
|
|
|
structlog.processors.format_exc_info,
|
2019-09-30 16:04:04 +00:00
|
|
|
]
|
|
|
|
|
2019-11-11 12:19:54 +00:00
|
|
|
LOGGING = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"version": 1,
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
"formatters": {
|
2019-11-11 12:19:54 +00:00
|
|
|
"plain": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.processors.JSONRenderer(sort_keys=True),
|
|
|
|
"foreign_pre_chain": LOG_PRE_CHAIN,
|
2018-11-11 12:41:48 +00:00
|
|
|
},
|
2019-11-11 12:19:54 +00:00
|
|
|
"colored": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.dev.ConsoleRenderer(colors=DEBUG),
|
|
|
|
"foreign_pre_chain": LOG_PRE_CHAIN,
|
2018-11-11 12:41:48 +00:00
|
|
|
},
|
2019-11-11 12:19:54 +00:00
|
|
|
},
|
2019-12-31 11:51:16 +00:00
|
|
|
"handlers": {
|
|
|
|
"console": {
|
2020-02-24 14:30:28 +00:00
|
|
|
"level": "DEBUG",
|
2019-12-31 11:51:16 +00:00
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
"formatter": "colored" if DEBUG else "plain",
|
2019-11-11 12:19:54 +00:00
|
|
|
},
|
|
|
|
},
|
2019-12-31 11:51:16 +00:00
|
|
|
"loggers": {},
|
2019-11-11 12:19:54 +00:00
|
|
|
}
|
2020-06-20 13:48:54 +00:00
|
|
|
|
|
|
|
TEST = False
|
2020-09-11 21:21:11 +00:00
|
|
|
TEST_RUNNER = "passbook.root.test_runner.PytestTestRunner"
|
2020-05-16 20:14:26 +00:00
|
|
|
LOG_LEVEL = CONFIG.y("log_level").upper()
|
|
|
|
|
2020-06-20 13:48:54 +00:00
|
|
|
|
2019-11-11 12:19:54 +00:00
|
|
|
_LOGGING_HANDLER_MAP = {
|
2020-05-09 18:53:47 +00:00
|
|
|
"": LOG_LEVEL,
|
|
|
|
"passbook": LOG_LEVEL,
|
2020-08-14 15:55:44 +00:00
|
|
|
"django": "WARNING",
|
|
|
|
"celery": "WARNING",
|
|
|
|
"selenium": "WARNING",
|
2020-05-09 18:53:47 +00:00
|
|
|
"grpc": LOG_LEVEL,
|
2020-08-14 15:55:44 +00:00
|
|
|
"docker": "WARNING",
|
|
|
|
"urllib3": "WARNING",
|
2020-09-02 22:04:12 +00:00
|
|
|
"websockets": "WARNING",
|
2020-09-05 23:07:06 +00:00
|
|
|
"daphne": "WARNING",
|
2020-10-03 18:36:36 +00:00
|
|
|
"dbbackup": "ERROR",
|
2020-10-19 15:39:12 +00:00
|
|
|
"kubernetes": "INFO",
|
2020-11-22 19:33:04 +00:00
|
|
|
"asyncio": "WARNING",
|
2019-11-11 12:19:54 +00:00
|
|
|
}
|
|
|
|
for handler_name, level in _LOGGING_HANDLER_MAP.items():
|
2020-05-09 18:53:47 +00:00
|
|
|
# pyright: reportGeneralTypeIssues=false
|
2019-12-31 11:51:16 +00:00
|
|
|
LOGGING["loggers"][handler_name] = {
|
|
|
|
"handlers": ["console"],
|
|
|
|
"level": level,
|
2020-02-24 14:30:28 +00:00
|
|
|
"propagate": False,
|
2018-11-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2019-09-30 16:04:04 +00:00
|
|
|
|
2019-10-11 10:47:29 +00:00
|
|
|
_DISALLOWED_ITEMS = [
|
2019-12-31 11:51:16 +00:00
|
|
|
"INSTALLED_APPS",
|
|
|
|
"MIDDLEWARE",
|
|
|
|
"AUTHENTICATION_BACKENDS",
|
|
|
|
"CELERY_BEAT_SCHEDULE",
|
2019-10-11 10:47:29 +00:00
|
|
|
]
|
2018-11-16 08:10:35 +00:00
|
|
|
# Load subapps's INSTALLED_APPS
|
|
|
|
for _app in INSTALLED_APPS:
|
2019-12-31 11:51:16 +00:00
|
|
|
if _app.startswith("passbook"):
|
|
|
|
if "apps" in _app:
|
|
|
|
_app = ".".join(_app.split(".")[:-2])
|
2018-11-16 08:10:35 +00:00
|
|
|
try:
|
|
|
|
app_settings = importlib.import_module("%s.settings" % _app)
|
2019-12-31 11:51:16 +00:00
|
|
|
INSTALLED_APPS.extend(getattr(app_settings, "INSTALLED_APPS", []))
|
|
|
|
MIDDLEWARE.extend(getattr(app_settings, "MIDDLEWARE", []))
|
|
|
|
AUTHENTICATION_BACKENDS.extend(
|
|
|
|
getattr(app_settings, "AUTHENTICATION_BACKENDS", [])
|
|
|
|
)
|
|
|
|
CELERY_BEAT_SCHEDULE.update(
|
|
|
|
getattr(app_settings, "CELERY_BEAT_SCHEDULE", {})
|
|
|
|
)
|
2018-11-24 21:27:02 +00:00
|
|
|
for _attr in dir(app_settings):
|
2019-12-31 11:51:16 +00:00
|
|
|
if not _attr.startswith("__") and _attr not in _DISALLOWED_ITEMS:
|
2018-11-24 21:27:02 +00:00
|
|
|
globals()[_attr] = getattr(app_settings, _attr)
|
2018-11-16 08:10:35 +00:00
|
|
|
except ImportError:
|
|
|
|
pass
|
2018-11-24 21:27:02 +00:00
|
|
|
|
|
|
|
if DEBUG:
|
2019-12-31 11:51:16 +00:00
|
|
|
INSTALLED_APPS.append("debug_toolbar")
|
|
|
|
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
2020-10-19 20:17:47 +00:00
|
|
|
CELERY_TASK_ALWAYS_EAGER = True
|
2020-05-06 22:05:10 +00:00
|
|
|
|
|
|
|
INSTALLED_APPS.append("passbook.core.apps.PassbookCoreConfig")
|
2020-09-16 19:54:35 +00:00
|
|
|
|
|
|
|
j_print("Booting passbook", version=__version__)
|