GooDrive/backend/core/settings.py
2026-10-13 19:43:55 +02:00

64 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from datetime import timedelta
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = os.environ.get('DEBUG','false').lower() == 'true'
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '')
if (not SECRET_KEY or SECRET_KEY.startswith('REMPLACE_')) and not DEBUG and os.environ.get('USE_SQLITE') != '1':
raise RuntimeError('Définis un DJANGO_SECRET_KEY aléatoire dans les variables d’environnement.')
if not SECRET_KEY:
SECRET_KEY = 'dev-only-unsafe-secret-key-for-local-tests'
ALLOWED_HOSTS = [x.strip() for x in os.environ.get('ALLOWED_HOSTS','localhost,127.0.0.1').split(',') if x.strip()]
INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',
'rest_framework','rest_framework_simplejwt','drive',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware','whitenoise.middleware.WhiteNoiseMiddleware','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',
]
ROOT_URLCONF='core.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='core.wsgi.application'
if os.environ.get('USE_SQLITE')=='1':
DATABASES={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':BASE_DIR/'test.sqlite3'}}
else:
DATABASES={'default':{'ENGINE':'django.db.backends.mysql',
'NAME':os.environ.get('MYSQL_DATABASE','bocagedrive'),'USER':os.environ.get('MYSQL_USER','bocagedrive'),
'PASSWORD':os.environ.get('MYSQL_PASSWORD',''),'HOST':os.environ.get('MYSQL_HOST','db'),
'PORT':os.environ.get('MYSQL_PORT','3306'), 'OPTIONS':{'charset':'utf8mb4'}}}
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'},
]
LANGUAGE_CODE='fr-fr'; TIME_ZONE='Europe/Paris'; USE_TZ=True; USE_I18N=True
STATIC_URL='/static/'; STATIC_ROOT=BASE_DIR/'staticfiles'
STORAGES={'staticfiles':{'BACKEND':'whitenoise.storage.CompressedManifestStaticFilesStorage'}}
DEFAULT_AUTO_FIELD='django.db.models.BigAutoField'
REST_FRAMEWORK={
'DEFAULT_AUTHENTICATION_CLASSES':['rest_framework_simplejwt.authentication.JWTAuthentication'],
'DEFAULT_PERMISSION_CLASSES':['rest_framework.permissions.IsAuthenticated'],
'DEFAULT_THROTTLE_CLASSES':['rest_framework.throttling.AnonRateThrottle'],
'DEFAULT_THROTTLE_RATES':{'anon':'30/min'},
}
SIMPLE_JWT={'ACCESS_TOKEN_LIFETIME':timedelta(minutes=30),'REFRESH_TOKEN_LIFETIME':timedelta(days=7),
'AUTH_HEADER_TYPES':('Bearer',)}
DRIVE_STORAGE_ROOT=Path(os.environ.get('DRIVE_STORAGE_ROOT','/data/files')).resolve()
FILE_UPLOAD_TEMP_DIR=str(DRIVE_STORAGE_ROOT.parent/'tmp')
Path(FILE_UPLOAD_TEMP_DIR).mkdir(parents=True,exist_ok=True)
DRIVE_STORAGE_ROOT.mkdir(parents=True,exist_ok=True)
DATA_UPLOAD_MAX_MEMORY_SIZE=5*1024*1024 # limits form-field memory, not file payload
FILE_UPLOAD_MAX_MEMORY_SIZE=0 # force uploads to use disk streaming
DRIVE_MAX_FILE_SIZE=int(os.environ.get('DRIVE_MAX_FILE_SIZE_MB','10240'))*1024*1024
SECURE_CONTENT_TYPE_NOSNIFF=True
SESSION_COOKIE_HTTPONLY=True
CSRF_COOKIE_HTTPONLY=True
SECURE_PROXY_SSL_HEADER=('HTTP_X_FORWARDED_PROTO','https')