ovdashboard/api/ovdashboard_api/settings.py

56 lines
1.2 KiB
Python
Raw Normal View History

2022-08-28 23:59:57 +00:00
"""
Configuration definition.
Converts per-run (environment) variables and config files into the
"python world" using `pydantic`.
Pydantic models might have convenience methods attached.
"""
2022-08-29 00:36:13 +00:00
from typing import Optional
2022-08-28 23:59:57 +00:00
from pydantic import BaseSettings
class Settings(BaseSettings):
"""
Per-run settings
"""
production_mode: bool = False
api_v1_prefix: str = "api/v1"
openapi_url: str = "/openapi.json"
2022-08-29 00:36:13 +00:00
docs_url: Optional[str] = "/docs"
redoc_url: Optional[str] = "/redoc"
caldav_base_url: str = "/remote.php/dav"
2022-08-31 18:26:07 +00:00
webdav_base_url: str = "/remote.php/webdav/ovdashboard"
2022-08-29 00:36:13 +00:00
dav_protocol: str = "https"
dav_host: str = "example.com"
2022-08-31 18:26:07 +00:00
dav_username: str = "ovdashboard"
2022-08-29 00:36:13 +00:00
dav_password: str = "changeme"
2022-08-31 18:26:07 +00:00
dav_path: str = "ovdashboard"
2022-08-29 00:36:13 +00:00
2022-09-04 23:41:51 +00:00
cache_seconds: int = 30
2022-08-29 19:20:03 +00:00
2022-08-29 00:36:13 +00:00
@property
def caldav_url(self) -> str:
2022-09-05 12:54:02 +00:00
"""
Combined CalDAV URL.
"""
2022-08-29 00:36:13 +00:00
return f"{self.dav_protocol}://" + \
f"{self.dav_host}{self.caldav_base_url}"
2022-08-28 23:59:57 +00:00
@property
2022-08-29 00:36:13 +00:00
def webdav_url(self) -> str:
2022-09-05 12:54:02 +00:00
"""
Combined WebDAV URL.
"""
2022-08-29 00:36:13 +00:00
return f"{self.dav_protocol}://" + \
f"{self.dav_host}{self.webdav_base_url}"
2022-08-28 23:59:57 +00:00
2022-08-29 00:36:13 +00:00
SETTINGS = Settings(_env_file=".env")