This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import os
|
||||
from typing import Annotated
|
||||
import logging
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_yaml import parse_yaml_file_as
|
||||
from fastapi import Depends
|
||||
|
||||
|
||||
@@ -23,19 +26,21 @@ class _Config(BaseModel):
|
||||
component: _ComponentConfig
|
||||
|
||||
|
||||
log = logging.getLogger("config")
|
||||
|
||||
|
||||
def load_config() -> _Config:
|
||||
"""
|
||||
Load the application config
|
||||
"""
|
||||
# TODO: Actually load it
|
||||
return _Config(
|
||||
database="sqlite:///db.sqlite3",
|
||||
component=_ComponentConfig(
|
||||
jid="test.localhost",
|
||||
server="localhost:5869",
|
||||
secret="abc123",
|
||||
),
|
||||
)
|
||||
|
||||
config_path = "/etc/xmpp-api/config.yaml"
|
||||
if (env_config_file := os.environ.get("XMPP_API__CONFIG_FILE")) is not None:
|
||||
config_path = env_config_file
|
||||
|
||||
log.info(f"Reading configuration from {config_path}")
|
||||
with open(config_path, "r", encoding="utf8") as f:
|
||||
return parse_yaml_file_as(_Config, f)
|
||||
|
||||
|
||||
ConfigDep = Annotated[_Config, Depends(load_config)]
|
||||
|
||||
Reference in New Issue
Block a user