base: Allow loading the password from a secret file

This commit is contained in:
PapaTutuWawa 2021-11-24 14:19:35 +01:00
parent e1b14bcf5a
commit 99f5f740e9

View File

@ -41,10 +41,18 @@ class MiraBot:
self._config = toml.load(config_path) self._config = toml.load(config_path)
self._jid = aioxmpp.JID.fromstr(self._config["jid"]) self._jid = aioxmpp.JID.fromstr(self._config["jid"])
self._password = self._config["password"]
self._avatar = self._config.get("avatar", None) self._avatar = self._config.get("avatar", None)
self._client = None self._client = None
# Also supports situations where the secret cannot be in the config file
if "password" in self._config:
self._password = self._config["password"]
else if "password_file" in self._config:
with open(self._config["password_file"], "r") as f:
self._password = f.read()
else:
raise Exception("Neither password nor password_file specified")
self._modules = {} # Module name -> module self._modules = {} # Module name -> module
self._storage_manager = StorageManager.get_instance( self._storage_manager = StorageManager.get_instance(
self._config.get("storage_path", "/etc/mira/storage.json") self._config.get("storage_path", "/etc/mira/storage.json")