advent22/api/advent22_api/core/config.py
Jörn-Michael Miehe af00dafb6c router integration: stuck
apparently, a @staticmethod that Depends on another @staticmethod in the same class is bad
2023-09-08 19:08:13 +00:00

54 lines
1,004 B
Python

import tomllib
from pydantic import BaseModel
from .settings import SETTINGS
from .webdav import WebDAV
class User(BaseModel):
name: str
password: str
class Server(BaseModel):
# Dateiname Schriftart
font: str
# Monat, während dem der Kalender läuft
# TODO penner
month: int = 12
# Alle Türen bleiben noch so viele Monate offen
# TODO penner
keep_open: int = 3
class Puzzle(BaseModel):
# Lösungswort
solution: str
# Länge des Kalenders
# TODO penner
days: int = 24
# Kalenderdefinition
calendar: str = "default.toml"
# Serverseitiger zusätzlicher "random" seed
random_pepper: str = ""
class Config(BaseModel):
admin: User
server: Server
puzzle: Puzzle
@staticmethod
async def get_config() -> "Config":
"""
Globale Konfiguration lesen
"""
txt = await WebDAV.read_str(path=SETTINGS.config_filename)
return Config.model_validate(tomllib.loads(txt))