Merge rest servlets into the client json resource object
This commit is contained in:
parent
22f00a09dd
commit
7256def8e4
|
@ -37,6 +37,7 @@ from synapse.api.urls import (
|
||||||
from synapse.config.homeserver import HomeServerConfig
|
from synapse.config.homeserver import HomeServerConfig
|
||||||
from synapse.crypto import context_factory
|
from synapse.crypto import context_factory
|
||||||
from synapse.util.logcontext import LoggingContext
|
from synapse.util.logcontext import LoggingContext
|
||||||
|
from synapse.rest.client.v1 import ClientV1RestResource
|
||||||
|
|
||||||
from daemonize import Daemonize
|
from daemonize import Daemonize
|
||||||
import twisted.manhole.telnet
|
import twisted.manhole.telnet
|
||||||
|
@ -59,7 +60,7 @@ class SynapseHomeServer(HomeServer):
|
||||||
return MatrixFederationHttpClient(self)
|
return MatrixFederationHttpClient(self)
|
||||||
|
|
||||||
def build_resource_for_client(self):
|
def build_resource_for_client(self):
|
||||||
return JsonResource()
|
return ClientV1RestResource(self)
|
||||||
|
|
||||||
def build_resource_for_federation(self):
|
def build_resource_for_federation(self):
|
||||||
return JsonResource()
|
return JsonResource()
|
||||||
|
@ -224,8 +225,6 @@ def setup():
|
||||||
content_addr=config.content_addr,
|
content_addr=config.content_addr,
|
||||||
)
|
)
|
||||||
|
|
||||||
hs.register_servlets()
|
|
||||||
|
|
||||||
hs.create_resource_tree(
|
hs.create_resource_tree(
|
||||||
web_client=config.webclient,
|
web_client=config.webclient,
|
||||||
redirect_root_to_web_client=True,
|
redirect_root_to_web_client=True,
|
||||||
|
|
|
@ -19,22 +19,18 @@ from . import (
|
||||||
voip, admin,
|
voip, admin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from synapse.http.server import JsonResource
|
||||||
|
|
||||||
class RestServletFactory(object):
|
|
||||||
|
|
||||||
""" A factory for creating REST servlets.
|
class ClientV1RestResource(JsonResource):
|
||||||
|
"""A resource for version 1 of the matrix client API."""
|
||||||
These REST servlets represent the entire client-server REST API. Generally
|
|
||||||
speaking, they serve as wrappers around events and the handlers that
|
|
||||||
process them.
|
|
||||||
|
|
||||||
See synapse.events for information on synapse events.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
client_resource = hs.get_resource_for_client()
|
JsonResource.__init__(self)
|
||||||
|
self.register_servlets(self, hs)
|
||||||
|
|
||||||
# TODO(erikj): There *must* be a better way of doing this.
|
@staticmethod
|
||||||
|
def register_servlets(client_resource, hs):
|
||||||
room.register_servlets(hs, client_resource)
|
room.register_servlets(hs, client_resource)
|
||||||
events.register_servlets(hs, client_resource)
|
events.register_servlets(hs, client_resource)
|
||||||
register.register_servlets(hs, client_resource)
|
register.register_servlets(hs, client_resource)
|
||||||
|
|
|
@ -24,7 +24,6 @@ from synapse.events.utils import serialize_event
|
||||||
from synapse.notifier import Notifier
|
from synapse.notifier import Notifier
|
||||||
from synapse.api.auth import Auth
|
from synapse.api.auth import Auth
|
||||||
from synapse.handlers import Handlers
|
from synapse.handlers import Handlers
|
||||||
from synapse.rest.client.v1 import RestServletFactory
|
|
||||||
from synapse.state import StateHandler
|
from synapse.state import StateHandler
|
||||||
from synapse.storage import DataStore
|
from synapse.storage import DataStore
|
||||||
from synapse.types import UserID, RoomAlias, RoomID, EventID
|
from synapse.types import UserID, RoomAlias, RoomID, EventID
|
||||||
|
@ -203,9 +202,6 @@ class HomeServer(BaseHomeServer):
|
||||||
def build_auth(self):
|
def build_auth(self):
|
||||||
return Auth(self)
|
return Auth(self)
|
||||||
|
|
||||||
def build_rest_servlet_factory(self):
|
|
||||||
return RestServletFactory(self)
|
|
||||||
|
|
||||||
def build_state_handler(self):
|
def build_state_handler(self):
|
||||||
return StateHandler(self)
|
return StateHandler(self)
|
||||||
|
|
||||||
|
@ -229,9 +225,3 @@ class HomeServer(BaseHomeServer):
|
||||||
clock=self.get_clock(),
|
clock=self.get_clock(),
|
||||||
hostname=self.hostname,
|
hostname=self.hostname,
|
||||||
)
|
)
|
||||||
|
|
||||||
def register_servlets(self):
|
|
||||||
""" Register all servlets associated with this HomeServer.
|
|
||||||
"""
|
|
||||||
# Simply building the ServletFactory is sufficient to have it register
|
|
||||||
self.get_rest_servlet_factory()
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ from ....utils import MockHttpResource, MockKey
|
||||||
from synapse.api.constants import PresenceState
|
from synapse.api.constants import PresenceState
|
||||||
from synapse.handlers.presence import PresenceHandler
|
from synapse.handlers.presence import PresenceHandler
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
|
from synapse.rest.client.v1 import presence
|
||||||
|
from synapse.rest.client.v1 import events
|
||||||
|
|
||||||
|
|
||||||
OFFLINE = PresenceState.OFFLINE
|
OFFLINE = PresenceState.OFFLINE
|
||||||
|
@ -86,7 +88,7 @@ class PresenceStateTestCase(unittest.TestCase):
|
||||||
return defer.succeed([])
|
return defer.succeed([])
|
||||||
room_member_handler.get_rooms_for_user = get_rooms_for_user
|
room_member_handler.get_rooms_for_user = get_rooms_for_user
|
||||||
|
|
||||||
hs.register_servlets()
|
presence.register_servlets(hs, self.mock_resource)
|
||||||
|
|
||||||
self.u_apple = hs.parse_userid(myid)
|
self.u_apple = hs.parse_userid(myid)
|
||||||
|
|
||||||
|
@ -172,7 +174,7 @@ class PresenceListTestCase(unittest.TestCase):
|
||||||
|
|
||||||
hs.get_auth().get_user_by_token = _get_user_by_token
|
hs.get_auth().get_user_by_token = _get_user_by_token
|
||||||
|
|
||||||
hs.register_servlets()
|
presence.register_servlets(hs, self.mock_resource)
|
||||||
|
|
||||||
self.u_apple = hs.parse_userid("@apple:test")
|
self.u_apple = hs.parse_userid("@apple:test")
|
||||||
self.u_banana = hs.parse_userid("@banana:test")
|
self.u_banana = hs.parse_userid("@banana:test")
|
||||||
|
@ -283,7 +285,8 @@ class PresenceEventStreamTestCase(unittest.TestCase):
|
||||||
|
|
||||||
hs.get_auth().get_user_by_req = _get_user_by_req
|
hs.get_auth().get_user_by_req = _get_user_by_req
|
||||||
|
|
||||||
hs.register_servlets()
|
presence.register_servlets(hs, self.mock_resource)
|
||||||
|
events.register_servlets(hs, self.mock_resource)
|
||||||
|
|
||||||
hs.handlers.room_member_handler = Mock(spec=[])
|
hs.handlers.room_member_handler = Mock(spec=[])
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ from ....utils import MockHttpResource, MockKey
|
||||||
from synapse.api.errors import SynapseError, AuthError
|
from synapse.api.errors import SynapseError, AuthError
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
|
|
||||||
|
from synapse.rest.client.v1 import profile
|
||||||
|
|
||||||
myid = "@1234ABCD:test"
|
myid = "@1234ABCD:test"
|
||||||
PATH_PREFIX = "/_matrix/client/api/v1"
|
PATH_PREFIX = "/_matrix/client/api/v1"
|
||||||
|
|
||||||
|
@ -61,7 +63,7 @@ class ProfileTestCase(unittest.TestCase):
|
||||||
|
|
||||||
hs.get_handlers().profile_handler = self.mock_handler
|
hs.get_handlers().profile_handler = self.mock_handler
|
||||||
|
|
||||||
hs.register_servlets()
|
profile.register_servlets(hs, self.mock_resource)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_my_name(self):
|
def test_get_my_name(self):
|
||||||
|
|
Loading…
Reference in New Issue