Remove BaseDendrite from appservice

This commit is contained in:
Till Faelligen 2023-03-20 11:11:53 +01:00
parent 93d0fba3c0
commit 75ba4ec770
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
8 changed files with 17 additions and 16 deletions

View file

@ -22,6 +22,7 @@ import (
"time" "time"
"github.com/matrix-org/dendrite/setup/jetstream" "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/setup/process"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
@ -30,7 +31,6 @@ import (
"github.com/matrix-org/dendrite/appservice/consumers" "github.com/matrix-org/dendrite/appservice/consumers"
"github.com/matrix-org/dendrite/appservice/query" "github.com/matrix-org/dendrite/appservice/query"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
) )
@ -38,7 +38,8 @@ import (
// NewInternalAPI returns a concerete implementation of the internal API. Callers // NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI( func NewInternalAPI(
base *base.BaseDendrite, processContext *process.ProcessContext,
cfg *config.Dendrite,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
userAPI userapi.AppserviceUserAPI, userAPI userapi.AppserviceUserAPI,
rsAPI roomserverAPI.RoomserverInternalAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
@ -48,7 +49,7 @@ func NewInternalAPI(
Transport: &http.Transport{ Transport: &http.Transport{
DisableKeepAlives: true, DisableKeepAlives: true,
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: base.Cfg.AppServiceAPI.DisableTLSValidation, InsecureSkipVerify: cfg.AppServiceAPI.DisableTLSValidation,
}, },
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}, },
@ -57,21 +58,21 @@ func NewInternalAPI(
// outbound and inbound requests (inbound only for the internal API) // outbound and inbound requests (inbound only for the internal API)
appserviceQueryAPI := &query.AppServiceQueryAPI{ appserviceQueryAPI := &query.AppServiceQueryAPI{
HTTPClient: client, HTTPClient: client,
Cfg: &base.Cfg.AppServiceAPI, Cfg: &cfg.AppServiceAPI,
ProtocolCache: map[string]appserviceAPI.ASProtocolResponse{}, ProtocolCache: map[string]appserviceAPI.ASProtocolResponse{},
CacheMu: sync.Mutex{}, CacheMu: sync.Mutex{},
} }
if len(base.Cfg.Derived.ApplicationServices) == 0 { if len(cfg.Derived.ApplicationServices) == 0 {
return appserviceQueryAPI return appserviceQueryAPI
} }
// Wrap application services in a type that relates the application service and // Wrap application services in a type that relates the application service and
// a sync.Cond object that can be used to notify workers when there are new // a sync.Cond object that can be used to notify workers when there are new
// events to be sent out. // events to be sent out.
for _, appservice := range base.Cfg.Derived.ApplicationServices { for _, appservice := range cfg.Derived.ApplicationServices {
// Create bot account for this AS if it doesn't already exist // Create bot account for this AS if it doesn't already exist
if err := generateAppServiceAccount(userAPI, appservice, base.Cfg.Global.ServerName); err != nil { if err := generateAppServiceAccount(userAPI, appservice, cfg.Global.ServerName); err != nil {
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{
"appservice": appservice.ID, "appservice": appservice.ID,
}).WithError(err).Panicf("failed to generate bot account for appservice") }).WithError(err).Panicf("failed to generate bot account for appservice")
@ -80,9 +81,9 @@ func NewInternalAPI(
// Only consume if we actually have ASes to track, else we'll just chew cycles needlessly. // Only consume if we actually have ASes to track, else we'll just chew cycles needlessly.
// We can't add ASes at runtime so this is safe to do. // We can't add ASes at runtime so this is safe to do.
js, _ := natsInstance.Prepare(base.ProcessContext, &base.Cfg.Global.JetStream) js, _ := natsInstance.Prepare(processContext, &cfg.Global.JetStream)
consumer := consumers.NewOutputRoomEventConsumer( consumer := consumers.NewOutputRoomEventConsumer(
base.ProcessContext, &base.Cfg.AppServiceAPI, processContext, &cfg.AppServiceAPI,
client, js, rsAPI, client, js, rsAPI,
) )
if err := consumer.Start(); err != nil { if err := consumer.Start(); err != nil {

View file

@ -130,7 +130,7 @@ func TestAppserviceInternalAPI(t *testing.T) {
natsInstance := jetstream.NATSInstance{} natsInstance := jetstream.NATSInstance{}
rsAPI := roomserver.NewInternalAPI(base, &natsInstance, caches) rsAPI := roomserver.NewInternalAPI(base, &natsInstance, caches)
usrAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, nil) usrAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, nil)
asAPI := appservice.NewInternalAPI(base, &natsInstance, usrAPI, rsAPI) asAPI := appservice.NewInternalAPI(base.ProcessContext, base.Cfg, &natsInstance, usrAPI, rsAPI)
runCases(t, asAPI) runCases(t, asAPI)
}) })

View file

@ -192,7 +192,7 @@ func startup() {
userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation) userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation)
asQuery := appservice.NewInternalAPI( asQuery := appservice.NewInternalAPI(
base, &natsInstance, userAPI, rsAPI, base.ProcessContext, base.Cfg, &natsInstance, userAPI, rsAPI,
) )
rsAPI.SetAppserviceAPI(asQuery) rsAPI.SetAppserviceAPI(asQuery)
caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.EnableMetrics) caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.EnableMetrics)

View file

@ -170,7 +170,7 @@ func (m *DendriteMonolith) Start() {
userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation) userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation)
asAPI := appservice.NewInternalAPI(base, &natsInstance, userAPI, rsAPI) asAPI := appservice.NewInternalAPI(base.ProcessContext, base.Cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI) rsAPI.SetAppserviceAPI(asAPI)
// The underlying roomserver implementation needs to be able to call the fedsender. // The underlying roomserver implementation needs to be able to call the fedsender.

View file

@ -33,7 +33,7 @@ func TestJoinRoomByIDOrAlias(t *testing.T) {
natsInstance := jetstream.NATSInstance{} natsInstance := jetstream.NATSInstance{}
rsAPI := roomserver.NewInternalAPI(base, &natsInstance, caches) rsAPI := roomserver.NewInternalAPI(base, &natsInstance, caches)
userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, nil) userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, nil)
asAPI := appservice.NewInternalAPI(base, &natsInstance, userAPI, rsAPI) asAPI := appservice.NewInternalAPI(base.ProcessContext, base.Cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetFederationAPI(nil, nil) // creates the rs.Inputer etc rsAPI.SetFederationAPI(nil, nil) // creates the rs.Inputer etc
// Create the users in the userapi // Create the users in the userapi

View file

@ -144,7 +144,7 @@ func (p *P2PMonolith) SetupDendrite(cfg *config.Dendrite, port int, enableRelayi
userAPI := userapi.NewInternalAPI(p.BaseDendrite, &natsInstance, rsAPI, federation) userAPI := userapi.NewInternalAPI(p.BaseDendrite, &natsInstance, rsAPI, federation)
asAPI := appservice.NewInternalAPI(p.BaseDendrite, &natsInstance, userAPI, rsAPI) asAPI := appservice.NewInternalAPI(p.BaseDendrite.ProcessContext, p.BaseDendrite.Cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetFederationAPI(fsAPI, keyRing) rsAPI.SetFederationAPI(fsAPI, keyRing)

View file

@ -164,7 +164,7 @@ func main() {
userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation) userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation)
asAPI := appservice.NewInternalAPI(base, &natsInstance, userAPI, rsAPI) asAPI := appservice.NewInternalAPI(base.ProcessContext, base.Cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI) rsAPI.SetAppserviceAPI(asAPI)
fsAPI := federationapi.NewInternalAPI( fsAPI := federationapi.NewInternalAPI(
base, &natsInstance, federation, rsAPI, caches, keyRing, true, base, &natsInstance, federation, rsAPI, caches, keyRing, true,

View file

@ -85,7 +85,7 @@ func main() {
userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation) userAPI := userapi.NewInternalAPI(base, &natsInstance, rsAPI, federation)
asAPI := appservice.NewInternalAPI(base, &natsInstance, userAPI, rsAPI) asAPI := appservice.NewInternalAPI(base.ProcessContext, base.Cfg, &natsInstance, userAPI, rsAPI)
// The underlying roomserver implementation needs to be able to call the fedsender. // The underlying roomserver implementation needs to be able to call the fedsender.
// This is different to rsAPI which can be the http client which doesn't need this // This is different to rsAPI which can be the http client which doesn't need this