| """Application configuration via environment variables.""" |
|
|
| import os |
| from functools import lru_cache |
| from pydantic_settings import BaseSettings |
|
|
|
|
| class Settings(BaseSettings): |
| """All config comes from environment variables or .env file.""" |
|
|
| |
| app_name: str = "ISP Handbook Service" |
| app_version: str = "1.0.0" |
| debug: bool = False |
| port: int = 7860 |
|
|
| |
| handbook_general_endpoint: str = "" |
| university_handbook_endpoint: str = "" |
| api_base_url: str = "https://finsapdev.qhtestingserver.com" |
| general_sections_path: str = "/MODEL_APIS/handbook_general_sections.php" |
| university_sections_path: str = "/MODEL_APIS/university_handbook.php" |
|
|
| |
| images_dir: str = "./images" |
|
|
| |
| font_dir: str = "./fonts" |
|
|
| |
| cors_origins: str = "http://localhost:5173,http://127.0.0.1:5173,https://finsapdev.qhtestingserver.com" |
|
|
| |
| http_timeout: int = 25 |
|
|
| model_config = {"env_file": ".env", "env_file_encoding": "utf-8", "extra": "ignore"} |
|
|
| @property |
| def cors_origins_list(self) -> list[str]: |
| return [o.strip() for o in self.cors_origins.split(",") if o.strip()] |
|
|
| @property |
| def general_endpoint_url(self) -> str: |
| if self.handbook_general_endpoint: |
| return self.handbook_general_endpoint |
| return self.api_base_url.rstrip("/") + self.general_sections_path |
|
|
| @property |
| def university_endpoint_url(self) -> str: |
| if self.university_handbook_endpoint: |
| return self.university_handbook_endpoint |
| return self.api_base_url.rstrip("/") + self.university_sections_path |
|
|
|
|
| @lru_cache() |
| def get_settings() -> Settings: |
| return Settings() |
|
|