aboutsummaryrefslogtreecommitdiff
path: root/userapi/inthttp
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-16 17:39:56 +0100
committerGitHub <noreply@github.com>2020-06-16 17:39:56 +0100
commite15a8042a19b270060beef1358f90cda075ddd38 (patch)
treefaa2334c37ec7b0753541bbe000a16b4ac13548d /userapi/inthttp
parent83391da0e04dda7a52589ee7ec6df2b615571894 (diff)
BREAKING: Make eduserver/appservice use userapi (#1138)
* BREAKING: Make eduserver/appservice use userapi This is a breaking change because this PR restructures how the AS API tracks its position in Kafka streams. Previously, it used the account DB to store partition offsets. However, this is also being used by `clientapi` for the same purpose, which is bad (each component needs to store offsets independently or else you might lose messages across restarts). This PR changes this behaviour to now store partition offsets in the `appservice` database. This means that: - Upon restart, the `appservice` component will attempt to replay all room events from the beginning of time. - An additional table will be created in the appservice database, which in and of itself is backwards compatible. * Return ErrorConflict
Diffstat (limited to 'userapi/inthttp')
-rw-r--r--userapi/inthttp/client.go27
-rw-r--r--userapi/inthttp/server.go26
2 files changed, 53 insertions, 0 deletions
diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go
index 48e6d7d7..0e9628c5 100644
--- a/userapi/inthttp/client.go
+++ b/userapi/inthttp/client.go
@@ -26,6 +26,9 @@ import (
// HTTP paths for the internal HTTP APIs
const (
+ PerformDeviceCreationPath = "/userapi/performDeviceCreation"
+ PerformAccountCreationPath = "/userapi/performAccountCreation"
+
QueryProfilePath = "/userapi/queryProfile"
QueryAccessTokenPath = "/userapi/queryAccessToken"
QueryDevicesPath = "/userapi/queryDevices"
@@ -52,6 +55,30 @@ type httpUserInternalAPI struct {
httpClient *http.Client
}
+func (h *httpUserInternalAPI) PerformAccountCreation(
+ ctx context.Context,
+ request *api.PerformAccountCreationRequest,
+ response *api.PerformAccountCreationResponse,
+) error {
+ span, ctx := opentracing.StartSpanFromContext(ctx, "PerformAccountCreation")
+ defer span.Finish()
+
+ apiURL := h.apiURL + PerformAccountCreationPath
+ return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+}
+
+func (h *httpUserInternalAPI) PerformDeviceCreation(
+ ctx context.Context,
+ request *api.PerformDeviceCreationRequest,
+ response *api.PerformDeviceCreationResponse,
+) error {
+ span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDeviceCreation")
+ defer span.Finish()
+
+ apiURL := h.apiURL + PerformDeviceCreationPath
+ return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
+}
+
func (h *httpUserInternalAPI) QueryProfile(
ctx context.Context,
request *api.QueryProfileRequest,
diff --git a/userapi/inthttp/server.go b/userapi/inthttp/server.go
index 8bf2efc0..8f3be773 100644
--- a/userapi/inthttp/server.go
+++ b/userapi/inthttp/server.go
@@ -25,6 +25,32 @@ import (
)
func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
+ internalAPIMux.Handle(PerformAccountCreationPath,
+ httputil.MakeInternalAPI("performAccountCreation", func(req *http.Request) util.JSONResponse {
+ request := api.PerformAccountCreationRequest{}
+ response := api.PerformAccountCreationResponse{}
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.MessageResponse(http.StatusBadRequest, err.Error())
+ }
+ if err := s.PerformAccountCreation(req.Context(), &request, &response); err != nil {
+ return util.ErrorResponse(err)
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
+ internalAPIMux.Handle(PerformDeviceCreationPath,
+ httputil.MakeInternalAPI("performDeviceCreation", func(req *http.Request) util.JSONResponse {
+ request := api.PerformDeviceCreationRequest{}
+ response := api.PerformDeviceCreationResponse{}
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.MessageResponse(http.StatusBadRequest, err.Error())
+ }
+ if err := s.PerformDeviceCreation(req.Context(), &request, &response); err != nil {
+ return util.ErrorResponse(err)
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
internalAPIMux.Handle(QueryProfilePath,
httputil.MakeInternalAPI("queryProfile", func(req *http.Request) util.JSONResponse {
request := api.QueryProfileRequest{}