From ee6bfe24f567d9e065124c5a0dba6f75c2f28331 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 14 Jul 2021 15:22:25 +0100 Subject: [PATCH] Try to sane default on jetstream base path --- cmd/generate-config/main.go | 5 ----- setup/config/config.go | 1 + setup/config/config_jetstream.go | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/generate-config/main.go b/cmd/generate-config/main.go index 52566dc13..bd70cbc5d 100644 --- a/cmd/generate-config/main.go +++ b/cmd/generate-config/main.go @@ -1,8 +1,6 @@ package main import ( - "crypto/rand" - "encoding/hex" "flag" "fmt" @@ -72,9 +70,6 @@ func main() { // don't hit matrix.org when running tests!!! cfg.SigningKeyServer.KeyPerspectives = config.KeyPerspectives{} cfg.UserAPI.BCryptCost = bcrypt.MinCost - var id [8]byte - _, _ = rand.Read(id[:]) - cfg.Global.JetStream.StoragePath = config.Path(hex.EncodeToString(id[:])) } j, err := yaml.Marshal(cfg) diff --git a/setup/config/config.go b/setup/config/config.go index a1fb9593d..0589b5a30 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -329,6 +329,7 @@ func (c *Dendrite) Verify(configErrs *ConfigErrors, isMonolith bool) { } func (c *Dendrite) Wiring() { + c.Global.JetStream.Matrix = &c.Global c.ClientAPI.Matrix = &c.Global c.EDUServer.Matrix = &c.Global c.FederationAPI.Matrix = &c.Global diff --git a/setup/config/config_jetstream.go b/setup/config/config_jetstream.go index 63957cf52..5b1dcdb99 100644 --- a/setup/config/config_jetstream.go +++ b/setup/config/config_jetstream.go @@ -1,8 +1,14 @@ package config -import "fmt" +import ( + "fmt" + "log" + "regexp" +) type JetStream struct { + Matrix *Global `yaml:"-"` + // Persistent directory to store JetStream streams in. StoragePath Path `yaml:"storage_path"` // A list of NATS addresses to connect to. If none are specified, an @@ -22,7 +28,11 @@ func (c *JetStream) TopicFor(name string) string { func (c *JetStream) Defaults() { c.Addresses = []string{} c.TopicPrefix = "Dendrite" - c.StoragePath = Path("./") + reg, err := regexp.Compile(`[^a-zA-Z0-9\.]+`) + if err != nil { + log.Fatal(err) + } + c.StoragePath = Path("./" + reg.ReplaceAllString(string(c.Matrix.ServerName), "")) } func (c *JetStream) Verify(configErrs *ConfigErrors, isMonolith bool) {