mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 14:13:11 -06:00
Improve configuration checks
This commit is contained in:
parent
0c5fc324c2
commit
496dd3a36d
|
|
@ -194,20 +194,22 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
|
||||||
// have a separate database config of their own.
|
// have a separate database config of their own.
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
var writer sqlutil.Writer
|
var writer sqlutil.Writer
|
||||||
if cfg.Global.DatabaseOptions.ConnectionString != "" && isMonolith {
|
if cfg.Global.DatabaseOptions.ConnectionString != "" {
|
||||||
switch {
|
if isMonolith {
|
||||||
case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite():
|
switch {
|
||||||
writer = sqlutil.NewExclusiveWriter()
|
case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite():
|
||||||
default:
|
writer = sqlutil.NewExclusiveWriter()
|
||||||
writer = sqlutil.NewDummyWriter()
|
default:
|
||||||
|
writer = sqlutil.NewDummyWriter()
|
||||||
|
}
|
||||||
|
db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Panic("Failed to set up global database connections")
|
||||||
|
}
|
||||||
|
logrus.Info("Using global database connection pool")
|
||||||
|
} else {
|
||||||
|
logrus.Panic("Using a global database connection pool is not supported in polylith deployments")
|
||||||
}
|
}
|
||||||
db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithError(err).Panic("Failed to set up global database connections")
|
|
||||||
}
|
|
||||||
logrus.Info("Using global database connection pool")
|
|
||||||
} else {
|
|
||||||
logrus.Info("Not using global database connection pool")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ideally we would only use SkipClean on routes which we know can allow '/' but due to
|
// Ideally we would only use SkipClean on routes which we know can allow '/' but due to
|
||||||
|
|
@ -250,7 +252,7 @@ func (b *BaseDendrite) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseConnection sets up a new database connection if appropriate,
|
// DatabaseConnection sets up a new database connection if appropriate,
|
||||||
// or returns the global connection pool if not (monolith mode only).
|
// or returns the global connection pool if not.
|
||||||
func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) {
|
func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) {
|
||||||
if dbProperties.ConnectionString != "" || b == nil {
|
if dbProperties.ConnectionString != "" || b == nil {
|
||||||
db, err := sqlutil.Open(dbProperties, writer)
|
db, err := sqlutil.Open(dbProperties, writer)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,9 @@ func (c *AppServiceAPI) Defaults(generate bool) {
|
||||||
func (c *AppServiceAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *AppServiceAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
checkURL(configErrs, "app_service_api.internal_api.listen", string(c.InternalAPI.Listen))
|
checkURL(configErrs, "app_service_api.internal_api.listen", string(c.InternalAPI.Listen))
|
||||||
checkURL(configErrs, "app_service_api.internal_api.bind", string(c.InternalAPI.Connect))
|
checkURL(configErrs, "app_service_api.internal_api.bind", string(c.InternalAPI.Connect))
|
||||||
//checkNotEmpty(configErrs, "app_service_api.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "app_service_api.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplicationServiceNamespace is the namespace that a specific application
|
// ApplicationServiceNamespace is the namespace that a specific application
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ func (c *FederationAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
if !isMonolith {
|
if !isMonolith {
|
||||||
checkURL(configErrs, "federation_api.external_api.listen", string(c.ExternalAPI.Listen))
|
checkURL(configErrs, "federation_api.external_api.listen", string(c.ExternalAPI.Listen))
|
||||||
}
|
}
|
||||||
//checkNotEmpty(configErrs, "federation_api.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "federation_api.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The config for setting a proxy to use for server->server requests
|
// The config for setting a proxy to use for server->server requests
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,7 @@ func (c *KeyServer) Defaults(generate bool) {
|
||||||
func (c *KeyServer) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *KeyServer) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
checkURL(configErrs, "key_server.internal_api.listen", string(c.InternalAPI.Listen))
|
checkURL(configErrs, "key_server.internal_api.listen", string(c.InternalAPI.Listen))
|
||||||
checkURL(configErrs, "key_server.internal_api.bind", string(c.InternalAPI.Connect))
|
checkURL(configErrs, "key_server.internal_api.bind", string(c.InternalAPI.Connect))
|
||||||
//checkNotEmpty(configErrs, "key_server.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "key_server.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,9 @@ func (c *MediaAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
if !isMonolith {
|
if !isMonolith {
|
||||||
checkURL(configErrs, "media_api.external_api.listen", string(c.ExternalAPI.Listen))
|
checkURL(configErrs, "media_api.external_api.listen", string(c.ExternalAPI.Listen))
|
||||||
}
|
}
|
||||||
//checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
|
|
||||||
checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath))
|
checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath))
|
||||||
checkPositive(configErrs, "media_api.max_file_size_bytes", int64(c.MaxFileSizeBytes))
|
checkPositive(configErrs, "media_api.max_file_size_bytes", int64(c.MaxFileSizeBytes))
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,7 @@ func (c *MSCs) Enabled(msc string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MSCs) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *MSCs) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
//checkNotEmpty(configErrs, "mscs.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "mscs.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,7 @@ func (c *RoomServer) Defaults(generate bool) {
|
||||||
func (c *RoomServer) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *RoomServer) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
checkURL(configErrs, "room_server.internal_api.listen", string(c.InternalAPI.Listen))
|
checkURL(configErrs, "room_server.internal_api.listen", string(c.InternalAPI.Listen))
|
||||||
checkURL(configErrs, "room_server.internal_ap.bind", string(c.InternalAPI.Connect))
|
checkURL(configErrs, "room_server.internal_ap.bind", string(c.InternalAPI.Connect))
|
||||||
//checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,7 @@ func (c *SyncAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
if !isMonolith {
|
if !isMonolith {
|
||||||
checkURL(configErrs, "sync_api.external_api.listen", string(c.ExternalAPI.Listen))
|
checkURL(configErrs, "sync_api.external_api.listen", string(c.ExternalAPI.Listen))
|
||||||
}
|
}
|
||||||
//checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ func (c *UserAPI) Defaults(generate bool) {
|
||||||
func (c *UserAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *UserAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
checkURL(configErrs, "user_api.internal_api.listen", string(c.InternalAPI.Listen))
|
checkURL(configErrs, "user_api.internal_api.listen", string(c.InternalAPI.Listen))
|
||||||
checkURL(configErrs, "user_api.internal_api.connect", string(c.InternalAPI.Connect))
|
checkURL(configErrs, "user_api.internal_api.connect", string(c.InternalAPI.Connect))
|
||||||
//checkNotEmpty(configErrs, "user_api.account_database.connection_string", string(c.AccountDatabase.ConnectionString))
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
|
checkNotEmpty(configErrs, "user_api.account_database.connection_string", string(c.AccountDatabase.ConnectionString))
|
||||||
|
}
|
||||||
checkPositive(configErrs, "user_api.openid_token_lifetime_ms", c.OpenIDTokenLifetimeMS)
|
checkPositive(configErrs, "user_api.openid_token_lifetime_ms", c.OpenIDTokenLifetimeMS)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue