54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import os
|
|
from typing import Optional
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
class Settings:
|
|
"""Configuration centralisée de l'application."""
|
|
|
|
def __init__(self):
|
|
load_dotenv()
|
|
|
|
@property
|
|
def SECRET_KEY(self) -> str:
|
|
key = os.environ.get('SECRET_KEY')
|
|
if not key:
|
|
raise ValueError("SECRET_KEY est obligatoire")
|
|
if len(key) < 32:
|
|
raise ValueError("SECRET_KEY doit faire au moins 32 caractères")
|
|
return key
|
|
|
|
@property
|
|
def DATABASE_URL(self) -> str:
|
|
return os.environ.get('DATABASE_URL', 'sqlite:///school_management.db')
|
|
|
|
@property
|
|
def DEBUG(self) -> bool:
|
|
return os.environ.get('DEBUG', 'false').lower() == 'true'
|
|
|
|
@property
|
|
def LOG_LEVEL(self) -> str:
|
|
return os.environ.get('LOG_LEVEL', 'INFO').upper()
|
|
|
|
@property
|
|
def FLASK_ENV(self) -> str:
|
|
return os.environ.get('FLASK_ENV', 'development')
|
|
|
|
@property
|
|
def DB_ECHO(self) -> bool:
|
|
return os.environ.get('DB_ECHO', 'false').lower() == 'true'
|
|
|
|
@property
|
|
def WTF_CSRF_TIME_LIMIT(self) -> int:
|
|
return int(os.environ.get('WTF_CSRF_TIME_LIMIT', '3600'))
|
|
|
|
def validate_config(self):
|
|
"""Valide la configuration complète."""
|
|
# Forcer l'évaluation de toutes les propriétés pour déclencher les validations
|
|
_ = self.SECRET_KEY
|
|
_ = self.DATABASE_URL
|
|
_ = self.DEBUG
|
|
|
|
|
|
# Instance globale
|
|
settings = Settings() |