41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
from functools import lru_cache
|
|
from typing import Literal
|
|
|
|
from pydantic import Field, field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore", populate_by_name=True)
|
|
|
|
hermes_bin: str = Field(default="hermes", alias="HERMES_BIN")
|
|
hermes_home: str | None = Field(default=None, alias="HERMES_HOME")
|
|
default_board: str = Field(default="default", alias="HERMES_KANBAN_BOARD")
|
|
auth_mode: Literal["telegram", "none", "dev"] = Field(default="dev", alias="KANBAN_UI_AUTH_MODE")
|
|
telegram_bot_token: str | None = Field(default=None, alias="TELEGRAM_BOT_TOKEN")
|
|
telegram_allowed_user_ids: list[int] = Field(default_factory=list, alias="TELEGRAM_ALLOWED_USER_IDS")
|
|
allowed_origins: list[str] = Field(default_factory=lambda: ["http://localhost:5173"], alias="KANBAN_UI_ALLOWED_ORIGINS")
|
|
command_timeout_seconds: int = Field(default=30, alias="KANBAN_UI_COMMAND_TIMEOUT_SECONDS")
|
|
|
|
@field_validator("telegram_allowed_user_ids", mode="before")
|
|
@classmethod
|
|
def parse_user_ids(cls, value):
|
|
if value is None or value == "":
|
|
return []
|
|
if isinstance(value, str):
|
|
return [int(part.strip()) for part in value.split(",") if part.strip()]
|
|
return value
|
|
|
|
@field_validator("allowed_origins", mode="before")
|
|
@classmethod
|
|
def parse_origins(cls, value):
|
|
if value is None or value == "":
|
|
return []
|
|
if isinstance(value, str):
|
|
return [part.strip() for part in value.split(",") if part.strip()]
|
|
return value
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|