|
1 | | -from .base import * |
| 1 | +import logging |
2 | 2 |
|
3 | | -DEBUG = False |
| 3 | +import sentry_sdk |
| 4 | +from sentry_sdk.integrations.celery import CeleryIntegration |
| 5 | +from sentry_sdk.integrations.django import DjangoIntegration |
| 6 | +from sentry_sdk.integrations.logging import LoggingIntegration |
| 7 | +from sentry_sdk.integrations.redis import RedisIntegration |
4 | 8 |
|
5 | | -try: |
6 | | - from .local import * |
7 | | -except ImportError: |
8 | | - pass |
| 9 | +from .base import * # noqa |
| 10 | +from .base import env |
| 11 | + |
| 12 | +# GENERAL |
| 13 | +# ------------------------------------------------------------------------------ |
| 14 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key |
| 15 | +SECRET_KEY = env("DJANGO_SECRET_KEY") |
| 16 | +# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts |
| 17 | +ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["example.com"]) |
| 18 | + |
| 19 | +# DATABASES |
| 20 | +# ------------------------------------------------------------------------------ |
| 21 | +DATABASES["default"] = env.db("DATABASE_URL") # noqa F405 |
| 22 | +DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405 |
| 23 | +DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405 |
| 24 | +DATABASES["default"]["ENGINE"] = 'django.db.backends.postgresql' |
| 25 | +# CACHES |
| 26 | +# ------------------------------------------------------------------------------ |
| 27 | +CACHES = { |
| 28 | + "default": { |
| 29 | + "BACKEND": "django.core.cache.backends.redis.RedisCache", |
| 30 | + "LOCATION": env("REDIS_URL"), |
| 31 | + "OPTIONS": { |
| 32 | + "CLIENT_CLASS": "django_redis.client.DefaultClient", |
| 33 | + # Mimicing memcache behavior. |
| 34 | + # https://github.com/jazzband/django-redis#memcached-exceptions-behavior |
| 35 | + "IGNORE_EXCEPTIONS": True, |
| 36 | + }, |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +# SECURITY |
| 41 | +# ------------------------------------------------------------------------------ |
| 42 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header |
| 43 | +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") |
| 44 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect |
| 45 | +SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True) |
| 46 | +# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure |
| 47 | +SESSION_COOKIE_SECURE = env.bool("SESSION_COOKIE_SECURE", default=True) |
| 48 | +# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure |
| 49 | +CSRF_COOKIE_SECURE = env.bool("CSRF_COOKIE_SECURE", default=True) |
| 50 | +# https://docs.djangoproject.com/en/dev/topics/security/#ssl-https |
| 51 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds |
| 52 | +# TODO: set this to 60 seconds first and then to 518400 once you prove the former works |
| 53 | +SECURE_HSTS_SECONDS = 60 |
| 54 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains |
| 55 | +SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( |
| 56 | + "DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True |
| 57 | +) |
| 58 | +# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload |
| 59 | +SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True) |
| 60 | +# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff |
| 61 | +SECURE_CONTENT_TYPE_NOSNIFF = env.bool( |
| 62 | + "DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True |
| 63 | +) |
| 64 | + |
| 65 | +# STATIC |
| 66 | +# ------------------------ |
| 67 | +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" |
| 68 | +# MEDIA |
| 69 | +# ------------------------------------------------------------------------------ |
| 70 | + |
| 71 | +# EMAIL |
| 72 | +# ------------------------------------------------------------------------------ |
| 73 | +# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email |
| 74 | +DEFAULT_FROM_EMAIL = env( |
| 75 | + "DJANGO_DEFAULT_FROM_EMAIL", |
| 76 | + default="SciELO Content Manager <suporte.aplicacao@scielo.org>", |
| 77 | +) |
| 78 | + |
| 79 | +# https://docs.djangoproject.com/en/dev/ref/settings/#server-email |
| 80 | +SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL) |
| 81 | + |
| 82 | +# https://docs.djangoproject.com/en/dev/ref/settings/#std-setting-EMAIL_HOST |
| 83 | +EMAIL_HOST = env.str("DJANGO_EMAIL_HOST", default="mailrelay.scielo.org") |
| 84 | + |
| 85 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-port |
| 86 | +EMAIL_PORT = env.int("DJANGO_EMAIL_PORT", default=25) |
| 87 | + |
| 88 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user |
| 89 | +EMAIL_HOST_USER = env.str("DJANGO_EMAIL_HOST_USER", default="suporte.aplicacao@scielo.org") |
| 90 | + |
| 91 | +# https://docs.djangoproject.com/en/dev/ref/settings/#std-setting-EMAIL_HOST_PASSWORD |
| 92 | +EMAIL_HOST_PASSWORD = env.str("DJANGO_EMAIL_HOST_PASSWORD", default="") |
| 93 | + |
| 94 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls |
| 95 | +EMAIL_USE_TLS = env.bool("DJANGO_EMAIL_USE_TLS", default=False) |
| 96 | + |
| 97 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-use-ssl |
| 98 | +EMAIL_USE_SSL = env.bool("DJANGO_EMAIL_USE_SSL", default=False) |
| 99 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix |
| 100 | +EMAIL_SUBJECT_PREFIX = env( |
| 101 | + "DJANGO_EMAIL_SUBJECT_PREFIX", |
| 102 | + default="[SciELO Content Manager ]", |
| 103 | +) |
| 104 | + |
| 105 | +# Anymail |
| 106 | +# ------------------------------------------------------------------------------ |
| 107 | +# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail |
| 108 | +INSTALLED_APPS += ["anymail"] # noqa F405 |
| 109 | +# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend |
| 110 | +# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference |
| 111 | +# https://anymail.readthedocs.io/en/stable/esps |
| 112 | +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" |
| 113 | +ANYMAIL = {} |
| 114 | + |
| 115 | +# django-compressor |
| 116 | +# ------------------------------------------------------------------------------ |
| 117 | +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED |
| 118 | +COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True) |
| 119 | +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE |
| 120 | +COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" |
| 121 | +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL |
| 122 | +COMPRESS_URL = STATIC_URL # noqa F405 |
| 123 | +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE |
| 124 | +COMPRESS_OFFLINE = True # Offline compression is required when using Whitenoise |
| 125 | +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_FILTERS |
| 126 | +COMPRESS_FILTERS = { |
| 127 | + "css": [ |
| 128 | + "compressor.filters.css_default.CssAbsoluteFilter", |
| 129 | + "compressor.filters.cssmin.rCSSMinFilter", |
| 130 | + ], |
| 131 | + "js": ["compressor.filters.jsmin.JSMinFilter"], |
| 132 | +} |
| 133 | + |
| 134 | +# LOGGING |
| 135 | +# ------------------------------------------------------------------------------ |
| 136 | +# https://docs.djangoproject.com/en/dev/ref/settings/#logging |
| 137 | +# See https://docs.djangoproject.com/en/dev/topics/logging for |
| 138 | +# more details on how to customize your logging configuration. |
| 139 | + |
| 140 | +LOGGING = { |
| 141 | + "version": 1, |
| 142 | + "disable_existing_loggers": True, |
| 143 | + "formatters": { |
| 144 | + "verbose": { |
| 145 | + "format": "%(levelname)s %(asctime)s %(module)s " |
| 146 | + "%(process)d %(thread)d %(message)s" |
| 147 | + } |
| 148 | + }, |
| 149 | + "handlers": { |
| 150 | + "console": { |
| 151 | + "level": "DEBUG", |
| 152 | + "class": "logging.StreamHandler", |
| 153 | + "formatter": "verbose", |
| 154 | + } |
| 155 | + }, |
| 156 | + "root": {"level": "INFO", "handlers": ["console"]}, |
| 157 | + "loggers": { |
| 158 | + "django.db.backends": { |
| 159 | + "level": "ERROR", |
| 160 | + "handlers": ["console"], |
| 161 | + "propagate": False, |
| 162 | + }, |
| 163 | + # Errors logged by the SDK itself |
| 164 | + "sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False}, |
| 165 | + "django.security.DisallowedHost": { |
| 166 | + "level": "ERROR", |
| 167 | + "handlers": ["console"], |
| 168 | + "propagate": False, |
| 169 | + }, |
| 170 | + }, |
| 171 | +} |
| 172 | + |
| 173 | +# Sentry |
| 174 | +# ------------------------------------------------------------------------------ |
| 175 | +SENTRY_DSN = env("SENTRY_DSN") |
| 176 | +SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO) |
| 177 | + |
| 178 | +sentry_logging = LoggingIntegration( |
| 179 | + level=SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs |
| 180 | + event_level=logging.ERROR, # Send errors as events |
| 181 | +) |
| 182 | +integrations = [ |
| 183 | + sentry_logging, |
| 184 | + DjangoIntegration(), |
| 185 | + CeleryIntegration(), |
| 186 | + RedisIntegration(), |
| 187 | +] |
| 188 | +sentry_sdk.init( |
| 189 | + dsn=SENTRY_DSN, |
| 190 | + integrations=integrations, |
| 191 | + environment=env("SENTRY_ENVIRONMENT", default="production"), |
| 192 | + traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=1.0), |
| 193 | + enable_tracing=True, |
| 194 | +) |
| 195 | + |
| 196 | +# Your stuff... |
| 197 | +# ------------------------------------------------------------------------------ |
0 commit comments