advent22/api/advent22_api/core/config.py

58 lines
1 KiB
Python
Raw Normal View History

import tomllib
2022-11-04 18:49:31 +00:00
from pydantic import BaseModel
from .settings import SETTINGS
from .webdav import WebDAV
2022-11-04 18:49:31 +00:00
2022-11-15 22:17:32 +00:00
class User(BaseModel):
name: str
password: str
2023-09-08 00:56:14 +00:00
class Server(BaseModel):
# Dateiname Schriftart
font: str
2023-09-07 16:44:44 +00:00
2023-09-14 23:38:35 +00:00
# Tag, an dem der Kalender startet
# TODO penner
2023-09-20 16:14:58 +00:00
begin_day: int = 1
2023-09-14 23:38:35 +00:00
# Monat, in dem der Kalender startet
2023-09-08 10:23:43 +00:00
# TODO penner
2023-09-20 16:14:58 +00:00
begin_month: int = 12
2023-09-07 16:44:44 +00:00
2023-09-20 16:14:58 +00:00
# Kalender so viele Tage nach der letzten Türöffnung schließen
2023-09-08 10:23:43 +00:00
# TODO penner
2023-09-20 16:14:58 +00:00
close_after: int = 90
2023-09-07 19:34:11 +00:00
class Puzzle(BaseModel):
2023-09-12 20:45:57 +00:00
# Titel
title: str
2023-09-07 21:05:00 +00:00
# Lösungswort
2023-09-07 19:34:11 +00:00
solution: str
2023-09-07 16:44:44 +00:00
2023-09-08 00:56:14 +00:00
# Kalenderdefinition
calendar: str = "default.toml"
2023-09-07 21:05:00 +00:00
2023-09-08 00:56:14 +00:00
# Serverseitiger zusätzlicher "random" seed
random_seed: str = ""
2023-09-07 21:05:00 +00:00
2023-09-07 16:44:44 +00:00
2022-11-04 18:49:31 +00:00
class Config(BaseModel):
2022-11-15 22:17:32 +00:00
admin: User
2023-09-08 00:56:14 +00:00
server: Server
2022-11-18 01:39:05 +00:00
puzzle: Puzzle
2023-09-14 23:38:35 +00:00
async def get_config() -> Config:
"""
Globale Konfiguration lesen
"""
2023-09-10 02:59:57 +00:00
txt = await WebDAV.read_str(path=SETTINGS.webdav.config_filename)
return Config.model_validate(tomllib.loads(txt))