summary refs log tree commit diff
path: root/synapse/handlers/e2e_room_keys.py
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-02-06 17:57:10 -0500
committerHubert Chathi <hubert@uhoreg.ca>2019-02-06 17:57:10 -0500
commit82486371738a130322f3a1829bc4b49f79c1a3e4 (patch)
tree58bd97eb0df9acc2c23cd2b52dd706b11506ff58 /synapse/handlers/e2e_room_keys.py
parentreturn proper error codes for some 404s (diff)
downloadsynapse-82486371738a130322f3a1829bc4b49f79c1a3e4.tar.xz
add new endpoint to update backup versions
Diffstat (limited to 'synapse/handlers/e2e_room_keys.py')
-rw-r--r--synapse/handlers/e2e_room_keys.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/synapse/handlers/e2e_room_keys.py b/synapse/handlers/e2e_room_keys.py
index c5d7bf0c29..e0e5ece747 100644
--- a/synapse/handlers/e2e_room_keys.py
+++ b/synapse/handlers/e2e_room_keys.py
@@ -19,7 +19,8 @@ from six import iteritems
 
 from twisted.internet import defer
 
-from synapse.api.errors import NotFoundError, RoomKeysVersionError, StoreError
+from synapse.api.errors import Codes, NotFoundError, RoomKeysVersionError, \
+    StoreError, SynapseError
 from synapse.util.async_helpers import Linearizer
 
 logger = logging.getLogger(__name__)
@@ -307,3 +308,34 @@ class E2eRoomKeysHandler(object):
                     raise NotFoundError("Unknown backup version")
                 else:
                     raise
+
+    @defer.inlineCallbacks
+    def update_version(self, user_id, version, version_info):
+        """Update the info about a given version of the user's backup
+
+        Args:
+            user_id(str): the user whose current backup version we're updating
+            version(str): the backup version we're updating
+            version_info(dict): the new information about the backup
+        Raises:
+            NotFoundError: if the requested backup version doesn't exist
+        Returns:
+            A deferred of an empty dict.
+        """
+        try:
+            old_info = yield self.store.get_e2e_room_keys_version_info(user_id, version)
+        except StoreError as e:
+            if e.code == 404:
+                raise NotFoundError("Unknown backup version")
+            else:
+                raise
+        if old_info["algorithm"] != version_info["algorithm"]:
+            raise SynapseError(
+                400,
+                "Algorithm does not match",
+                Codes.INVALID_PARAM
+            )
+
+        yield self.store.update_e2e_room_keys_version(user_id, version, version_info)
+
+        defer.returnValue({})