aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
Diffstat (limited to 'appservice')
-rw-r--r--appservice/appservice.go2
-rw-r--r--appservice/consumers/roomserver.go4
-rw-r--r--appservice/storage/postgres/storage.go5
-rw-r--r--appservice/storage/sqlite3/storage.go9
-rw-r--r--appservice/storage/storage.go22
-rw-r--r--appservice/storage/storage_wasm.go24
6 files changed, 26 insertions, 40 deletions
diff --git a/appservice/appservice.go b/appservice/appservice.go
index 72869041..e356f68e 100644
--- a/appservice/appservice.go
+++ b/appservice/appservice.go
@@ -48,7 +48,7 @@ func NewInternalAPI(
rsAPI roomserverAPI.RoomserverInternalAPI,
) appserviceAPI.AppServiceQueryAPI {
// Create a connection to the appservice postgres DB
- appserviceDB, err := storage.NewDatabase(string(base.Cfg.Database.AppService), base.Cfg.DbProperties())
+ appserviceDB, err := storage.NewDatabase(&base.Cfg.AppServiceAPI.Database)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to appservice db")
}
diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go
index 4c0156b2..84f2b9ab 100644
--- a/appservice/consumers/roomserver.go
+++ b/appservice/consumers/roomserver.go
@@ -48,7 +48,7 @@ func NewOutputRoomEventConsumer(
workerStates []types.ApplicationServiceWorkerState,
) *OutputRoomEventConsumer {
consumer := internal.ContinualConsumer{
- Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
+ Topic: string(cfg.Global.Kafka.Topics.OutputRoomEvent),
Consumer: kafkaConsumer,
PartitionStore: appserviceDB,
}
@@ -56,7 +56,7 @@ func NewOutputRoomEventConsumer(
roomServerConsumer: &consumer,
asDB: appserviceDB,
rsAPI: rsAPI,
- serverName: string(cfg.Matrix.ServerName),
+ serverName: string(cfg.Global.ServerName),
workerStates: workerStates,
}
consumer.ProcessMessage = s.onMessage
diff --git a/appservice/storage/postgres/storage.go b/appservice/storage/postgres/storage.go
index 03f331d6..9fda87ae 100644
--- a/appservice/storage/postgres/storage.go
+++ b/appservice/storage/postgres/storage.go
@@ -21,6 +21,7 @@ import (
// Import postgres database driver
_ "github.com/lib/pq"
+ "github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib"
)
@@ -34,10 +35,10 @@ type Database struct {
}
// NewDatabase opens a new database
-func NewDatabase(dataSourceName string, dbProperties sqlutil.DbProperties) (*Database, error) {
+func NewDatabase(dbProperties *config.DatabaseOptions) (*Database, error) {
var result Database
var err error
- if result.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil {
+ if result.db, err = sqlutil.Open(dbProperties); err != nil {
return nil, err
}
if err = result.prepare(); err != nil {
diff --git a/appservice/storage/sqlite3/storage.go b/appservice/storage/sqlite3/storage.go
index cb55c8d9..59af9016 100644
--- a/appservice/storage/sqlite3/storage.go
+++ b/appservice/storage/sqlite3/storage.go
@@ -20,6 +20,7 @@ import (
"database/sql"
// Import SQLite database driver
+ "github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib"
_ "github.com/mattn/go-sqlite3"
@@ -34,14 +35,10 @@ type Database struct {
}
// NewDatabase opens a new database
-func NewDatabase(dataSourceName string) (*Database, error) {
+func NewDatabase(dbProperties *config.DatabaseOptions) (*Database, error) {
var result Database
var err error
- cs, err := sqlutil.ParseFileURI(dataSourceName)
- if err != nil {
- return nil, err
- }
- if result.db, err = sqlutil.Open(sqlutil.SQLiteDriverName(), cs, nil); err != nil {
+ if result.db, err = sqlutil.Open(dbProperties); err != nil {
return nil, err
}
if err = result.prepare(); err != nil {
diff --git a/appservice/storage/storage.go b/appservice/storage/storage.go
index c848d15d..e2d7e4e5 100644
--- a/appservice/storage/storage.go
+++ b/appservice/storage/storage.go
@@ -17,26 +17,22 @@
package storage
import (
- "net/url"
+ "fmt"
"github.com/matrix-org/dendrite/appservice/storage/postgres"
"github.com/matrix-org/dendrite/appservice/storage/sqlite3"
- "github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/dendrite/internal/config"
)
// NewDatabase opens a new Postgres or Sqlite database (based on dataSourceName scheme)
// and sets DB connection parameters
-func NewDatabase(dataSourceName string, dbProperties sqlutil.DbProperties) (Database, error) {
- uri, err := url.Parse(dataSourceName)
- if err != nil {
- return postgres.NewDatabase(dataSourceName, dbProperties)
- }
- switch uri.Scheme {
- case "postgres":
- return postgres.NewDatabase(dataSourceName, dbProperties)
- case "file":
- return sqlite3.NewDatabase(dataSourceName)
+func NewDatabase(dbProperties *config.DatabaseOptions) (Database, error) {
+ switch {
+ case dbProperties.ConnectionString.IsSQLite():
+ return sqlite3.NewDatabase(dbProperties)
+ case dbProperties.ConnectionString.IsPostgres():
+ return postgres.NewDatabase(dbProperties)
default:
- return postgres.NewDatabase(dataSourceName, dbProperties)
+ return nil, fmt.Errorf("unexpected database type")
}
}
diff --git a/appservice/storage/storage_wasm.go b/appservice/storage/storage_wasm.go
index 1d6c4b4a..7eb7da26 100644
--- a/appservice/storage/storage_wasm.go
+++ b/appservice/storage/storage_wasm.go
@@ -16,26 +16,18 @@ package storage
import (
"fmt"
- "net/url"
"github.com/matrix-org/dendrite/appservice/storage/sqlite3"
- "github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/dendrite/internal/config"
)
-func NewDatabase(
- dataSourceName string,
- dbProperties sqlutil.DbProperties, // nolint:unparam
-) (Database, error) {
- uri, err := url.Parse(dataSourceName)
- if err != nil {
- return nil, fmt.Errorf("Cannot use postgres implementation")
- }
- switch uri.Scheme {
- case "postgres":
- return nil, fmt.Errorf("Cannot use postgres implementation")
- case "file":
- return sqlite3.NewDatabase(dataSourceName)
+func NewDatabase(dbProperties *config.DatabaseOptions) (Database, error) {
+ switch {
+ case dbProperties.ConnectionString.IsSQLite():
+ return sqlite3.NewDatabase(dbProperties)
+ case dbProperties.ConnectionString.IsPostgres():
+ return nil, fmt.Errorf("can't use Postgres implementation")
default:
- return nil, fmt.Errorf("Cannot use postgres implementation")
+ return nil, fmt.Errorf("unexpected database type")
}
}