mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-20 13:23:22 -06:00
Groundwork for HTTP APIs for server key API
This commit is contained in:
parent
9b783f9b49
commit
8af52942c1
|
|
@ -17,7 +17,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/clientapi"
|
"github.com/matrix-org/dendrite/clientapi"
|
||||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
|
||||||
"github.com/matrix-org/dendrite/common/transactions"
|
"github.com/matrix-org/dendrite/common/transactions"
|
||||||
"github.com/matrix-org/dendrite/eduserver"
|
"github.com/matrix-org/dendrite/eduserver"
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
|
|
@ -31,9 +30,10 @@ func main() {
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
keyDB := base.CreateKeyDB()
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
|
||||||
|
serverKeyAPI := base.CreateHTTPServerKeyAPIs()
|
||||||
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
asQuery := base.CreateHTTPAppServiceAPIs()
|
asQuery := base.CreateHTTPAppServiceAPIs()
|
||||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||||
|
|
@ -42,7 +42,7 @@ func main() {
|
||||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
||||||
|
|
||||||
clientapi.SetupClientAPIComponent(
|
clientapi.SetupClientAPIComponent(
|
||||||
base, deviceDB, accountDB, federation, &keyRing,
|
base, deviceDB, accountDB, federation, keyRing,
|
||||||
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
|
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
|
||||||
"github.com/matrix-org/dendrite/eduserver"
|
"github.com/matrix-org/dendrite/eduserver"
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
"github.com/matrix-org/dendrite/federationapi"
|
"github.com/matrix-org/dendrite/federationapi"
|
||||||
|
|
@ -30,10 +29,12 @@ func main() {
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
keyDB := base.CreateKeyDB()
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
|
|
||||||
|
serverKeyAPI := base.CreateHTTPServerKeyAPIs()
|
||||||
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
|
||||||
|
|
||||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||||
asAPI := base.CreateHTTPAppServiceAPIs()
|
asAPI := base.CreateHTTPAppServiceAPIs()
|
||||||
|
|
@ -42,7 +43,7 @@ func main() {
|
||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
|
|
||||||
federationapi.SetupFederationAPIComponent(
|
federationapi.SetupFederationAPIComponent(
|
||||||
base, accountDB, deviceDB, federation, &keyRing,
|
base, accountDB, deviceDB, federation, keyRing,
|
||||||
rsAPI, asAPI, fsAPI, eduProducer,
|
rsAPI, asAPI, fsAPI, eduProducer,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
|
||||||
"github.com/matrix-org/dendrite/federationsender"
|
"github.com/matrix-org/dendrite/federationsender"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -26,11 +25,13 @@ func main() {
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
keyDB := base.CreateKeyDB()
|
|
||||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
serverKeyAPI := base.CreateHTTPServerKeyAPIs()
|
||||||
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||||
fsAPI := federationsender.SetupFederationSenderComponent(
|
fsAPI := federationsender.SetupFederationSenderComponent(
|
||||||
base, federation, rsAPI, &keyRing,
|
base, federation, rsAPI, keyRing,
|
||||||
)
|
)
|
||||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -24,9 +23,10 @@ func main() {
|
||||||
cfg := basecomponent.ParseFlags()
|
cfg := basecomponent.ParseFlags()
|
||||||
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true)
|
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true)
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
keyDB := base.CreateKeyDB()
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
|
||||||
|
serverKeyAPI := base.CreateHTTPServerKeyAPIs()
|
||||||
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||||
|
|
|
||||||
|
|
@ -186,29 +186,6 @@ func (b *BaseDendrite) CreateAccountsDB() accounts.Database {
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateKeyDB creates a new instance of the key database. Should only be called
|
|
||||||
// once per component.
|
|
||||||
/*
|
|
||||||
func (b *BaseDendrite) CreateKeyDB() keydb.Database {
|
|
||||||
db, err := keydb.NewDatabase(
|
|
||||||
string(b.Cfg.Database.ServerKey),
|
|
||||||
b.Cfg.DbProperties(),
|
|
||||||
b.Cfg.Matrix.ServerName,
|
|
||||||
b.Cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
|
|
||||||
b.Cfg.Matrix.KeyID,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(err).Panicf("failed to connect to keys db")
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedDB, err := cache.NewKeyDatabase(db, b.ImmutableCache)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(err).Panicf("failed to create key cache wrapper")
|
|
||||||
}
|
|
||||||
return cachedDB
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// CreateFederationClient creates a new federation client. Should only be called
|
// CreateFederationClient creates a new federation client. Should only be called
|
||||||
// once per component.
|
// once per component.
|
||||||
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
|
@ -10,6 +11,20 @@ import (
|
||||||
|
|
||||||
type ServerKeyInternalAPI interface {
|
type ServerKeyInternalAPI interface {
|
||||||
gomatrixserverlib.KeyDatabase
|
gomatrixserverlib.KeyDatabase
|
||||||
|
|
||||||
|
KeyRing() *gomatrixserverlib.KeyRing
|
||||||
|
|
||||||
|
InputPublicKeys(
|
||||||
|
ctx context.Context,
|
||||||
|
request *InputPublicKeysRequest,
|
||||||
|
response *InputPublicKeysResponse,
|
||||||
|
) error
|
||||||
|
|
||||||
|
QueryPublicKeys(
|
||||||
|
ctx context.Context,
|
||||||
|
request *QueryPublicKeysRequest,
|
||||||
|
response *QueryPublicKeysResponse,
|
||||||
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRoomserverInputAPIHTTP creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
|
// NewRoomserverInputAPIHTTP creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
|
||||||
|
|
@ -28,3 +43,18 @@ func NewServerKeyInternalAPIHTTP(
|
||||||
immutableCache: immutableCache,
|
immutableCache: immutableCache,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type httpServerKeyInternalAPI struct {
|
||||||
|
ServerKeyInternalAPI
|
||||||
|
|
||||||
|
serverKeyAPIURL string
|
||||||
|
httpClient *http.Client
|
||||||
|
immutableCache caching.ImmutableCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *httpServerKeyInternalAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
||||||
|
return &gomatrixserverlib.KeyRing{
|
||||||
|
KeyDatabase: s,
|
||||||
|
KeyFetchers: []gomatrixserverlib.KeyFetcher{s},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,52 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common/caching"
|
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
|
"github.com/opentracing/opentracing-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpServerKeyInternalAPI struct {
|
const (
|
||||||
ServerKeyInternalAPI
|
// RoomserverPerformJoinPath is the HTTP path for the PerformJoin API.
|
||||||
|
ServerKeyInputPublicKeyPath = "/api/serverkeyapi/inputPublicKey"
|
||||||
|
|
||||||
serverKeyAPIURL string
|
// RoomserverPerformLeavePath is the HTTP path for the PerformLeave API.
|
||||||
httpClient *http.Client
|
ServerKeyQueryPublicKeyPath = "/api/serverkeyapi/queryPublicKey"
|
||||||
immutableCache caching.ImmutableCache
|
)
|
||||||
|
|
||||||
|
type InputPublicKeysRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServerKeyInternalAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
type InputPublicKeysResponse struct {
|
||||||
return &gomatrixserverlib.KeyRing{
|
|
||||||
KeyDatabase: s,
|
|
||||||
KeyFetchers: []gomatrixserverlib.KeyFetcher{s},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServerKeyInternalAPI) StoreKeys(
|
func (h *httpServerKeyInternalAPI) InputPublicKeys(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult,
|
request *InputPublicKeysRequest,
|
||||||
|
response *InputPublicKeysResponse,
|
||||||
) error {
|
) error {
|
||||||
return nil
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputPublicKey")
|
||||||
|
defer span.Finish()
|
||||||
|
|
||||||
|
apiURL := h.serverKeyAPIURL + ServerKeyInputPublicKeyPath
|
||||||
|
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServerKeyInternalAPI) FetchKeys(
|
type QueryPublicKeysRequest struct {
|
||||||
ctx context.Context,
|
}
|
||||||
requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
|
||||||
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
type QueryPublicKeysResponse struct {
|
||||||
return nil, nil
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
serverkeyapi/api/satisfy.go
Normal file
25
serverkeyapi/api/satisfy.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *httpServerKeyInternalAPI) FetcherName() string {
|
||||||
|
return "httpServerKeyInternalAPI"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *httpServerKeyInternalAPI) StoreKeys(
|
||||||
|
ctx context.Context,
|
||||||
|
results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult,
|
||||||
|
) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *httpServerKeyInternalAPI) FetchKeys(
|
||||||
|
ctx context.Context,
|
||||||
|
requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
||||||
|
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
@ -5,12 +5,13 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common/caching"
|
"github.com/matrix-org/dendrite/common/caching"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi/storage"
|
"github.com/matrix-org/dendrite/serverkeyapi/storage"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerKeyAPI struct {
|
type ServerKeyAPI struct {
|
||||||
gomatrixserverlib.KeyDatabase
|
api.ServerKeyInternalAPI
|
||||||
|
|
||||||
DB storage.Database
|
DB storage.Database
|
||||||
Cfg *config.Dendrite
|
Cfg *config.Dendrite
|
||||||
|
|
@ -36,3 +37,7 @@ func (s *ServerKeyAPI) FetchKeys(
|
||||||
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
||||||
return s.DB.FetchKeys(ctx, requests)
|
return s.DB.FetchKeys(ctx, requests)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerKeyAPI) FetcherName() string {
|
||||||
|
return s.DB.FetcherName()
|
||||||
|
}
|
||||||
|
|
|
||||||
43
serverkeyapi/internal/http.go
Normal file
43
serverkeyapi/internal/http.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *ServerKeyAPI) SetupHTTP(servMux *http.ServeMux) {
|
||||||
|
servMux.Handle(api.ServerKeyQueryPublicKeyPath,
|
||||||
|
common.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||||
|
var request api.QueryPublicKeysRequest
|
||||||
|
var response api.QueryPublicKeysResponse
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if err := s.DB.FetchKeys(); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
servMux.Handle(api.ServerKeyInputPublicKeyPath,
|
||||||
|
common.MakeInternalAPI("inputPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||||
|
var request api.InputPublicKeysRequest
|
||||||
|
var response api.InputPublicKeysResponse
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if err := s.DB.FetchKeys(); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue