From 42b2569a839637e45415048cd2877a20218d745e Mon Sep 17 00:00:00 2001 From: John Andersen Date: Wed, 25 Oct 2023 17:41:54 -0700 Subject: [PATCH] Pass bovine_db_url hackily via config.json to os.environ Signed-off-by: John Andersen --- docs/federation_activitypub.md | 14 ++++++++------ scitt_emulator/federation_activitypub_bovine.py | 9 +++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/federation_activitypub.md b/docs/federation_activitypub.md index 380f4feb..801c029f 100644 --- a/docs/federation_activitypub.md +++ b/docs/federation_activitypub.md @@ -125,11 +125,12 @@ Populate Bob's federation config ```json { "handle_name": "bob", + "fqdn": "scitt.bob.chadig.com", "workspace": "~/Documents/fediverse/scitt_federation_bob/", + "bovine_db_url": "~/Documents/fediverse/scitt_federation_bob/bovine.sqlite3", "following": { "alice": { - "actor_id": "alice@localhost:7000", - "domain": "http://localhost:7000" + "actor_id": "alice@scitt.alice.chadig.com", } } } @@ -140,7 +141,7 @@ Start the server ```console $ rm -rf workspace_bob/ $ mkdir -p workspace_bob/storage/operations -$ BOVINE_DB_URL="sqlite://${HOME}/Documents/fediverse/scitt_federation_bob/bovine.sqlite3" scitt-emulator server \ +$ scitt-emulator server \ --workspace ${HOME}/Documents/fediverse/scitt_federation_bob/workspace_bob/ --tree-alg CCF --port 6000 \ --middleware scitt_emulator.federation_activitypub_bovine:SCITTFederationActivityPubBovine \ --middleware-config-path ${HOME}/Documents/fediverse/scitt_federation_bob/config.json @@ -155,11 +156,12 @@ Populate Alice's federation config ```json { "handle_name": "alice", + "fqdn": "scitt.alice.chadig.com", "workspace": "~/Documents/fediverse/scitt_federation_alice/", + "bovine_db_url": "~/Documents/fediverse/scitt_federation_alice/bovine.sqlite3", "following": { "bob": { - "actor_id": "bob@localhost:6000", - "domain": "http://localhost:6000" + "actor_id": "bob@scitt.bob.chadig.com" } } } @@ -170,7 +172,7 @@ Start the server ```console $ rm -rf workspace_alice/ $ mkdir -p workspace_alice/storage/operations -$ BOVINE_DB_URL="sqlite://${HOME}/Documents/fediverse/scitt_federation_alice/bovine.sqlite3" scitt-emulator server \ +$ scitt-emulator server \ --workspace ${HOME}/Documents/fediverse/scitt_federation_alice/workspace_alice/ --tree-alg CCF --port 7000 \ --middleware scitt_emulator.federation_activitypub_bovine:SCITTFederationActivityPubBovine \ --middleware-config-path ${HOME}/Documents/fediverse/scitt_federation_alice/config.json diff --git a/scitt_emulator/federation_activitypub_bovine.py b/scitt_emulator/federation_activitypub_bovine.py index 52fa88a5..7911e1da 100644 --- a/scitt_emulator/federation_activitypub_bovine.py +++ b/scitt_emulator/federation_activitypub_bovine.py @@ -1,3 +1,4 @@ +import os import sys import json import types @@ -47,6 +48,14 @@ def __init__(self, app, signals, config_path): self.fqdn = self.config.get("fqdn", None) self.workspace = Path(self.config["workspace"]).expanduser() + self.bovine_db_url = self.config.get("bovine_db_url", None) + if self.bovine_db_url and self.bovine_db_url.startswith("~"): + self.bovine_db_url = str(Path(self.bovine_db_url).expanduser()) + # TODO Pass this as variable + if not "BOVINE_DB_URL" in os.environ and self.bovine_db_url: + os.environ["BOVINE_DB_URL"] = self.bovine_db_url + logging.debug(f"Set BOVINE_DB_URL to {self.bovine_db_url}") + BovinePubSub(app) BovineHerd(app)