advent22/api/advent22_api/config.py

26 lines
444 B
Python
Raw Normal View History

2022-11-04 18:49:31 +00:00
import tomli
from pydantic import BaseModel
from .dav_common import dav_get_textfile_content
from .settings import SETTINGS
2022-11-15 22:17:32 +00:00
class User(BaseModel):
name: str
password: str
2022-11-18 01:39:05 +00:00
class Puzzle(BaseModel):
solution: str
2022-11-04 18:49:31 +00:00
class Config(BaseModel):
2022-11-15 22:17:32 +00:00
admin: User
2022-11-18 01:39:05 +00:00
puzzle: Puzzle
2022-11-04 18:49:31 +00:00
async def get_config() -> Config:
txt = await dav_get_textfile_content(path=SETTINGS.config_filename)
return Config.parse_obj(tomli.loads(txt))