Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5063 from matrix-org/erikj/move_endpoints
Browse files Browse the repository at this point in the history
Move some rest endpoints to client reader
  • Loading branch information
erikjohnston authored Apr 15, 2019
2 parents 6b0ddf8 + ec638a1 commit 6e27a86
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/5063.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for handling /verions, /voip and /push_rules client endpoints to client_reader worker.
6 changes: 6 additions & 0 deletions docs/workers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ following regular expressions::
^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
^/_matrix/client/(api/v1|r0|unstable)/keys/query$
^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
^/_matrix/client/versions$
^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$

Additionally, the following REST endpoints can be handled for GET requests::

^/_matrix/client/(api/v1|r0|unstable)/pushrules/.*$

Additionally, the following REST endpoints can be handled, but all requests must
be routed to the same instance::
Expand Down
11 changes: 7 additions & 4 deletions synapse/app/client_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@
from synapse.replication.slave.storage.transactions import SlavedTransactionStore
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.rest.client.v1.login import LoginRestServlet
from synapse.rest.client.v1.push_rule import PushRuleRestServlet
from synapse.rest.client.v1.room import (
JoinedRoomMemberListRestServlet,
PublicRoomListRestServlet,
RoomEventContextServlet,
RoomMemberListRestServlet,
RoomStateRestServlet,
)
from synapse.rest.client.v1.voip import VoipRestServlet
from synapse.rest.client.v2_alpha.account import ThreepidRestServlet
from synapse.rest.client.v2_alpha.keys import KeyChangesServlet, KeyQueryServlet
from synapse.rest.client.v2_alpha.register import RegisterRestServlet
from synapse.rest.client.versions import VersionsRestServlet
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
Expand Down Expand Up @@ -109,12 +112,12 @@ def _listen_http(self, listener_config):
ThreepidRestServlet(self).register(resource)
KeyQueryServlet(self).register(resource)
KeyChangesServlet(self).register(resource)
VoipRestServlet(self).register(resource)
PushRuleRestServlet(self).register(resource)
VersionsRestServlet(self).register(resource)

resources.update({
"/_matrix/client/r0": resource,
"/_matrix/client/unstable": resource,
"/_matrix/client/v2_alpha": resource,
"/_matrix/client/api/v1": resource,
"/_matrix/client": resource,
})

root_resource = create_resource_tree(resources, NoResource())
Expand Down
7 changes: 7 additions & 0 deletions synapse/rest/client/v1/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ def __init__(self, hs):
super(PushRuleRestServlet, self).__init__(hs)
self.store = hs.get_datastore()
self.notifier = hs.get_notifier()
self._is_worker = hs.config.worker_app is not None

@defer.inlineCallbacks
def on_PUT(self, request):
if self._is_worker:
raise Exception("Cannot handle PUT /push_rules on worker")

spec = _rule_spec_from_path([x.decode('utf8') for x in request.postpath])
try:
priority_class = _priority_class_from_spec(spec)
Expand Down Expand Up @@ -103,6 +107,9 @@ def on_PUT(self, request):

@defer.inlineCallbacks
def on_DELETE(self, request):
if self._is_worker:
raise Exception("Cannot handle DELETE /push_rules on worker")

spec = _rule_spec_from_path([x.decode('utf8') for x in request.postpath])

requester = yield self.auth.get_user_by_req(request)
Expand Down

0 comments on commit 6e27a86

Please sign in to comment.