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

Unify v1 and v2 REST client APIs #5226

Merged
merged 28 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1531476
port everything to use r0
hawkowl May 21, 2019
87adbc4
fix
hawkowl May 21, 2019
622122e
fixes
hawkowl May 22, 2019
54d20a6
fixes
hawkowl May 22, 2019
44f3aae
fixes
hawkowl May 22, 2019
169be22
fixes
hawkowl May 22, 2019
d91e084
fixes
hawkowl May 22, 2019
63fe8d7
fixes
hawkowl May 22, 2019
d8afa71
Merge remote-tracking branch 'origin/develop' into hawkowl/burn-v2
hawkowl May 27, 2019
33075f6
fix 500
hawkowl May 27, 2019
34e0a18
fix 500
hawkowl May 27, 2019
fe089c9
fix 500
hawkowl May 27, 2019
bf1da35
make it point to the r0 url
hawkowl May 27, 2019
5eaff91
this is supposed to be r0 as well
hawkowl May 27, 2019
02c4420
fix missing var
hawkowl May 27, 2019
0c046bc
add v1 url adding
hawkowl May 28, 2019
dac219b
update this copyright since this is original
hawkowl May 28, 2019
6247f77
fix
hawkowl May 28, 2019
76ee829
Update and rename 5226.removal to 5226.misc
hawkowl May 29, 2019
dc36d62
Merge branch 'develop' into hawkowl/burn-v2
hawkowl May 29, 2019
796f888
remove all code duplication
hawkowl May 30, 2019
7eadafe
Merge branch 'hawkowl/burn-v2' of ssh://github.com/matrix-org/synapse…
hawkowl May 30, 2019
f001507
Merge remote-tracking branch 'origin/develop' into hawkowl/burn-v2
hawkowl May 30, 2019
21e2627
Merge branch 'develop' into hawkowl/burn-v2
hawkowl May 31, 2019
12e4487
Update logout.py
hawkowl May 31, 2019
883c7f1
bump timeout duration
hawkowl Jun 3, 2019
a2a4f84
Merge branch 'hawkowl/burn-v2' of ssh://github.com/matrix-org/synapse…
hawkowl Jun 3, 2019
258dcba
Merge remote-tracking branch 'origin/develop' into hawkowl/burn-v2
hawkowl Jun 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5226.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The base classes for the v1 and v2_alpha REST APIs have been unified.
4 changes: 1 addition & 3 deletions scripts-dev/list_url_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def visit_Call(self, node):
else:
return

if name == "client_path_patterns":
PATTERNS_V1.append(node.args[0].s)
elif name == "client_v2_patterns":
if name == "client_patterns":
PATTERNS_V2.append(node.args[0].s)


Expand Down
11 changes: 5 additions & 6 deletions synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
from synapse.replication.slave.storage.devices import SlavedDeviceStore
from synapse.replication.slave.storage.registration import SlavedRegistrationStore
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.rest.client.v1.base import ClientV1RestServlet, client_path_patterns
from synapse.rest.client.v2_alpha._base import client_v2_patterns
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
Expand All @@ -49,11 +48,11 @@
logger = logging.getLogger("synapse.app.frontend_proxy")


class PresenceStatusStubServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/presence/(?P<user_id>[^/]*)/status")
class PresenceStatusStubServlet(RestServlet):
PATTERNS = client_patterns("/presence/(?P<user_id>[^/]*)/status")

def __init__(self, hs):
super(PresenceStatusStubServlet, self).__init__(hs)
super(PresenceStatusStubServlet, self).__init__()
self.http_client = hs.get_simple_http_client()
self.auth = hs.get_auth()
self.main_uri = hs.config.worker_main_http_uri
Expand Down Expand Up @@ -84,7 +83,7 @@ def on_PUT(self, request, user_id):


class KeyUploadServlet(RestServlet):
PATTERNS = client_v2_patterns("/keys/upload(/(?P<device_id>[^/]+))?$")
PATTERNS = client_patterns("/keys/upload(/(?P<device_id>[^/]+))?$")

def __init__(self, hs):
"""
Expand Down
65 changes: 0 additions & 65 deletions synapse/rest/client/v1/base.py

This file was deleted.

28 changes: 15 additions & 13 deletions synapse/rest/client/v1/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
from twisted.internet import defer

from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
from synapse.http.servlet import parse_json_object_from_request
from synapse.http.servlet import RestServlet, parse_json_object_from_request
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.types import RoomAlias

from .base import ClientV1RestServlet, client_path_patterns

logger = logging.getLogger(__name__)


Expand All @@ -33,13 +32,14 @@ def register_servlets(hs, http_server):
ClientAppserviceDirectoryListServer(hs).register(http_server)


class ClientDirectoryServer(ClientV1RestServlet):
PATTERNS = client_path_patterns("/directory/room/(?P<room_alias>[^/]*)$")
class ClientDirectoryServer(RestServlet):
PATTERNS = client_patterns("/directory/room/(?P<room_alias>[^/]*)$", v1=True)

def __init__(self, hs):
super(ClientDirectoryServer, self).__init__(hs)
super(ClientDirectoryServer, self).__init__()
self.store = hs.get_datastore()
self.handlers = hs.get_handlers()
self.auth = hs.get_auth()

@defer.inlineCallbacks
def on_GET(self, request, room_alias):
Expand Down Expand Up @@ -120,13 +120,14 @@ def on_DELETE(self, request, room_alias):
defer.returnValue((200, {}))


class ClientDirectoryListServer(ClientV1RestServlet):
PATTERNS = client_path_patterns("/directory/list/room/(?P<room_id>[^/]*)$")
class ClientDirectoryListServer(RestServlet):
PATTERNS = client_patterns("/directory/list/room/(?P<room_id>[^/]*)$", v1=True)

def __init__(self, hs):
super(ClientDirectoryListServer, self).__init__(hs)
super(ClientDirectoryListServer, self).__init__()
self.store = hs.get_datastore()
self.handlers = hs.get_handlers()
self.auth = hs.get_auth()

@defer.inlineCallbacks
def on_GET(self, request, room_id):
Expand Down Expand Up @@ -162,15 +163,16 @@ def on_DELETE(self, request, room_id):
defer.returnValue((200, {}))


class ClientAppserviceDirectoryListServer(ClientV1RestServlet):
PATTERNS = client_path_patterns(
"/directory/list/appservice/(?P<network_id>[^/]*)/(?P<room_id>[^/]*)$"
class ClientAppserviceDirectoryListServer(RestServlet):
PATTERNS = client_patterns(
"/directory/list/appservice/(?P<network_id>[^/]*)/(?P<room_id>[^/]*)$", v1=True
)

def __init__(self, hs):
super(ClientAppserviceDirectoryListServer, self).__init__(hs)
super(ClientAppserviceDirectoryListServer, self).__init__()
self.store = hs.get_datastore()
self.handlers = hs.get_handlers()
self.auth = hs.get_auth()

def on_PUT(self, request, network_id, room_id):
content = parse_json_object_from_request(request)
Expand Down
17 changes: 9 additions & 8 deletions synapse/rest/client/v1/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
from twisted.internet import defer

from synapse.api.errors import SynapseError
from synapse.http.servlet import RestServlet
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.streams.config import PaginationConfig

from .base import ClientV1RestServlet, client_path_patterns

logger = logging.getLogger(__name__)


class EventStreamRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/events$")
class EventStreamRestServlet(RestServlet):
PATTERNS = client_patterns("/events$", v1=True)

DEFAULT_LONGPOLL_TIME_MS = 30000

def __init__(self, hs):
super(EventStreamRestServlet, self).__init__(hs)
super(EventStreamRestServlet, self).__init__()
self.event_stream_handler = hs.get_event_stream_handler()
self.auth = hs.get_auth()

@defer.inlineCallbacks
def on_GET(self, request):
Expand Down Expand Up @@ -76,11 +77,11 @@ def on_OPTIONS(self, request):


# TODO: Unit test gets, with and without auth, with different kinds of events.
class EventRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/events/(?P<event_id>[^/]*)$")
class EventRestServlet(RestServlet):
PATTERNS = client_patterns("/events/(?P<event_id>[^/]*)$", v1=True)

def __init__(self, hs):
super(EventRestServlet, self).__init__(hs)
super(EventRestServlet, self).__init__()
self.clock = hs.get_clock()
self.event_handler = hs.get_event_handler()
self._event_serializer = hs.get_event_client_serializer()
Expand Down
12 changes: 6 additions & 6 deletions synapse/rest/client/v1/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

from twisted.internet import defer

from synapse.http.servlet import parse_boolean
from synapse.http.servlet import RestServlet, parse_boolean
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.streams.config import PaginationConfig

from .base import ClientV1RestServlet, client_path_patterns


# TODO: Needs unit testing
class InitialSyncRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/initialSync$")
class InitialSyncRestServlet(RestServlet):
PATTERNS = client_patterns("/initialSync$", v1=True)

def __init__(self, hs):
super(InitialSyncRestServlet, self).__init__(hs)
super(InitialSyncRestServlet, self).__init__()
self.initial_sync_handler = hs.get_initial_sync_handler()
self.auth = hs.get_auth()

@defer.inlineCallbacks
def on_GET(self, request):
Expand Down
22 changes: 11 additions & 11 deletions synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
parse_json_object_from_request,
parse_string,
)
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.rest.well_known import WellKnownBuilder
from synapse.types import UserID, map_username_to_mxid_localpart
from synapse.util.msisdn import phone_number_to_msisdn

from .base import ClientV1RestServlet, client_path_patterns

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -81,15 +80,16 @@ def login_id_thirdparty_from_phone(identifier):
}


class LoginRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/login$")
class LoginRestServlet(RestServlet):
PATTERNS = client_patterns("/login$", v1=True)
CAS_TYPE = "m.login.cas"
SSO_TYPE = "m.login.sso"
TOKEN_TYPE = "m.login.token"
JWT_TYPE = "m.login.jwt"

def __init__(self, hs):
super(LoginRestServlet, self).__init__(hs)
super(LoginRestServlet, self).__init__()
self.hs = hs
self.jwt_enabled = hs.config.jwt_enabled
self.jwt_secret = hs.config.jwt_secret
self.jwt_algorithm = hs.config.jwt_algorithm
Expand Down Expand Up @@ -371,7 +371,7 @@ def do_jwt_login(self, login_submission):


class CasRedirectServlet(RestServlet):
PATTERNS = client_path_patterns("/login/(cas|sso)/redirect")
PATTERNS = client_patterns("/login/(cas|sso)/redirect", v1=True)

def __init__(self, hs):
super(CasRedirectServlet, self).__init__()
Expand All @@ -394,27 +394,27 @@ def on_GET(self, request):
finish_request(request)


class CasTicketServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/login/cas/ticket")
class CasTicketServlet(RestServlet):
PATTERNS = client_patterns("/login/cas/ticket", v1=True)

def __init__(self, hs):
super(CasTicketServlet, self).__init__(hs)
super(CasTicketServlet, self).__init__()
self.cas_server_url = hs.config.cas_server_url
self.cas_service_url = hs.config.cas_service_url
self.cas_required_attributes = hs.config.cas_required_attributes
self._sso_auth_handler = SSOAuthHandler(hs)
self._http_client = hs.get_simple_http_client()

@defer.inlineCallbacks
def on_GET(self, request):
client_redirect_url = parse_string(request, "redirectUrl", required=True)
http_client = self.hs.get_simple_http_client()
uri = self.cas_server_url + "/proxyValidate"
args = {
"ticket": parse_string(request, "ticket", required=True),
"service": self.cas_service_url
}
try:
body = yield http_client.get_raw(uri, args)
body = yield self._http_client.get_raw(uri, args)
except PartialDownloadError as pde:
# Twisted raises this error if the connection is closed,
# even if that's being used old-http style to signal end-of-data
Expand Down
19 changes: 10 additions & 9 deletions synapse/rest/client/v1/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

from twisted.internet import defer

from .base import ClientV1RestServlet, client_path_patterns
from synapse.http.servlet import RestServlet
from synapse.rest.client.v2_alpha._base import client_patterns

logger = logging.getLogger(__name__)


class LogoutRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/logout$")
class LogoutRestServlet(RestServlet):
PATTERNS = client_patterns("/logout$", v1=True)

def __init__(self, hs):
super(LogoutRestServlet, self).__init__(hs)
self._auth = hs.get_auth()
super(LogoutRestServlet, self).__init__()
self.auth = hs.get_auth()
self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler()

Expand All @@ -41,7 +42,7 @@ def on_POST(self, request):
if requester.device_id is None:
# the acccess token wasn't associated with a device.
# Just delete the access token
access_token = self._auth.get_access_token_from_request(request)
access_token = self.auth.get_access_token_from_request(request)
yield self._auth_handler.delete_access_token(access_token)
else:
yield self._device_handler.delete_device(
Expand All @@ -50,11 +51,11 @@ def on_POST(self, request):
defer.returnValue((200, {}))


class LogoutAllRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/logout/all$")
class LogoutAllRestServlet(RestServlet):
PATTERNS = client_patterns("/logout/all$", v1=True)

def __init__(self, hs):
super(LogoutAllRestServlet, self).__init__(hs)
super(LogoutAllRestServlet, self).__init__()
self.auth = hs.get_auth()
self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler()
Expand Down
Loading