From 3bfd5f18ae021ae53a857bdbe2e1a1b50d8e5322 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Fri, 7 Oct 2022 21:32:20 +0200 Subject: [PATCH] Add Monolith config options for HTTP(s) Bind Addresses Signed-off-by: Timo Rothenpieler --- cmd/dendrite-monolith-server/main.go | 14 ++++++++++---- dendrite-sample.monolith.yaml | 6 ++++++ setup/config/config_global.go | 5 +++++ setup/config/config_monolith.go | 22 ++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 setup/config/config_monolith.go diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index ff980dc1c..9740c7517 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -33,8 +33,8 @@ import ( ) var ( - httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") - httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") + httpBindAddr = flag.String("http-bind-address", "", "The HTTP listening port for the server") + httpsBindAddr = flag.String("https-bind-address", "", "The HTTPS listening port for the server") apiBindAddr = flag.String("api-bind-address", "localhost:18008", "The HTTP listening port for the internal HTTP APIs (if -api is enabled)") certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") @@ -44,8 +44,14 @@ var ( func main() { cfg := setup.ParseFlags(true) - httpAddr := config.HTTPAddress("http://" + *httpBindAddr) - httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr) + httpAddr := cfg.Global.Monolith.HTTPBindAddr + httpsAddr := cfg.Global.Monolith.HTTPBindAddr + if *httpBindAddr != "" { + httpAddr = config.HTTPAddress("http://" + *httpBindAddr) + } + if *httpsBindAddr != "" { + httpsAddr = config.HTTPAddress("https://" + *httpsBindAddr) + } httpAPIAddr := httpAddr options := []basepkg.BaseDendriteOptions{} if *enableHTTPAPIs { diff --git a/dendrite-sample.monolith.yaml b/dendrite-sample.monolith.yaml index d86e9da94..d4bf4fe08 100644 --- a/dendrite-sample.monolith.yaml +++ b/dendrite-sample.monolith.yaml @@ -9,6 +9,12 @@ version: 2 # Global Matrix configuration. This configuration applies to all components. global: + # Monolith specific configuration + monolith: + # HTTP and HTTPS bind address + http_bind_address: http://:8008 + https_bind_address: https://:8448 + # The domain name of this homeserver. server_name: localhost diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 801c68450..3ae2d5ad1 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -12,6 +12,9 @@ import ( ) type Global struct { + // Monolith specific configuration options, like bind address. + Monolith Monolith `yaml:"monolith,omitempty"` + // Signing identity contains the server name, private key and key ID of // the deployment. gomatrixserverlib.SigningIdentity `yaml:",inline"` @@ -96,6 +99,7 @@ func (c *Global) Defaults(opts DefaultOpts) { if opts.Monolithic { c.DatabaseOptions.Defaults(90) } + c.Monolith.Defaults(opts) c.JetStream.Defaults(opts) c.Metrics.Defaults(opts) c.DNSCache.Defaults() @@ -113,6 +117,7 @@ func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { v.Verify(configErrs) } + c.Monolith.Verify(configErrs, isMonolith) c.JetStream.Verify(configErrs, isMonolith) c.Metrics.Verify(configErrs, isMonolith) c.Sentry.Verify(configErrs, isMonolith) diff --git a/setup/config/config_monolith.go b/setup/config/config_monolith.go new file mode 100644 index 000000000..e39c39b16 --- /dev/null +++ b/setup/config/config_monolith.go @@ -0,0 +1,22 @@ +package config + +type Monolith struct { + HTTPBindAddr HTTPAddress `yaml:"http_bind_address"` + HTTPSBindAddr HTTPAddress `yaml:"https_bind_address"` +} + +func (c *Monolith) Defaults(opts DefaultOpts) { + if !opts.Monolithic { + return + } + c.HTTPBindAddr = "http://:8008" + c.HTTPSBindAddr = "https://:8448" +} + +func (c *Monolith) Verify(configErrs *ConfigErrors, isMonolith bool) { + if !isMonolith { + return + } + checkURL(configErrs, "monolith.http_bind_address", string(c.HTTPBindAddr)) + checkURL(configErrs, "monolith.https_bind_address", string(c.HTTPSBindAddr)) +}