2020-08-10 08:18:04 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-03 04:12:11 -05:00
|
|
|
"flag"
|
2020-08-10 08:18:04 -05:00
|
|
|
"fmt"
|
2022-09-01 08:15:41 -05:00
|
|
|
"path/filepath"
|
2020-08-10 08:18:04 -05:00
|
|
|
|
2021-03-08 07:19:02 -06:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
2020-08-10 08:18:04 -05:00
|
|
|
"gopkg.in/yaml.v2"
|
2022-09-27 11:06:49 -05:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2023-04-19 09:50:33 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2020-08-10 08:18:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-09-01 08:15:41 -05:00
|
|
|
defaultsForCI := flag.Bool("ci", false, "Populate the configuration with sane defaults for use in CI")
|
2021-10-29 06:06:10 -05:00
|
|
|
serverName := flag.String("server", "", "The domain name of the server if not 'localhost'")
|
2022-09-01 08:15:41 -05: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")
|
2020-09-03 04:12:11 -05:00
|
|
|
flag.Parse()
|
|
|
|
|
2022-09-01 08:15:41 -05:00
|
|
|
var cfg *config.Dendrite
|
|
|
|
if *normalise == "" {
|
|
|
|
cfg = &config.Dendrite{
|
|
|
|
Version: config.Version,
|
|
|
|
}
|
|
|
|
cfg.Defaults(config.DefaultOpts{
|
2023-02-14 05:47:47 -06:00
|
|
|
Generate: true,
|
|
|
|
SingleDatabase: true,
|
2022-09-01 08:15:41 -05:00
|
|
|
})
|
|
|
|
if *serverName != "" {
|
2023-04-19 09:50:33 -05:00
|
|
|
cfg.Global.ServerName = spec.ServerName(*serverName)
|
2022-09-01 08:15:41 -05:00
|
|
|
}
|
|
|
|
uri := config.DataSource(*dbURI)
|
2023-02-14 05:47:47 -06:00
|
|
|
if uri.IsSQLite() || uri == "" {
|
2022-09-01 08:15:41 -05:00
|
|
|
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,
|
2023-02-14 05:47:47 -06:00
|
|
|
"relayapi": &cfg.RelayAPI.Database,
|
2022-09-01 08:15:41 -05:00
|
|
|
} {
|
|
|
|
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
|
|
|
|
}
|
2023-01-20 06:13:36 -06:00
|
|
|
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))
|
|
|
|
cfg.Global.JetStream.StoragePath = config.Path(*dirPath)
|
|
|
|
cfg.SyncAPI.Fulltext.IndexPath = config.Path(filepath.Join(*dirPath, "searchindex"))
|
2022-09-01 08:15:41 -05:00
|
|
|
cfg.Logging = []config.LogrusHook{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
Level: "info",
|
|
|
|
Params: map[string]interface{}{
|
|
|
|
"path": filepath.Join(*dirPath, "log"),
|
2020-08-11 07:21:26 -05:00
|
|
|
},
|
|
|
|
},
|
2022-09-01 08:15:41 -05:00
|
|
|
}
|
|
|
|
if *defaultsForCI {
|
|
|
|
cfg.AppServiceAPI.DisableTLSValidation = true
|
|
|
|
cfg.ClientAPI.RateLimiting.Enabled = false
|
|
|
|
cfg.FederationAPI.DisableTLSValidation = false
|
2023-01-23 06:17:15 -06:00
|
|
|
cfg.FederationAPI.DisableHTTPKeepalives = true
|
2022-09-01 08:15:41 -05:00
|
|
|
// don't hit matrix.org when running tests!!!
|
|
|
|
cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{}
|
|
|
|
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))
|
2023-07-20 09:06:05 -05:00
|
|
|
cfg.MSCs.MSCs = []string{"msc2836", "msc2444", "msc2753"}
|
2022-09-01 08:15:41 -05:00
|
|
|
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 11:06:49 -05:00
|
|
|
cfg.SyncAPI.Fulltext = config.Fulltext{
|
|
|
|
Enabled: true,
|
2022-09-27 11:10:47 -05:00
|
|
|
IndexPath: config.Path(filepath.Join(*dirPath, "searchindex")),
|
2022-09-27 11:06:49 -05:00
|
|
|
InMemory: true,
|
|
|
|
Language: "en",
|
|
|
|
}
|
2022-09-01 08:15:41 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var err error
|
2023-02-14 05:47:47 -06:00
|
|
|
if cfg, err = config.Load(*normalise); err != nil {
|
2022-09-01 08:15:41 -05:00
|
|
|
panic(err)
|
2022-04-06 06:11:19 -05:00
|
|
|
}
|
2020-09-03 04:12:11 -05:00
|
|
|
}
|
|
|
|
|
2020-08-10 08:18:04 -05:00
|
|
|
j, err := yaml.Marshal(cfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(j))
|
|
|
|
}
|