summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-05 10:08:12 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-05 10:08:12 +0000
commit27091f146a0ebdbfe1ae7c5cd30de51515cfbebc (patch)
treef32ff280c60ccaf599c2ef053dd5c464e53e3854 /synapse/storage
parentImpl push_bulk function (diff)
downloadsynapse-27091f146a0ebdbfe1ae7c5cd30de51515cfbebc.tar.xz
Add hs_token column and generate a different token f.e application service.
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/appservice.py17
-rw-r--r--synapse/storage/schema/application_services.sql1
2 files changed, 13 insertions, 5 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index b64416de28..3c8bf9ad0d 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -60,6 +60,7 @@ class ApplicationServiceStore(SQLBaseStore):
             if service.token == token:
                 service.url = None
                 service.namespaces = None
+                service.hs_token = None
 
     def _unregister_app_service_txn(self, txn, token):
         # kill the url to prevent pushes
@@ -100,6 +101,9 @@ class ApplicationServiceStore(SQLBaseStore):
         if not service.token or not service.url:
             raise StoreError(400, "Token and url must be specified.")
 
+        if not service.hs_token:
+            raise StoreError(500, "No HS token")
+
         yield self.runInteraction(
             "update_app_service",
             self._update_app_service_txn,
@@ -126,8 +130,8 @@ class ApplicationServiceStore(SQLBaseStore):
             return False
 
         txn.execute(
-            "UPDATE application_services SET url=? WHERE id=?",
-            (service.url, as_id,)
+            "UPDATE application_services SET url=?, hs_token=? WHERE id=?",
+            (service.url, service.hs_token, as_id,)
         )
         # cleanup regex
         txn.execute(
@@ -196,6 +200,7 @@ class ApplicationServiceStore(SQLBaseStore):
         #     'namespace': enum,
         #     'as_id': 0,
         #     'token': "something",
+        #     'hs_token': "otherthing",
         #     'id': 0
         #   }
         # ]
@@ -208,6 +213,7 @@ class ApplicationServiceStore(SQLBaseStore):
                 services[as_token] = {
                     "url": res["url"],
                     "token": as_token,
+                    "hs_token": res["hs_token"],
                     "namespaces": {
                         ApplicationService.NS_USERS: [],
                         ApplicationService.NS_ALIASES: [],
@@ -230,8 +236,9 @@ class ApplicationServiceStore(SQLBaseStore):
         for service in services.values():
             logger.info("Found application service: %s", service)
             self.cache.services.append(ApplicationService(
-                service["token"],
-                service["url"],
-                service["namespaces"]
+                token=service["token"],
+                url=service["url"],
+                namespaces=service["namespaces"],
+                hs_token=service["hs_token"]
             ))
 
diff --git a/synapse/storage/schema/application_services.sql b/synapse/storage/schema/application_services.sql
index 6d245fc807..03b5a10c8a 100644
--- a/synapse/storage/schema/application_services.sql
+++ b/synapse/storage/schema/application_services.sql
@@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS application_services(
     id INTEGER PRIMARY KEY AUTOINCREMENT,
     url TEXT,
     token TEXT,
+    hs_token TEXT,
     UNIQUE(token) ON CONFLICT ROLLBACK
 );