aboutsummaryrefslogtreecommitdiff
path: root/cmd/generate-config/main.go
blob: ff91e753f99f6ec1fe05d15875729ac3477cd08b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main

import (
	"flag"
	"fmt"

	"github.com/matrix-org/dendrite/setup/config"
	"github.com/matrix-org/gomatrixserverlib"
	"golang.org/x/crypto/bcrypt"
	"gopkg.in/yaml.v2"
)

func main() {
	defaultsForCI := flag.Bool("ci", false, "sane defaults for CI testing")
	serverName := flag.String("server", "", "The domain name of the server if not 'localhost'")
	dbURI := flag.String("db", "", "The DB URI to use for all components if not SQLite files")
	flag.Parse()

	cfg := &config.Dendrite{}
	cfg.Defaults(true)
	if *serverName != "" {
		cfg.Global.ServerName = gomatrixserverlib.ServerName(*serverName)
	}
	if *dbURI != "" {
		cfg.Global.Kafka.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.AppServiceAPI.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.FederationAPI.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.KeyServer.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.MSCs.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.MediaAPI.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.RoomServer.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.SyncAPI.Database.ConnectionString = config.DataSource(*dbURI)
		cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(*dbURI)
		cfg.UserAPI.DeviceDatabase.ConnectionString = config.DataSource(*dbURI)
	}
	cfg.Global.TrustedIDServers = []string{
		"matrix.org",
		"vector.im",
	}
	cfg.Logging = []config.LogrusHook{
		{
			Type:  "file",
			Level: "info",
			Params: map[string]interface{}{
				"path": "/var/log/dendrite",
			},
		},
	}
	cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{
		{
			ServerName: "matrix.org",
			Keys: []config.KeyPerspectiveTrustKey{
				{
					KeyID:     "ed25519:auto",
					PublicKey: "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw",
				},
				{
					KeyID:     "ed25519:a_RXGa",
					PublicKey: "l8Hft5qXKn1vfHrg3p4+W8gELQVo8N13JkluMfmn2sQ",
				},
			},
		},
	}
	cfg.MediaAPI.ThumbnailSizes = []config.ThumbnailSize{
		{
			Width:        32,
			Height:       32,
			ResizeMethod: "crop",
		},
		{
			Width:        96,
			Height:       96,
			ResizeMethod: "crop",
		},
		{
			Width:        640,
			Height:       480,
			ResizeMethod: "scale",
		},
	}

	if *defaultsForCI {
		cfg.AppServiceAPI.DisableTLSValidation = true
		cfg.ClientAPI.RateLimiting.Enabled = false
		cfg.FederationAPI.DisableTLSValidation = true
		// don't hit matrix.org when running tests!!!
		cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{}
		cfg.MSCs.MSCs = []string{"msc2836", "msc2946", "msc2444", "msc2753"}
		cfg.Logging[0].Level = "trace"
		cfg.UserAPI.BCryptCost = bcrypt.MinCost
	}

	j, err := yaml.Marshal(cfg)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(j))
}