dendrite/serverkeyapi/api/http.go
Neil Alexander 7d6461dd3c
Server key component (#1050)
* Server key API (works for monolith but not for polylith yet)

* Re-enable caching on server key API component

* Groundwork for HTTP APIs for server key API

* Hopefully implement HTTP for server key API

* Simplify public key request marshalling from map keys

* Update gomatrixserverlib

* go mod tidy

* Common -> internal

* remove keyring.go

* Update Docker Hub for server key API

* YAML is funny about indentation

* Wire in new server key API into hybrid monolith mode

* Create maps

* Route server key API endpoints on internal API mux

* Fix server key API URLs

* Add fetcher behaviour into server key API implementation

* Return error if we failed to fetch some keys

* Return results anyway

* Move things about a bit

* Remove unused code

* Fix comments, don't use federation sender URL in polylith mode

* Add server_key_api to sample config

* Review comments

* HTTP API to cache keys that have been requested

* Overwrite server_key_api listen in monolith hybrid mode
2020-05-27 10:19:24 +01:00

58 lines
1.7 KiB
Go

package api
import (
"context"
commonHTTP "github.com/matrix-org/dendrite/internal/http"
"github.com/matrix-org/gomatrixserverlib"
"github.com/opentracing/opentracing-go"
)
const (
// ServerKeyInputPublicKeyPath is the HTTP path for the InputPublicKeys API.
ServerKeyInputPublicKeyPath = "/serverkeyapi/inputPublicKey"
// ServerKeyQueryPublicKeyPath is the HTTP path for the QueryPublicKeys API.
ServerKeyQueryPublicKeyPath = "/serverkeyapi/queryPublicKey"
)
type InputPublicKeysRequest struct {
Keys map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"keys"`
}
type InputPublicKeysResponse struct {
}
func (h *httpServerKeyInternalAPI) InputPublicKeys(
ctx context.Context,
request *InputPublicKeysRequest,
response *InputPublicKeysResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InputPublicKey")
defer span.Finish()
apiURL := h.serverKeyAPIURL + ServerKeyInputPublicKeyPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}
type QueryPublicKeysRequest struct {
Requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp `json:"requests"`
}
type QueryPublicKeysResponse struct {
Results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"results"`
}
func (h *httpServerKeyInternalAPI) QueryPublicKeys(
ctx context.Context,
request *QueryPublicKeysRequest,
response *QueryPublicKeysResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPublicKey")
defer span.Finish()
apiURL := h.serverKeyAPIURL + ServerKeyQueryPublicKeyPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}