66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""Environment driven configuration values."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from .utils import normalize_recipients
|
|
|
|
load_dotenv()
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
SECRET_KEY = os.getenv("FLASK_SECRET_KEY", "dev")
|
|
SENTRY_DSN = os.getenv("SENTRY_DSN")
|
|
SENTRY_TRACES_SAMPLE_RATE = float(
|
|
os.getenv("SENTRY_TRACES_SAMPLE_RATE", "0.0"))
|
|
ENABLE_REQUEST_LOGS = os.getenv("ENABLE_REQUEST_LOGS", "true").lower() in {
|
|
"1", "true", "yes"}
|
|
ENABLE_JSON_LOGS = os.getenv("ENABLE_JSON_LOGS", "false").lower() in {
|
|
"1", "true", "yes"}
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL")
|
|
POSTGRES_URL = os.getenv("POSTGRES_URL")
|
|
|
|
|
|
def resolve_sqlite_path() -> Path:
|
|
"""Resolve the configured SQLite path honoring DATABASE_URL."""
|
|
if DATABASE_URL:
|
|
if DATABASE_URL.startswith("sqlite:"):
|
|
match = re.match(r"sqlite:(?:////?|)(.+)", DATABASE_URL)
|
|
if match:
|
|
return Path(match.group(1))
|
|
return Path("data/forms.db")
|
|
return Path(DATABASE_URL)
|
|
return BASE_DIR / "data" / "forms.db"
|
|
|
|
|
|
SQLITE_DB_PATH = resolve_sqlite_path()
|
|
|
|
RATE_LIMIT_MAX = int(os.getenv("RATE_LIMIT_MAX", "10"))
|
|
RATE_LIMIT_WINDOW = int(os.getenv("RATE_LIMIT_WINDOW", "60"))
|
|
REDIS_URL = os.getenv("REDIS_URL")
|
|
|
|
STRICT_ORIGIN_CHECK = os.getenv("STRICT_ORIGIN_CHECK", "false").lower() in {
|
|
"1", "true", "yes"}
|
|
ALLOWED_ORIGIN = os.getenv("ALLOWED_ORIGIN")
|
|
|
|
SMTP_SETTINGS = {
|
|
"host": os.getenv("SMTP_HOST"),
|
|
"port": int(os.getenv("SMTP_PORT", "587")),
|
|
"username": os.getenv("SMTP_USERNAME"),
|
|
"password": os.getenv("SMTP_PASSWORD"),
|
|
"sender": os.getenv("SMTP_SENDER"),
|
|
"use_tls": os.getenv("SMTP_USE_TLS", "true").lower() in {"1", "true", "yes"},
|
|
"recipients": normalize_recipients(os.getenv("SMTP_RECIPIENTS")),
|
|
}
|
|
|
|
if not SMTP_SETTINGS["sender"] and SMTP_SETTINGS["username"]:
|
|
SMTP_SETTINGS["sender"] = SMTP_SETTINGS["username"]
|
|
|
|
ADMIN_USERNAME = os.getenv("ADMIN_USERNAME", "admin")
|
|
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "admin")
|