import os import logging from dotenv import load_dotenv BASEDIR = os.path.abspath(os.path.dirname(__file__)) load_dotenv(os.path.join(BASEDIR, ".env")) class Config: """General configuration. Mostly loaded from environment via .env""" FLASK_ENV = None # # set in subclass SECRET_KEY = os.environ.get("SECRET_KEY") or "90e01e751977d4276a4c70d98564b425e" LOG_TO_STDOUT = os.environ.get("LOG_TO_STDOUT") LOG_LEVEL = getattr(logging, os.environ.get("LOG_LEVEL", "INFO"), "INFO") MAIL_SERVER = os.environ.get("MAIL_SERVER", "localhost") LANGUAGES = ["fr", "en"] # unused for now ADMIN_MAIL = os.environ.get("ADMIN_MAIL") ADMIN_LOGIN = os.environ.get("ADMIN_LOGIN") or "admin" ADMINS = [ADMIN_MAIL] ERR_MAIL = os.environ.get("ERR_MAIL") # Le "from" des mails émis. Attention: peut être remplacée par la préférence email_from_addr: MAIL_FROM = os.environ.get("MAIL_FROM") or ("no-reply@" + MAIL_SERVER) AUTOSCO_DIR = os.environ.get("AUTOSCO_DIR", "/opt/autosco") AUTOSCO_VAR_DIR = os.environ.get("AUTOSCO_VAR_DIR", "/opt/autosco-data") AUTOSCO_LOG_FILE = os.path.join(AUTOSCO_VAR_DIR, "log", "autosco.log") # evite confusion avec le log nginx scodoc_error.log: AUTOSCO_ERR_FILE = os.path.join(AUTOSCO_VAR_DIR, "log", "autosco_exc.log") # MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # Flask uploads (16Mo, en ligne avec nginx) # flask_json: JSON_ADD_STATUS = False JSON_USE_ENCODE_METHODS = True JSON_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" # "%Y-%m-%dT%H:%M:%S" # --- Lien avec API ScoDoc SCODOC_URL = os.environ.get("SCODOC_URL", "http://localhost:5000") SCODOC_LOGIN = os.environ.get("SCODOC_LOGIN", "autosco") SCODOC_PASSWORD = os.environ.get("SCODOC_PASSWORD") SCODOC_CHECK_CERTIFICATE = os.environ.get("SCODOC_CHECK_CERTIFICATE", True) API_TIMEOUT = 120 # 2 minutes API_URL = SCODOC_URL + "/ScoDoc/api" SCODOC_DEPT_ACRONYM = "ESPL" def __getitem__(self, k) -> str | int | None: return getattr(self, k) def get(self, k, default=None): return getattr(self, k, default=default) class ProdConfig(Config): "mode production, normalement derrière nginx/gunicorn" FLASK_ENV = "production" DEBUG = False TESTING = False PREFERRED_URL_SCHEME = "https" class DevConfig(Config): "mode développement" FLASK_ENV = "development" DEBUG = True TESTING = False SECRET_KEY = os.environ.get("DEV_SECRET_KEY") or "cc4fbec7d9a34eb69a7e3e710087d87a" class TestConfig(DevConfig): "Pour les tests unitaires" TESTING = True DEBUG = False SERVER_NAME = os.environ.get("AUTOSCO_TEST_SERVER_NAME") or "autotest.gr" SECRET_KEY = os.environ.get("TEST_SECRET_KEY") or "c8ecff5db1592c308f563ff30e0f6bbc" class TestAPIConfig(Config): "Pour les tests de l'API" FLASK_ENV = "test_api" TESTING = False DEBUG = True SECRET_KEY = os.environ.get("TEST_SECRET_KEY") or "d8ecff5db15946789Hhahbh88aja276" mode = os.environ.get("FLASK_ENV", "production") if mode == "production": RunningConfig = ProdConfig elif mode == "development": RunningConfig = DevConfig elif mode == "test": RunningConfig = TestConfig elif mode == "test_api": RunningConfig = TestAPIConfig