Move lookup endpoint to CS API (and s/is_server/id_server/)

pull/5115/head
Brendan Abolivier 2019-04-30 14:36:35 +01:00
parent 15b7a84aa8
commit 8df16a8aee
7 changed files with 32 additions and 115 deletions

View File

@ -33,7 +33,6 @@ CONTENT_REPO_PREFIX = "/_matrix/content"
SERVER_KEY_V2_PREFIX = "/_matrix/key/v2"
MEDIA_PREFIX = "/_matrix/media/r0"
LEGACY_MEDIA_PREFIX = "/_matrix/media/v1"
IDENTITY_PREFIX = "/_matrix/identity/api/v1"
class ConsentURIBuilder(object):

View File

@ -40,7 +40,6 @@ from synapse import events
from synapse.api.urls import (
CONTENT_REPO_PREFIX,
FEDERATION_PREFIX,
IDENTITY_PREFIX,
LEGACY_MEDIA_PREFIX,
MEDIA_PREFIX,
SERVER_KEY_V2_PREFIX,
@ -63,7 +62,6 @@ from synapse.python_dependencies import check_requirements
from synapse.replication.http import REPLICATION_PREFIX, ReplicationRestResource
from synapse.replication.tcp.resource import ReplicationStreamProtocolFactory
from synapse.rest import ClientRestResource
from synapse.rest.identity.v1 import IdentityApiV1Resource
from synapse.rest.key.v2 import KeyApiV2Resource
from synapse.rest.media.v0.content_repository import ContentRepoResource
from synapse.rest.well_known import WellKnownResource
@ -229,9 +227,6 @@ class SynapseHomeServer(HomeServer):
"'media' resource conflicts with enable_media_repo=False",
)
if name in ["identity"]:
resources[IDENTITY_PREFIX] = IdentityApiV1Resource(self)
if name in ["keys", "federation"]:
resources[SERVER_KEY_V2_PREFIX] = KeyApiV2Resource(self)

View File

@ -573,7 +573,6 @@ KNOWN_RESOURCES = (
'replication',
'static',
'webclient',
'identity',
)

View File

@ -480,6 +480,38 @@ class ThreepidDeleteRestServlet(RestServlet):
)
class ThreepidLookupRestServlet(RestServlet):
PATTERNS = client_v2_patterns("/account/3pid/lookup$")
def __init__(self, hs):
super(ThreepidLookupRestServlet, self).__init__()
self.config = hs.config
self.auth = hs.get_auth()
self.identity_handler = IdentityHandler(hs)
@defer.inlineCallbacks
def on_GET(self, request):
"""Proxy a /_matrix/identity/api/v1/lookup request to an identity
server
"""
yield self.auth.get_user_by_req(request)
# Extract query parameters
query_params = request.args
assert_params_in_dict(query_params, [b"medium", b"address", b"id_server"])
# Retrieve address and medium from the request parameters
medium = parse_string(request, "medium")
address = parse_string(request, "address")
id_server = parse_string(request, "id_server")
# Proxy the request to the identity server. lookup_3pid handles checking
# if the lookup is allowed so we don't need to do it here.
ret = yield self.identity_handler.lookup_3pid(id_server, medium, address)
respond_with_json(200, ret)
class WhoamiRestServlet(RestServlet):
PATTERNS = client_v2_patterns("/account/whoami$")

View File

@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2019 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View File

@ -1,24 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2019 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from twisted.web.resource import Resource
from .lookup import IdentityLookup
class IdentityApiV1Resource(Resource):
def __init__(self, hs):
Resource.__init__(self)
self.putChild(b"lookup", IdentityLookup(hs))

View File

@ -1,70 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2019 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from twisted.internet import defer
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET
from synapse.api.errors import SynapseError
from synapse.handlers.identity import IdentityHandler
from synapse.http.server import respond_with_json, wrap_json_request_handler
from synapse.http.servlet import assert_params_in_dict, parse_string
logger = logging.getLogger(__name__)
class IdentityLookup(Resource):
isLeaf = True
def __init__(self, hs):
self.config = hs.config
self.auth = hs.get_auth()
self.identity_handler = IdentityHandler(hs)
Resource.__init__(self)
def render_GET(self, request):
self.async_render_GET(request)
return NOT_DONE_YET
@wrap_json_request_handler
@defer.inlineCallbacks
def async_render_GET(self, request):
"""Proxy a /_matrix/identity/api/v1/lookup request to an identity
server
"""
yield self.auth.get_user_by_req(request, allow_guest=True)
if not self.config.enable_3pid_lookup:
raise SynapseError(
403,
"Looking up third-party identifiers is denied from this server"
)
# Extract query parameters
query_params = request.args
assert_params_in_dict(query_params, [b"medium", b"address", b"is_server"])
# Retrieve address and medium from the request parameters
medium = parse_string(request, "medium")
address = parse_string(request, "address")
is_server = parse_string(request, "is_server")
# Proxy the request to the identity server
ret = yield self.identity_handler.lookup_3pid(is_server, medium, address)
respond_with_json(request, 200, ret, send_cors=True)