From 1d9455f6398527bdee1375c63a8570dfa74104f6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 12 Jul 2018 22:59:17 +0300 Subject: [PATCH] Allow specifying address and listen host/port separately. Fixes #160 --- example-config.yaml | 9 ++++----- mautrix_telegram/config.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 0c88b987..82042e2d 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -11,12 +11,11 @@ homeserver: # Application service host/registration related details # Changing these values requires regeneration of the registration. appservice: - # The protocol the homeserver should use when connecting to this appservice. - # Usually "http" or "https". - protocol: http + # The address that the homeserver can use to connect to this appservice. + address: http://localhost:8080 - # The hostname and port where the homeserver can find this appservice. - hostname: localhost + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 port: 8080 # The full URI to the database. diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 8c9f9410..8b90eabd 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -144,7 +144,12 @@ class Config(DictWithRecursion): copy("homeserver.verify_ssl") copy("homeserver.domain") - copy("appservice.protocol") + if "appservice.protocol" in self and "appservice.address" not in self: + protocol, hostname, port = (self["appservice.protocol"], self["appservice.hostname"], + self["appservice.port"]) + base["appservice.address"] = f"{protocol}://{hostname}:{port}" + else: + copy("appservice.address") copy("appservice.hostname") copy("appservice.port") @@ -257,10 +262,8 @@ class Config(DictWithRecursion): self.set("appservice.as_token", self._new_token()) self.set("appservice.hs_token", self._new_token()) - url = (f"{self['appservice.protocol']}://" - f"{self['appservice.hostname']}:{self['appservice.port']}") self._registration = { - "id": self.get("appservice.id", "telegram"), + "id": self["appservice.id"] or "telegram", "as_token": self["appservice.as_token"], "hs_token": self["appservice.hs_token"], "namespaces": { @@ -273,7 +276,7 @@ class Config(DictWithRecursion): "regex": f"#{alias_format}:{homeserver}" }] }, - "url": url, + "url": self["appservice.address"], "sender_localpart": self["appservice.bot_username"], "rate_limited": False }