diff --git a/pyproject.toml b/pyproject.toml index 18a8c66..a8bb14b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/vona/config/__init__.py b/vona/config/__init__.py index 5ec5267..57d5326 100644 --- a/vona/config/__init__.py +++ b/vona/config/__init__.py @@ -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") diff --git a/vona/db/__init__.py b/vona/db/__init__.py new file mode 100644 index 0000000..7db46c3 --- /dev/null +++ b/vona/db/__init__.py @@ -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']}")