diff options
author | Kegsay <kegan@matrix.org> | 2020-08-03 12:29:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-03 12:29:58 +0100 |
commit | ffcb6d2ea199cfa985e72ffbdcb884fb9bc9f54d (patch) | |
tree | 6d25818803444fead9ab18db15e88e30be6641c6 /keyserver/inthttp | |
parent | b5cb1d153458ad83abdfbebed7405dd9da159cb8 (diff) |
Produce OTK counts in /sync response (#1235)
* Add QueryOneTimeKeys for /sync extensions
* Unbreak tests
* Produce OTK counts in /sync response
* Linting
Diffstat (limited to 'keyserver/inthttp')
-rw-r--r-- | keyserver/inthttp/client.go | 18 | ||||
-rw-r--r-- | keyserver/inthttp/server.go | 11 |
2 files changed, 29 insertions, 0 deletions
diff --git a/keyserver/inthttp/client.go b/keyserver/inthttp/client.go index 3f9690b5..b65cbdaf 100644 --- a/keyserver/inthttp/client.go +++ b/keyserver/inthttp/client.go @@ -31,6 +31,7 @@ const ( PerformClaimKeysPath = "/keyserver/performClaimKeys" QueryKeysPath = "/keyserver/queryKeys" QueryKeyChangesPath = "/keyserver/queryKeyChanges" + QueryOneTimeKeysPath = "/keyserver/queryOneTimeKeys" ) // NewKeyServerClient creates a KeyInternalAPI implemented by talking to a HTTP POST API. @@ -108,6 +109,23 @@ func (h *httpKeyInternalAPI) QueryKeys( } } +func (h *httpKeyInternalAPI) QueryOneTimeKeys( + ctx context.Context, + request *api.QueryOneTimeKeysRequest, + response *api.QueryOneTimeKeysResponse, +) { + span, ctx := opentracing.StartSpanFromContext(ctx, "QueryOneTimeKeys") + defer span.Finish() + + apiURL := h.apiURL + QueryOneTimeKeysPath + err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + if err != nil { + response.Error = &api.KeyError{ + Err: err.Error(), + } + } +} + func (h *httpKeyInternalAPI) QueryKeyChanges( ctx context.Context, request *api.QueryKeyChangesRequest, diff --git a/keyserver/inthttp/server.go b/keyserver/inthttp/server.go index f3d2882c..615b6f80 100644 --- a/keyserver/inthttp/server.go +++ b/keyserver/inthttp/server.go @@ -58,6 +58,17 @@ func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(QueryOneTimeKeysPath, + httputil.MakeInternalAPI("queryOneTimeKeys", func(req *http.Request) util.JSONResponse { + request := api.QueryOneTimeKeysRequest{} + response := api.QueryOneTimeKeysResponse{} + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + s.QueryOneTimeKeys(req.Context(), &request, &response) + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) internalAPIMux.Handle(QueryKeyChangesPath, httputil.MakeInternalAPI("queryKeyChanges", func(req *http.Request) util.JSONResponse { request := api.QueryKeyChangesRequest{} |