advent22/api/advent22_api/settings.py

59 lines
1.1 KiB
Python

from pydantic import BaseModel, BaseSettings
class DavSettings(BaseModel):
"""
Connection to a DAV server.
"""
protocol: str = "https"
host: str = "example.com"
username: str = "advent22_user"
password: str = "password"
path: str = "/remote.php/webdav"
prefix: str = "/advent22"
disable_check: bool = False
retries: int = 20
@property
def url(self) -> str:
"""
Combined DAV URL.
"""
return f"{self.protocol}://{self.host}{self.path}{self.prefix}"
class Settings(BaseSettings):
"""
Per-run settings.
"""
#####
# general settings
#####
production_mode: bool = False
#####
# openapi settings
#####
openapi_url: str = "/openapi.json"
docs_url: str | None = None if production_mode else "/docs"
redoc_url: str | None = None if production_mode else "/redoc"
#####
# webdav settings
#####
webdav: DavSettings = DavSettings()
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
env_nested_delimiter = "__"
SETTINGS = Settings()