Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
82486371
Commit
82486371
authored
6 years ago
by
Hubert Chathi
Browse files
Options
Downloads
Patches
Plain Diff
add new endpoint to update backup versions
parent
664c81e8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/e2e_room_keys.py
+33
-1
33 additions, 1 deletion
synapse/handlers/e2e_room_keys.py
synapse/rest/client/v2_alpha/room_keys.py
+33
-0
33 additions, 0 deletions
synapse/rest/client/v2_alpha/room_keys.py
synapse/storage/e2e_room_keys.py
+21
-0
21 additions, 0 deletions
synapse/storage/e2e_room_keys.py
with
87 additions
and
1 deletion
synapse/handlers/e2e_room_keys.py
+
33
−
1
View file @
82486371
...
...
@@ -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
({})
This diff is collapsed.
Click to expand it.
synapse/rest/client/v2_alpha/room_keys.py
+
33
−
0
View file @
82486371
...
...
@@ -380,6 +380,39 @@ class RoomKeysVersionServlet(RestServlet):
)
defer
.
returnValue
((
200
,
{}))
@defer.inlineCallbacks
def
on_PUT
(
self
,
request
,
version
):
"""
Update the information about a given version of the user
'
s room_keys backup.
POST /room_keys/version/12345 HTTP/1.1
Content-Type: application/json
{
"
algorithm
"
:
"
m.megolm_backup.v1
"
,
"
auth_data
"
: {
"
public_key
"
:
"
abcdefg
"
,
"
signatures
"
: {
"
ed25519:something
"
:
"
hijklmnop
"
}
}
}
HTTP/1.1 200 OK
Content-Type: application/json
{}
"""
requester
=
yield
self
.
auth
.
get_user_by_req
(
request
,
allow_guest
=
False
)
user_id
=
requester
.
user
.
to_string
()
info
=
parse_json_object_from_request
(
request
)
if
version
is
None
:
raise
SynapseError
(
400
,
"
No version specified to update
"
,
Codes
.
MISSING_PARAM
)
yield
self
.
e2e_room_keys_handler
.
update_version
(
user_id
,
version
,
info
)
defer
.
returnValue
((
200
,
{}))
def
register_servlets
(
hs
,
http_server
):
RoomKeysServlet
(
hs
).
register
(
http_server
)
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/e2e_room_keys.py
+
21
−
0
View file @
82486371
...
...
@@ -298,6 +298,27 @@ class EndToEndRoomKeyStore(SQLBaseStore):
"
create_e2e_room_keys_version_txn
"
,
_create_e2e_room_keys_version_txn
)
def
update_e2e_room_keys_version
(
self
,
user_id
,
version
,
info
):
"""
Update a given backup version
Args:
user_id(str): the user whose backup version we
'
re updating
version(str): the version ID of the backup version we
'
re updating
info(dict): the new backup version info to store
"""
return
self
.
_simple_update
(
table
=
"
e2e_room_keys_versions
"
,
keyvalues
=
{
"
user_id
"
:
user_id
,
"
version
"
:
version
,
},
updatevalues
=
{
"
auth_data
"
:
json
.
dumps
(
info
[
"
auth_data
"
]),
},
desc
=
"
update_e2e_room_keys_version
"
)
def
delete_e2e_room_keys_version
(
self
,
user_id
,
version
=
None
):
"""
Delete a given backup version of the user
'
s room keys.
Doesn
'
t delete their actual key data.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment