From 0069aee42645706bb596a44d0734b52c3c0dc949 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 4 Jun 2020 16:36:41 +0100 Subject: [PATCH] Remove ParseMonolith/LoadMonolith --- cmd/dendrite-appservice-server/main.go | 2 +- cmd/dendrite-client-api-server/main.go | 2 +- cmd/dendrite-edu-server/main.go | 2 +- cmd/dendrite-federation-api-server/main.go | 2 +- cmd/dendrite-federation-sender-server/main.go | 2 +- cmd/dendrite-key-server/main.go | 2 +- cmd/dendrite-media-api-server/main.go | 2 +- cmd/dendrite-monolith-server/main.go | 2 +- cmd/dendrite-public-rooms-api-server/main.go | 2 +- cmd/dendrite-room-server/main.go | 2 +- cmd/dendrite-server-key-api-server/main.go | 2 +- cmd/dendrite-sync-api-server/main.go | 2 +- internal/basecomponent/flags.go | 23 ++------------- internal/config/config.go | 28 ++----------------- 14 files changed, 17 insertions(+), 58 deletions(-) diff --git a/cmd/dendrite-appservice-server/main.go b/cmd/dendrite-appservice-server/main.go index c16505fd8..4fc2a173d 100644 --- a/cmd/dendrite-appservice-server/main.go +++ b/cmd/dendrite-appservice-server/main.go @@ -21,7 +21,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-client-api-server/main.go b/cmd/dendrite-client-api-server/main.go index 2eec84ab8..1304a7fde 100644 --- a/cmd/dendrite-client-api-server/main.go +++ b/cmd/dendrite-client-api-server/main.go @@ -23,7 +23,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-edu-server/main.go b/cmd/dendrite-edu-server/main.go index ca0460f8d..ceeb13658 100644 --- a/cmd/dendrite-edu-server/main.go +++ b/cmd/dendrite-edu-server/main.go @@ -22,7 +22,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true) defer func() { if err := base.Close(); err != nil { diff --git a/cmd/dendrite-federation-api-server/main.go b/cmd/dendrite-federation-api-server/main.go index 604dd4e3d..dec30fe61 100644 --- a/cmd/dendrite-federation-api-server/main.go +++ b/cmd/dendrite-federation-api-server/main.go @@ -23,7 +23,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-federation-sender-server/main.go b/cmd/dendrite-federation-sender-server/main.go index aeaa837d1..a1dc7dba7 100644 --- a/cmd/dendrite-federation-sender-server/main.go +++ b/cmd/dendrite-federation-sender-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-key-server/main.go b/cmd/dendrite-key-server/main.go index 17fee2c64..a8accbcb3 100644 --- a/cmd/dendrite-key-server/main.go +++ b/cmd/dendrite-key-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-media-api-server/main.go b/cmd/dendrite-media-api-server/main.go index 1a51717a7..018559383 100644 --- a/cmd/dendrite-media-api-server/main.go +++ b/cmd/dendrite-media-api-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 78919f2b6..57e8f66f5 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -49,7 +49,7 @@ var ( ) func main() { - cfg := basecomponent.ParseMonolithFlags() + cfg := basecomponent.ParseFlags(true) if *enableHTTPAPIs { // If the HTTP APIs are enabled then we need to update the Listen // statements in the configuration so that we know where to find diff --git a/cmd/dendrite-public-rooms-api-server/main.go b/cmd/dendrite-public-rooms-api-server/main.go index 18a813baf..f5443c194 100644 --- a/cmd/dendrite-public-rooms-api-server/main.go +++ b/cmd/dendrite-public-rooms-api-server/main.go @@ -22,7 +22,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-room-server/main.go b/cmd/dendrite-room-server/main.go index 65a1e9ae5..79745cded 100644 --- a/cmd/dendrite-room-server/main.go +++ b/cmd/dendrite-room-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true) defer base.Close() // nolint: errcheck federation := base.CreateFederationClient() diff --git a/cmd/dendrite-server-key-api-server/main.go b/cmd/dendrite-server-key-api-server/main.go index 075734125..e206978cd 100644 --- a/cmd/dendrite-server-key-api-server/main.go +++ b/cmd/dendrite-server-key-api-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "ServerKeyAPI", true) defer base.Close() // nolint: errcheck diff --git a/cmd/dendrite-sync-api-server/main.go b/cmd/dendrite-sync-api-server/main.go index eeab115a9..bb56b4ab0 100644 --- a/cmd/dendrite-sync-api-server/main.go +++ b/cmd/dendrite-sync-api-server/main.go @@ -20,7 +20,7 @@ import ( ) func main() { - cfg := basecomponent.ParseFlags() + cfg := basecomponent.ParseFlags(false) base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true) defer base.Close() // nolint: errcheck diff --git a/internal/basecomponent/flags.go b/internal/basecomponent/flags.go index ecef81f6b..117df0796 100644 --- a/internal/basecomponent/flags.go +++ b/internal/basecomponent/flags.go @@ -25,33 +25,14 @@ import ( var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.") // ParseFlags parses the commandline flags and uses them to create a config. -// If running as a monolith use `ParseMonolithFlags` instead. -func ParseFlags() *config.Dendrite { +func ParseFlags(monolith bool) *config.Dendrite { flag.Parse() if *configPath == "" { logrus.Fatal("--config must be supplied") } - cfg, err := config.Load(*configPath) - - if err != nil { - logrus.Fatalf("Invalid config file: %s", err) - } - - return cfg -} - -// ParseMonolithFlags parses the commandline flags and uses them to create a -// config. Should only be used if running a monolith. See `ParseFlags`. -func ParseMonolithFlags() *config.Dendrite { - flag.Parse() - - if *configPath == "" { - logrus.Fatal("--config must be supplied") - } - - cfg, err := config.LoadMonolithic(*configPath) + cfg, err := config.Load(*configPath, monolith) if err != nil { logrus.Fatalf("Invalid config file: %s", err) diff --git a/internal/config/config.go b/internal/config/config.go index 597995855..858646ab0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -370,11 +370,9 @@ type LogrusHook struct { // It implements the error interface. type configErrors []string -// Load a yaml config file for a server run as multiple processes. +// Load a yaml config file for a server run as multiple processes or as a monolith. // Checks the config to ensure that it is valid. -// The checks are different if the server is run as a monolithic process instead -// of being split into multiple components -func Load(configPath string) (*Dendrite, error) { +func Load(configPath string, monolith bool) (*Dendrite, error) { configData, err := ioutil.ReadFile(configPath) if err != nil { return nil, err @@ -385,27 +383,7 @@ func Load(configPath string) (*Dendrite, error) { } // Pass the current working directory and ioutil.ReadFile so that they can // be mocked in the tests - monolithic := false - return loadConfig(basePath, configData, ioutil.ReadFile, monolithic) -} - -// LoadMonolithic loads a yaml config file for a server run as a single monolith. -// Checks the config to ensure that it is valid. -// The checks are different if the server is run as a monolithic process instead -// of being split into multiple components -func LoadMonolithic(configPath string) (*Dendrite, error) { - configData, err := ioutil.ReadFile(configPath) - if err != nil { - return nil, err - } - basePath, err := filepath.Abs(".") - if err != nil { - return nil, err - } - // Pass the current working directory and ioutil.ReadFile so that they can - // be mocked in the tests - monolithic := true - return loadConfig(basePath, configData, ioutil.ReadFile, monolithic) + return loadConfig(basePath, configData, ioutil.ReadFile, monolith) } func loadConfig(