2020-08-10 14:18:04 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-03 10:12:11 +01:00
|
|
|
"flag"
|
2020-08-10 14:18:04 +01:00
|
|
|
"fmt"
|
2022-09-01 14:15:41 +01:00
|
|
|
"path/filepath"
|
2020-08-10 14:18:04 +01:00
|
|
|
|
2021-10-29 12:06:10 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2021-03-08 13:19:02 +00:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
2020-08-10 14:18:04 +01:00
|
|
|
"gopkg.in/yaml.v2"
|
2022-09-27 17:06:49 +01:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2020-08-10 14:18:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-09-01 14:15:41 +01:00
|
|
|
defaultsForCI := flag.Bool("ci", false, "Populate the configuration with sane defaults for use in CI")
|
2021-10-29 12:06:10 +01:00
|
|
|
serverName := flag.String("server", "", "The domain name of the server if not 'localhost'")
|
2022-09-01 14:15:41 +01:00
|
|
|
dbURI := flag.String("db", "", "The DB URI to use for all components (PostgreSQL only)")
|
|
|
|
dirPath := flag.String("dir", "./", "The folder to use for paths (like SQLite databases, media storage)")
|
|
|
|
normalise := flag.String("normalise", "", "Normalise an existing configuration file by adding new/missing options and defaults")
|
|
|
|
polylith := flag.Bool("polylith", false, "Generate a config that makes sense for polylith deployments")
|
2020-09-03 10:12:11 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2022-09-01 14:15:41 +01:00
|
|
|
var cfg *config.Dendrite
|
|
|
|
if *normalise == "" {
|
|
|
|
cfg = &config.Dendrite{
|
|
|
|
Version: config.Version,
|
|
|
|
}
|
|
|
|
cfg.Defaults(config.DefaultOpts{
|
|
|
|
Generate: true,
|
|
|
|
Monolithic: !*polylith,
|
|
|
|
})
|
|
|
|
if *serverName != "" {
|
|
|
|
cfg.Global.ServerName = gomatrixserverlib.ServerName(*serverName)
|
|
|
|
}
|
|
|
|
uri := config.DataSource(*dbURI)
|
|
|
|
if *polylith || uri.IsSQLite() || uri == "" {
|
|
|
|
for name, db := range map[string]*config.DatabaseOptions{
|
|
|
|
"federationapi": &cfg.FederationAPI.Database,
|
|
|
|
"keyserver": &cfg.KeyServer.Database,
|
|
|
|
"mscs": &cfg.MSCs.Database,
|
|
|
|
"mediaapi": &cfg.MediaAPI.Database,
|
|
|
|
"roomserver": &cfg.RoomServer.Database,
|
|
|
|
"syncapi": &cfg.SyncAPI.Database,
|
|
|
|
"userapi": &cfg.UserAPI.AccountDatabase,
|
|
|
|
} {
|
|
|
|
if uri == "" {
|
|
|
|
path := filepath.Join(*dirPath, fmt.Sprintf("dendrite_%s.db", name))
|
|
|
|
db.ConnectionString = config.DataSource(fmt.Sprintf("file:%s", path))
|
|
|
|
} else {
|
|
|
|
db.ConnectionString = uri
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cfg.Global.DatabaseOptions.ConnectionString = uri
|
|
|
|
}
|
|
|
|
cfg.Logging = []config.LogrusHook{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
Level: "info",
|
|
|
|
Params: map[string]interface{}{
|
|
|
|
"path": filepath.Join(*dirPath, "log"),
|
2020-08-11 13:21:26 +01:00
|
|
|
},
|
|
|
|
},
|
2022-09-01 14:15:41 +01:00
|
|
|
}
|
|
|
|
if *defaultsForCI {
|
|
|
|
cfg.AppServiceAPI.DisableTLSValidation = true
|
|
|
|
cfg.ClientAPI.RateLimiting.Enabled = false
|
|
|
|
cfg.FederationAPI.DisableTLSValidation = false
|
|
|
|
// don't hit matrix.org when running tests!!!
|
|
|
|
cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{}
|
|
|
|
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))
|
|
|
|
cfg.MSCs.MSCs = []string{"msc2836", "msc2946", "msc2444", "msc2753"}
|
|
|
|
cfg.Logging[0].Level = "trace"
|
|
|
|
cfg.Logging[0].Type = "std"
|
|
|
|
cfg.UserAPI.BCryptCost = bcrypt.MinCost
|
|
|
|
cfg.Global.JetStream.InMemory = true
|
|
|
|
cfg.Global.JetStream.StoragePath = config.Path(*dirPath)
|
|
|
|
cfg.ClientAPI.RegistrationDisabled = false
|
|
|
|
cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled = true
|
|
|
|
cfg.ClientAPI.RegistrationSharedSecret = "complement"
|
|
|
|
cfg.Global.Presence = config.PresenceOptions{
|
|
|
|
EnableInbound: true,
|
|
|
|
EnableOutbound: true,
|
|
|
|
}
|
2022-09-27 17:06:49 +01:00
|
|
|
cfg.SyncAPI.Fulltext = config.Fulltext{
|
|
|
|
Enabled: true,
|
|
|
|
IndexPath: config.Path(filepath.Join(*dirPath, "fulltextindex")),
|
|
|
|
InMemory: true,
|
|
|
|
Language: "en",
|
|
|
|
}
|
2022-09-01 14:15:41 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var err error
|
|
|
|
if cfg, err = config.Load(*normalise, !*polylith); err != nil {
|
|
|
|
panic(err)
|
2022-04-06 12:11:19 +01:00
|
|
|
}
|
2020-09-03 10:12:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
j, err := yaml.Marshal(cfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(j))
|
|
|
|
}
|