|
| 1 | +import os |
| 2 | +from dotenv import load_dotenv |
| 3 | + |
| 4 | +# Charger les variables d'environnement |
| 5 | +load_dotenv() |
| 6 | + |
| 7 | + |
| 8 | +class Config: |
| 9 | + """Configuration centralisée de l'application""" |
| 10 | + |
| 11 | + # Configuration Zammad |
| 12 | + ZAMMAD_API_URL = os.getenv("ZAMMAD_API_URL", "") |
| 13 | + ZAMMAD_API_TOKEN = os.getenv("ZAMMAD_API_TOKEN", "") |
| 14 | + |
| 15 | + # Configuration authentification webhook |
| 16 | + WEBHOOK_USERNAME = os.getenv("WEBHOOK_USERNAME", "") |
| 17 | + WEBHOOK_PASSWORD = os.getenv("WEBHOOK_PASSWORD", "") |
| 18 | + |
| 19 | + # Configuration Flask |
| 20 | + DEBUG = os.getenv("FLASK_DEBUG", "False").lower() == "true" |
| 21 | + PORT = int(os.getenv("FLASK_PORT", "5000")) |
| 22 | + |
| 23 | + # Configuration Mails (correction et paramètres SMTP) |
| 24 | + MAIL_FROM = os.getenv("MAIL_FROM", "") |
| 25 | + SMTP_HOST = os.getenv("SMTP_HOST", "") |
| 26 | + SMTP_PORT = int(os.getenv("SMTP_PORT", "587")) |
| 27 | + SMTP_USERNAME = os.getenv("SMTP_USERNAME", "") |
| 28 | + SMTP_PASSWORD = os.getenv("SMTP_PASSWORD", "") |
| 29 | + SMTP_RECIPIENTS = os.getenv("SMTP_RECIPIENTS", "").split(",") |
| 30 | + SMTP_USE_TLS = os.getenv("SMTP_USE_TLS", "True").lower() == "true" |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def validate(cls): |
| 34 | + """Valide que toutes les configurations obligatoires sont présentes""" |
| 35 | + required_vars = [ |
| 36 | + ("ZAMMAD_API_URL", cls.ZAMMAD_API_URL), |
| 37 | + ("ZAMMAD_API_TOKEN", cls.ZAMMAD_API_TOKEN), |
| 38 | + ("WEBHOOK_USERNAME", cls.WEBHOOK_USERNAME), |
| 39 | + ("WEBHOOK_PASSWORD", cls.WEBHOOK_PASSWORD), |
| 40 | + ("MAIL_FROM", cls.MAIL_FROM), |
| 41 | + ("SMTP_HOST", cls.SMTP_HOST), |
| 42 | + ("SMTP_PORT", cls.SMTP_PORT), |
| 43 | + ("SMTP_USERNAME", cls.SMTP_USERNAME), |
| 44 | + ("SMTP_PASSWORD", cls.SMTP_PASSWORD), |
| 45 | + ("SMTP_RECIPIENTS", cls.SMTP_RECIPIENTS), |
| 46 | + ] |
| 47 | + |
| 48 | + missing_vars = [] |
| 49 | + for var_name, var_value in required_vars: |
| 50 | + if not var_value: |
| 51 | + missing_vars.append(var_name) |
| 52 | + |
| 53 | + if missing_vars: |
| 54 | + raise ValueError( |
| 55 | + f"Variables d'environnement manquantes: {', '.join(missing_vars)}" |
| 56 | + ) |
| 57 | + |
| 58 | + return True |
0 commit comments