Add -api flag to monolith (#1044)

* Add flag for enabling HTTP APIs in monolith mode

* Flag -api

* Only start HTTP APIs if needed
This commit is contained in:
Neil Alexander 2020-05-18 10:56:43 +01:00 committed by GitHub
parent bfb954519b
commit dce4f436f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 35 additions and 22 deletions

View file

@ -22,7 +22,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI")
base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -26,7 +26,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "ClientAPI")
base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -54,7 +54,7 @@ type P2PDendrite struct {
// The componentName is used for logging purposes, and should be a friendly name
// of the component running, e.g. SyncAPI.
func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName)
baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName, false)
ctx, cancel := context.WithCancel(context.Background())

View file

@ -23,7 +23,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI")
base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true)
defer func() {
if err := base.Close(); err != nil {
logrus.WithError(err).Warn("BaseDendrite close failed")

View file

@ -25,7 +25,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "FederationAPI")
base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -22,7 +22,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "FederationSender")
base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true)
defer base.Close() // nolint: errcheck
federation := base.CreateFederationClient()

View file

@ -21,7 +21,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "KeyServer")
base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -21,7 +21,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "MediaAPI")
base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true)
defer base.Close() // nolint: errcheck
deviceDB := base.CreateDeviceDB()

View file

@ -41,15 +41,16 @@ 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")
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")
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")
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")
enableHTTPAPIs = flag.Bool("api", false, "Expose internal HTTP APIs in monolith mode")
)
func main() {
cfg := basecomponent.ParseMonolithFlags()
base := basecomponent.NewBaseDendrite(cfg, "Monolith")
base := basecomponent.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -23,7 +23,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI")
base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true)
defer base.Close() // nolint: errcheck
deviceDB := base.CreateDeviceDB()

View file

@ -22,7 +22,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI")
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true)
defer base.Close() // nolint: errcheck
keyDB := base.CreateKeyDB()
federation := base.CreateFederationClient()

View file

@ -21,7 +21,7 @@ import (
func main() {
cfg := basecomponent.ParseFlags()
base := basecomponent.NewBaseDendrite(cfg, "SyncAPI")
base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true)
defer base.Close() // nolint: errcheck
deviceDB := base.CreateDeviceDB()

View file

@ -108,7 +108,7 @@ func main() {
if err := cfg.Derive(); err != nil {
logrus.Fatalf("Failed to derive values from config: %s", err)
}
base := basecomponent.NewBaseDendrite(cfg, "Monolith")
base := basecomponent.NewBaseDendrite(cfg, "Monolith", false)
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()