56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
ROOT_DIR = Path(__file__).resolve().parent.parent
|
|
CONFIG_DIR = ROOT_DIR / "config"
|
|
DATA_DIR = ROOT_DIR / "data"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
app_name: str = "sub-provider"
|
|
app_env: str = "prod"
|
|
host: str = "0.0.0.0"
|
|
port: int = 18080
|
|
log_level: str = "info"
|
|
|
|
public_path: str = Field(default="change-me-random-hash-path")
|
|
public_base_url: str | None = None
|
|
request_timeout_seconds: float = 20.0
|
|
cache_ttl_seconds: int = 900
|
|
bundle_cache_ttl_seconds: int = 600
|
|
max_proxy_name_length: int = 80
|
|
default_user_agent: str = "sub-provider/0.2"
|
|
database_url: str = Field(default=f"sqlite:///{(DATA_DIR / 'app.db').resolve().as_posix()}")
|
|
database_echo: bool = False
|
|
admin_token: str | None = None
|
|
admin_session_secret: str = "change-this-admin-session-secret"
|
|
admin_session_max_age: int = 86400
|
|
|
|
config_dir: Path = CONFIG_DIR
|
|
sources_file: Path = CONFIG_DIR / "sources.yaml"
|
|
app_config_file: Path = CONFIG_DIR / "app.yaml"
|
|
clients_file: Path = CONFIG_DIR / "clients.yaml"
|
|
regions_file: Path = CONFIG_DIR / "regions.yaml"
|
|
policy_groups_file: Path = CONFIG_DIR / "policy-groups.yaml"
|
|
rules_config_file: Path = CONFIG_DIR / "rules.yaml"
|
|
rules_dir: Path = CONFIG_DIR / "rules"
|
|
bundle_cache_dir: Path = ROOT_DIR / "output" / "bundle-cache"
|
|
fetch_cache_dir: Path = DATA_DIR / "fetch-cache"
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=ROOT_DIR / ".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_settings() -> Settings:
|
|
return Settings()
|