aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-08 15:51:07 +0100
committerGitHub <noreply@github.com>2020-06-08 15:51:07 +0100
commit4f171c56a832c836b0eb21650ee84d56e451dd6a (patch)
treee92059f1dbb784c978b60897d6ac13983d51c1b4 /appservice
parentcdb9a115715bd5a9e84df5bc95060e2dac1f6d89 (diff)
Split out SetupFooComponent (#1106)
* Split out adding HTTP routes from making internal APIs for clarity * Split out more components * Split out more things * Finish converting * internal mux for internal routes
Diffstat (limited to 'appservice')
-rw-r--r--appservice/appservice.go33
1 files changed, 19 insertions, 14 deletions
diff --git a/appservice/appservice.go b/appservice/appservice.go
index b5ffba5e..dca600bf 100644
--- a/appservice/appservice.go
+++ b/appservice/appservice.go
@@ -21,6 +21,7 @@ import (
"sync"
"time"
+ "github.com/gorilla/mux"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/appservice/consumers"
"github.com/matrix-org/dendrite/appservice/inthttp"
@@ -40,15 +41,28 @@ import (
"github.com/sirupsen/logrus"
)
-// SetupAppServiceAPIComponent sets up and registers HTTP handlers for the AppServices
-// component.
-func SetupAppServiceAPIComponent(
+// AddPublicRoutes registers HTTP handlers for CS API calls
+func AddPublicRoutes(router *mux.Router, cfg *config.Dendrite, rsAPI roomserverAPI.RoomserverInternalAPI,
+ accountsDB accounts.Database, federation *gomatrixserverlib.FederationClient, txnCache *transactions.Cache) {
+
+ routing.Setup(
+ router, cfg, rsAPI,
+ accountsDB, federation, txnCache,
+ )
+}
+
+// AddInternalRoutes registers HTTP handlers for internal API calls
+func AddInternalRoutes(router *mux.Router, queryAPI appserviceAPI.AppServiceQueryAPI) {
+ inthttp.AddRoutes(queryAPI, router)
+}
+
+// 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.
+func NewInternalAPI(
base *basecomponent.BaseDendrite,
accountsDB accounts.Database,
deviceDB devices.Database,
- federation *gomatrixserverlib.FederationClient,
rsAPI roomserverAPI.RoomserverInternalAPI,
- transactionsCache *transactions.Cache,
) appserviceAPI.AppServiceQueryAPI {
// Create a connection to the appservice postgres DB
appserviceDB, err := storage.NewDatabase(string(base.Cfg.Database.AppService), base.Cfg.DbProperties())
@@ -85,8 +99,6 @@ func SetupAppServiceAPIComponent(
Cfg: base.Cfg,
}
- inthttp.AddRoutes(appserviceQueryAPI, base.InternalAPIMux)
-
consumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
rsAPI, workerStates,
@@ -99,13 +111,6 @@ func SetupAppServiceAPIComponent(
if err := workers.SetupTransactionWorkers(appserviceDB, workerStates); err != nil {
logrus.WithError(err).Panicf("failed to start app service transaction workers")
}
-
- // Set up HTTP Endpoints
- routing.Setup(
- base.PublicAPIMux, base.Cfg, rsAPI,
- accountsDB, federation, transactionsCache,
- )
-
return appserviceQueryAPI
}