mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
81 lines
1.5 KiB
Python
81 lines
1.5 KiB
Python
from typing import TypeVar
|
|
|
|
from pydantic import BaseModel
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class DavSettings(BaseModel):
|
|
"""
|
|
Connection to a DAV server.
|
|
"""
|
|
|
|
protocol: str = "https"
|
|
host: str = "example.com"
|
|
path: str = "/remote.php/webdav"
|
|
prefix: str = "/advent22"
|
|
|
|
username: str = "advent22_user"
|
|
password: str = "password"
|
|
|
|
cache_ttl: int = 60 * 30
|
|
config_filename: str = "config.toml"
|
|
|
|
@property
|
|
def url(self) -> str:
|
|
"""
|
|
Combined DAV URL.
|
|
"""
|
|
|
|
return f"{self.protocol}://{self.host}{self.path}{self.prefix}"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""
|
|
Per-run settings.
|
|
"""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
env_nested_delimiter="__",
|
|
)
|
|
|
|
#####
|
|
# general settings
|
|
#####
|
|
|
|
production_mode: bool = False
|
|
ui_directory: str = "/usr/local/share/advent22_ui/html"
|
|
|
|
#####
|
|
# openapi settings
|
|
#####
|
|
|
|
def __dev_value(self, value: T) -> T | None:
|
|
if self.production_mode:
|
|
return None
|
|
|
|
return value
|
|
|
|
@property
|
|
def openapi_url(self) -> str | None:
|
|
return self.__dev_value("/api/openapi.json")
|
|
|
|
@property
|
|
def docs_url(self) -> str | None:
|
|
return self.__dev_value("/api/docs")
|
|
|
|
@property
|
|
def redoc_url(self) -> str | None:
|
|
return self.__dev_value("/api/redoc")
|
|
|
|
#####
|
|
# webdav settings
|
|
#####
|
|
|
|
webdav: DavSettings = DavSettings()
|
|
|
|
|
|
SETTINGS = Settings()
|