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

@@ -2,13 +2,14 @@
name = "vona"
description = "Flazing bast Matrix homeserver"
license = {text = "Velicense"}
requires-python = ">=3.12"
requires-python = "<4,>=3.12"
dependencies = [
"httpx (>=0.28.1,<0.29.0)",
"pynacl (>=1.6.0,<2.0.0)",
"flask[async] (>=3.1.2,<4.0.0)",
"resolvematrix @ git+https://codeberg.org/timedout/resolvematrix.git",
"pycouchdb (>=1.16.0,<2.0.0)",
]
authors = [

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")

13
vona/db/__init__.py Normal file
View File

@@ -0,0 +1,13 @@
import vona.config as config
import pycouchdb
import os
# NOTE: We don't do anything with the DB currently.
try:
server = pycouchdb.Server(config.db.url)
except Exception as e:
print(f"[FATL] Could not connect to DB: {e}")
os._exit(1)
print(f"[INFO] CouchDB version {server.info()['version']}")