ba-thesis/backend/config.py

42 lines
1.3 KiB
Python
Raw Normal View History

"""This module provides global application settings.
All settings are read from environment variables, but defaults are provided below
if the respective envvar is unset.
"""
2023-05-12 04:59:05 +02:00
import os
from urllib.parse import quote_plus as url_encode
from functools import lru_cache
from pydantic import BaseSettings, PostgresDsn
class Settings(BaseSettings):
"""Contains application-specific configuration values.
Reads the values from environment variables and falls back to default values
if the corresponding environment variable is unset.
"""
app_name: str = os.getenv("APP_NAME", "MEDWingS")
admin_email: str = os.getenv("ADMIN_EMAIL", "admin@example.com")
# Debug mode has the following effects:
# - logs SQL operations
2023-05-12 04:59:05 +02:00
debug_mode: bool = False
if os.getenv("DEBUG_MODE", "false").lower() == "true":
debug_mode = True
pg_hostname = os.getenv("POSTGRES_HOST", "db")
pg_port = os.getenv("POSTGRES_PORT", "5432")
pg_dbname = os.getenv("POSTGRES_DB", "medwings")
pg_user = url_encode(os.getenv("POSTGRES_USER", "medwings"))
pg_password = url_encode(os.getenv("POSTGRES_PASSWORD", "medwings"))
2023-05-12 04:59:05 +02:00
@lru_cache
def get_settings() -> Settings:
"""Creates the settings once and returns a cached version on subsequent requests."""
return Settings()