Add CouchDB stuffs

This commit is contained in:
2025-10-26 05:34:17 -04:00
parent 32cdb239ff
commit 9d68082764
3 changed files with 38 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
from types import SimpleNamespace
from pathlib import Path
import tomllib
import os
@@ -13,6 +14,11 @@ server_name: str = ""
signing_key: str = ""
support: dict = {"contacts": []}
db = SimpleNamespace(
name="vona",
url="",
)
_CONFIG_PATH = Path(os.getenv("VONA_CONFIG", "/etc/vona/config.toml"))
@@ -57,7 +63,7 @@ def _validate_cat_path(cat_path: str) -> Path:
def _apply_config(cfg: dict) -> None:
global addr, port, server_name, signing_key, cat, support, users_can_register
global addr, port, server_name, signing_key, cat, support, users_can_register, db
if "address" in cfg:
addr = str(cfg["address"])
@@ -111,10 +117,24 @@ def _apply_config(cfg: dict) -> None:
else:
_warn("No support contacts are defined")
if "enable_registration" in cfg:
support = support_obj
if "enable_registration" in cfg and isinstance(cfg["enable_registration"], bool):
users_can_register = cfg["enable_registration"]
support = support_obj
if "db" in cfg and isinstance(cfg["db"], dict):
_db = cfg["db"]
if "url" in _db:
db.url = str(_db["url"])
else:
_fatal("No DB URL provided")
if "name" in _db:
db.name = str(_db["name"])
else:
_warn("No DB name provided, defaulting to `vona`")
else:
_fatal("NO DB provided")
print("[INFO] Configuration file was valid")