From eaa564a9302557abb7178905817badd72a48b580 Mon Sep 17 00:00:00 2001 From: Binesh Bannerjee Date: Sat, 25 Jan 2025 17:56:49 -0500 Subject: [PATCH 1/3] Allow the pickle_key to be configured via the config file. --- maubot/__main__.py | 2 ++ maubot/client.py | 2 +- maubot/config.py | 1 + maubot/example-config.yaml | 1 + maubot/standalone/__main__.py | 2 +- maubot/standalone/config.py | 1 + maubot/standalone/example-config.yaml | 1 + 7 files changed, 8 insertions(+), 2 deletions(-) diff --git a/maubot/__main__.py b/maubot/__main__.py index c4cba44..57b89a2 100644 --- a/maubot/__main__.py +++ b/maubot/__main__.py @@ -43,6 +43,7 @@ class Maubot(Program): server: MaubotServer db: Database crypto_db: Database | None + crypto_db_pickle_key: str = "mau.crypto" plugin_postgres_db: PostgresDatabase | None state_store: PgStateStore @@ -73,6 +74,7 @@ class Maubot(Program): ) def prepare_db(self) -> None: + self.crypto_db_pickle_key = self.config["crypto_db_pickle_key"] self.db = Database.create( self.config["database"], upgrade_table=upgrade_table, diff --git a/maubot/client.py b/maubot/client.py index bdb76fc..b841891 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -186,7 +186,7 @@ class Client(DBClient): def _prepare_crypto(self) -> None: self.crypto_store = PgCryptoStore( - account_id=self.id, pickle_key="mau.crypto", db=self.maubot.crypto_db + account_id=self.id, pickle_key=self.maubot.crypto_db_pickle_key, db=self.maubot.crypto_db ) self.crypto = OlmMachine( self.client, diff --git a/maubot/config.py b/maubot/config.py index b8e42de..1e16b46 100644 --- a/maubot/config.py +++ b/maubot/config.py @@ -43,6 +43,7 @@ class Config(BaseFileConfig): base["crypto_database"] = self["crypto_database.postgres_uri"] else: copy("crypto_database") + copy("crypto_db_pickle_key") copy("plugin_directories.upload") copy("plugin_directories.load") copy("plugin_directories.trash") diff --git a/maubot/example-config.yaml b/maubot/example-config.yaml index f21ac1e..e0a53c6 100644 --- a/maubot/example-config.yaml +++ b/maubot/example-config.yaml @@ -3,6 +3,7 @@ # SQLite: sqlite:filename.db # Postgres: postgresql://username:password@hostname/dbname database: sqlite:maubot.db +crypto_db_pickle_key: mau.crypto # Separate database URL for the crypto database. "default" means use the same database as above. crypto_database: default diff --git a/maubot/standalone/__main__.py b/maubot/standalone/__main__.py index c320af4..91a302f 100644 --- a/maubot/standalone/__main__.py +++ b/maubot/standalone/__main__.py @@ -147,7 +147,7 @@ if device_id and not OlmMachine: exc_info=crypto_import_error, ) elif device_id: - crypto_store = PgCryptoStore(account_id=user_id, pickle_key="mau.crypto", db=db) + crypto_store = PgCryptoStore(account_id=user_id, pickle_key=config["crypto_db_pickle_key"], db=db) state_store = PgCryptoStateStore(db) bot_config = None diff --git a/maubot/standalone/config.py b/maubot/standalone/config.py index f2c90a0..0eb2dbe 100644 --- a/maubot/standalone/config.py +++ b/maubot/standalone/config.py @@ -47,6 +47,7 @@ class Config(BaseFileConfig): copy("server.public_url") copy("database") copy("database_opts") + copy("crypto_db_pickle_key") if "plugin_config" in base: copy("plugin_config") copy("logging") diff --git a/maubot/standalone/example-config.yaml b/maubot/standalone/example-config.yaml index 8ee4e43..3f012b8 100644 --- a/maubot/standalone/example-config.yaml +++ b/maubot/standalone/example-config.yaml @@ -43,6 +43,7 @@ server: # The database for the plugin. Used for plugin data, the sync token and e2ee data (if enabled). # SQLite and Postgres are supported. database: sqlite:bot.db +crypto_db_pickle_key: mau.crypto # Additional arguments for asyncpg.create_pool() or sqlite3.connect() # https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool From 03747dba836dda3dbf1ecde23fe6b65734caae51 Mon Sep 17 00:00:00 2001 From: Binesh Bannerjee Date: Sat, 25 Jan 2025 18:09:20 -0500 Subject: [PATCH 2/3] Formatting woes. --- maubot/client.py | 4 +++- maubot/standalone/__main__.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/maubot/client.py b/maubot/client.py index b841891..83e5478 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -186,7 +186,9 @@ class Client(DBClient): def _prepare_crypto(self) -> None: self.crypto_store = PgCryptoStore( - account_id=self.id, pickle_key=self.maubot.crypto_db_pickle_key, db=self.maubot.crypto_db + account_id=self.id, + pickle_key=self.maubot.crypto_db_pickle_key, + db=self.maubot.crypto_db ) self.crypto = OlmMachine( self.client, diff --git a/maubot/standalone/__main__.py b/maubot/standalone/__main__.py index 91a302f..2c1ffce 100644 --- a/maubot/standalone/__main__.py +++ b/maubot/standalone/__main__.py @@ -147,7 +147,9 @@ if device_id and not OlmMachine: exc_info=crypto_import_error, ) elif device_id: - crypto_store = PgCryptoStore(account_id=user_id, pickle_key=config["crypto_db_pickle_key"], db=db) + crypto_store = PgCryptoStore( + account_id=user_id, pickle_key=config["crypto_db_pickle_key"], db=db + ) state_store = PgCryptoStateStore(db) bot_config = None From eaba3f03f4a54644ccfdca4a62abce0a9ba62030 Mon Sep 17 00:00:00 2001 From: Binesh Bannerjee Date: Sat, 25 Jan 2025 18:10:51 -0500 Subject: [PATCH 3/3] More formatting woes. --- maubot/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maubot/client.py b/maubot/client.py index 83e5478..bf0fe42 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -188,7 +188,7 @@ class Client(DBClient): self.crypto_store = PgCryptoStore( account_id=self.id, pickle_key=self.maubot.crypto_db_pickle_key, - db=self.maubot.crypto_db + db=self.maubot.crypto_db, ) self.crypto = OlmMachine( self.client,