Add EDU server wiring

This commit is contained in:
Neil Alexander 2021-07-28 14:06:23 +01:00
parent dcadec88d9
commit 8683f7553f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
9 changed files with 105 additions and 0 deletions

View file

@ -15,6 +15,7 @@ const (
EDUServerInputTypingEventPath = "/eduserver/input"
EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice"
EDUServerInputReceiptEventPath = "/eduserver/receipt"
EDUServerInputSigningKeyUpdatePath = "/eduserver/signingKeyUpdate"
)
// NewEDUServerClient creates a EDUServerInputAPI implemented by talking to a HTTP POST API.
@ -68,3 +69,16 @@ func (h *httpEDUServerInputAPI) InputReceiptEvent(
apiURL := h.eduServerURL + EDUServerInputReceiptEventPath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}
// InputSigningKeyUpdate implements EDUServerInputAPI
func (h *httpEDUServerInputAPI) InputSigningKeyUpdate(
ctx context.Context,
request *api.InputSigningKeyUpdateRequest,
response *api.InputSigningKeyUpdateResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InputSigningKeyUpdate")
defer span.Finish()
apiURL := h.eduServerURL + EDUServerInputSigningKeyUpdatePath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}

View file

@ -51,4 +51,17 @@ func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
internalAPIMux.Handle(EDUServerInputSigningKeyUpdatePath,
httputil.MakeInternalAPI("inputSigningKeyUpdate", func(req *http.Request) util.JSONResponse {
var request api.InputSigningKeyUpdateRequest
var response api.InputSigningKeyUpdateResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
if err := t.InputSigningKeyUpdate(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
}