From 6554253f487f668e4b63b0ace7b7a170078d3045 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Apr 2018 19:28:12 +0100 Subject: [PATCH 1/2] Option to defer to an ID server for user_directory --- synapse/config/user_directory.py | 8 ++++++++ synapse/rest/client/v2_alpha/user_directory.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/synapse/config/user_directory.py b/synapse/config/user_directory.py index 38e894784..093ebc4d0 100644 --- a/synapse/config/user_directory.py +++ b/synapse/config/user_directory.py @@ -23,11 +23,15 @@ class UserDirectoryConfig(Config): def read_config(self, config): self.user_directory_search_all_users = False + self.user_directory_defer_to_id_server = None user_directory_config = config.get("user_directory", None) if user_directory_config: self.user_directory_search_all_users = ( user_directory_config.get("search_all_users", False) ) + self.user_directory_defer_to_id_server = ( + user_directory_config.get("defer_to_id_server", None) + ) def default_config(self, config_dir_path, server_name, **kwargs): return """ @@ -41,4 +45,8 @@ class UserDirectoryConfig(Config): # #user_directory: # search_all_users: false + # + # If this is set, user search will be delegated to this ID server instead + # of synapse performing the saerch itself. + # defer_to_id_server: id.example.com """ diff --git a/synapse/rest/client/v2_alpha/user_directory.py b/synapse/rest/client/v2_alpha/user_directory.py index 2d4a43c35..fd3638914 100644 --- a/synapse/rest/client/v2_alpha/user_directory.py +++ b/synapse/rest/client/v2_alpha/user_directory.py @@ -16,6 +16,7 @@ import logging from twisted.internet import defer +from signedjson.sign import sign_json from synapse.api.errors import SynapseError from synapse.http.servlet import RestServlet, parse_json_object_from_request @@ -36,6 +37,7 @@ class UserDirectorySearchRestServlet(RestServlet): self.hs = hs self.auth = hs.get_auth() self.user_directory_handler = hs.get_user_directory_handler() + self.http_client = hs.get_simple_http_client() @defer.inlineCallbacks def on_POST(self, request): @@ -60,6 +62,14 @@ class UserDirectorySearchRestServlet(RestServlet): body = parse_json_object_from_request(request) + if self.hs.config.user_directory_defer_to_id_server: + signed_body = sign_json(body, self.hs.hostname, self.hs.config.signing_key[0]) + url = "https://%s/_matrix/identity/api/v1/user_directory/search" % ( + self.hs.config.user_directory_defer_to_id_server, + ) + resp = yield self.http_client.post_json_get_json(url, signed_body) + defer.returnValue((200, resp)) + limit = body.get("limit", 10) limit = min(limit, 50) From 643c89d4974eccda45802bc72d783904784a52a3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 25 Apr 2018 11:40:37 +0100 Subject: [PATCH 2/2] Fix spelling & add experimental API comment --- synapse/config/user_directory.py | 3 ++- synapse/rest/client/v2_alpha/user_directory.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/synapse/config/user_directory.py b/synapse/config/user_directory.py index 093ebc4d0..9b0ae9128 100644 --- a/synapse/config/user_directory.py +++ b/synapse/config/user_directory.py @@ -47,6 +47,7 @@ class UserDirectoryConfig(Config): # search_all_users: false # # If this is set, user search will be delegated to this ID server instead - # of synapse performing the saerch itself. + # of synapse performing the search itself. + # This is an experimental API. # defer_to_id_server: id.example.com """ diff --git a/synapse/rest/client/v2_alpha/user_directory.py b/synapse/rest/client/v2_alpha/user_directory.py index fd3638914..9b1a01997 100644 --- a/synapse/rest/client/v2_alpha/user_directory.py +++ b/synapse/rest/client/v2_alpha/user_directory.py @@ -64,7 +64,7 @@ class UserDirectorySearchRestServlet(RestServlet): if self.hs.config.user_directory_defer_to_id_server: signed_body = sign_json(body, self.hs.hostname, self.hs.config.signing_key[0]) - url = "https://%s/_matrix/identity/api/v1/user_directory/search" % ( + url = "http://%s/_matrix/identity/api/v1/user_directory/search" % ( self.hs.config.user_directory_defer_to_id_server, ) resp = yield self.http_client.post_json_get_json(url, signed_body)