Add CouchDB stuffs
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
name = "vona"
|
name = "vona"
|
||||||
description = "Flazing bast Matrix homeserver"
|
description = "Flazing bast Matrix homeserver"
|
||||||
license = {text = "Velicense"}
|
license = {text = "Velicense"}
|
||||||
requires-python = ">=3.12"
|
requires-python = "<4,>=3.12"
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"httpx (>=0.28.1,<0.29.0)",
|
"httpx (>=0.28.1,<0.29.0)",
|
||||||
"pynacl (>=1.6.0,<2.0.0)",
|
"pynacl (>=1.6.0,<2.0.0)",
|
||||||
"flask[async] (>=3.1.2,<4.0.0)",
|
"flask[async] (>=3.1.2,<4.0.0)",
|
||||||
"resolvematrix @ git+https://codeberg.org/timedout/resolvematrix.git",
|
"resolvematrix @ git+https://codeberg.org/timedout/resolvematrix.git",
|
||||||
|
"pycouchdb (>=1.16.0,<2.0.0)",
|
||||||
]
|
]
|
||||||
|
|
||||||
authors = [
|
authors = [
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from types import SimpleNamespace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tomllib
|
import tomllib
|
||||||
import os
|
import os
|
||||||
@@ -13,6 +14,11 @@ server_name: str = ""
|
|||||||
signing_key: str = ""
|
signing_key: str = ""
|
||||||
support: dict = {"contacts": []}
|
support: dict = {"contacts": []}
|
||||||
|
|
||||||
|
db = SimpleNamespace(
|
||||||
|
name="vona",
|
||||||
|
url="",
|
||||||
|
)
|
||||||
|
|
||||||
_CONFIG_PATH = Path(os.getenv("VONA_CONFIG", "/etc/vona/config.toml"))
|
_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:
|
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:
|
if "address" in cfg:
|
||||||
addr = str(cfg["address"])
|
addr = str(cfg["address"])
|
||||||
@@ -111,10 +117,24 @@ def _apply_config(cfg: dict) -> None:
|
|||||||
else:
|
else:
|
||||||
_warn("No support contacts are defined")
|
_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"]
|
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")
|
print("[INFO] Configuration file was valid")
|
||||||
|
|
||||||
|
|||||||
13
vona/db/__init__.py
Normal file
13
vona/db/__init__.py
Normal 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']}")
|
||||||
Reference in New Issue
Block a user