| 1 | """Application configuration. |
| 2 | |
| 3 | Most configuration is set via environment variables. |
| 4 | |
| 5 | For local development, use a .env file to set |
| 6 | environment variables. |
| 7 | """ |
| 8 | from pathlib import Path |
| 9 | |
| 10 | from dotenv import load_dotenv |
| 11 | from environs import Env |
| 12 | from loguru import logger |
| 13 | |
| 14 | # environs >= 14 stopped mutating os.environ from read_env() — values only land on the |
| 15 | # Env instance. Use python-dotenv to populate os.environ for the many os.environ.get() |
| 16 | # callsites across the app (notably _load_jwt_secret in app/auth/utils.py). |
| 17 | _DOTENV_PATH = Path(__file__).parent.parent / ".env" |
| 18 | load_dotenv(_DOTENV_PATH) |
| 19 | env = Env() |
| 20 | logger.info(f"Loading environment from {_DOTENV_PATH}") |
| 21 | |
| 22 | |
| 23 | basedir = Path().absolute() |
| 24 | db_path = str(basedir / "data" / "copilot.db") |
| 25 | |
| 26 | ENV = env.str("SECRET_KEY", default="production") |
| 27 | DEBUG = env.bool("FLASK_DEBUG", default=False) |
| 28 | SECRET_KEY = env.str("SECRET_KEY", "not-a-secret") |
| 29 | # SQLALCHEMY_DATABASE_URI = env.str("SQLALCHEMY_DATABASE_URI", f"sqlite:///{db_path}") |
| 30 | SQLALCHEMY_DATABASE_URI = env.str( |
| 31 | "SQLALCHEMY_DATABASE_URI", |
| 32 | f"sqlite+aiosqlite:///{db_path}", |
| 33 | ) |
| 34 | SQLALCHEMY_TRACK_MODIFICATIONS = env.bool( |
| 35 | "SQLALCHEMY_TRACK_MODIFICATIONS", |
| 36 | default=False, |
| 37 | ) |
| 38 | |
| 39 | # --------------------------------------------------------------------------- |
| 40 | # SOCFortress MDR forwarding |
| 41 | # --------------------------------------------------------------------------- |
| 42 | # When enabled, newly-created alerts for customers that have the "SOCFortress |
| 43 | # MDR" integration deployed are forwarded to the MDR server's |
| 44 | # POST /api/v1/alerts/copilot endpoint. The MDR server then tasks the collector |
| 45 | # to fetch the authoritative indexer document. One CoPilot stack maps to one |
| 46 | # MDR collector, so the collector UUID and MDR base URL are global env values. |
| 47 | MDR_ENABLED = env.bool("MDR_ENABLED", default=False) |
| 48 | MDR_SERVER_URL = env.str("MDR_SERVER_URL", default="https://mdr-server.socfortress.co") |
| 49 | MDR_COLLECTOR_UUID = env.str("MDR_COLLECTOR_UUID", default="") |