summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-03-31 13:48:03 +0100
committerKegan Dougal <kegan@matrix.org>2015-03-31 13:48:03 +0100
commitcf1fa59f4b72dbf5c9d735eaf051f1456721d91f (patch)
treed76997dacc5d16ddd8ffe64fae3c849b64e13988 /synapse/storage
parentPyflakes (diff)
downloadsynapse-cf1fa59f4b72dbf5c9d735eaf051f1456721d91f.tar.xz
Use a sender localpart instead of a user ID.
Form the user ID at runtime instead, This gives less room for error in AS
config files since they cannot specify the domain of another HS.
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/appservice.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index a8780eca1e..557e377ca5 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -21,6 +21,7 @@ from twisted.internet import defer
 from synapse.api.constants import Membership
 from synapse.appservice import ApplicationService, AppServiceTransaction
 from synapse.storage.roommember import RoomsForUser
+from synapse.types import UserID
 from ._base import SQLBaseStore
 
 
@@ -31,6 +32,7 @@ class ApplicationServiceStore(SQLBaseStore):
 
     def __init__(self, hs):
         super(ApplicationServiceStore, self).__init__(hs)
+        self.hostname = hs.hostname
         self.services_cache = []
         self._populate_appservice_cache(
             hs.config.app_service_config_files
@@ -200,11 +202,16 @@ class ApplicationServiceStore(SQLBaseStore):
         return service_list
 
     def _load_appservice(self, as_info):
-        required_string_fields = ["url", "as_token", "hs_token", "sender"]
+        required_string_fields = [
+            "url", "as_token", "hs_token", "sender_localpart"
+        ]
         for field in required_string_fields:
             if not isinstance(as_info.get(field), basestring):
                 raise KeyError("Required string field: '%s'", field)
 
+        user = UserID(as_info["sender_localpart"], self.hostname)
+        user_id = user.to_string()
+
         # namespace checks
         if not isinstance(as_info.get("namespaces"), dict):
             raise KeyError("Requires 'namespaces' object.")
@@ -231,7 +238,7 @@ class ApplicationServiceStore(SQLBaseStore):
             url=as_info["url"],
             namespaces=as_info["namespaces"],
             hs_token=as_info["hs_token"],
-            sender=as_info["sender"],
+            sender=user_id,
             id=as_info["as_token"]  # the token is the only unique thing here
         )