Add a method for getting RoomServerURL

This moves the hardcoding of HTTPs into one place.
This commit is contained in:
Mark Haines 2017-06-19 14:31:06 +01:00
parent c205b14c92
commit 5c21bf5781
4 changed files with 13 additions and 12 deletions

View file

@ -61,11 +61,7 @@ func main() {
cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey,
) )
// Hard code the roomserver to talk HTTP for now. queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil)
// If we support HTTPS we need to think of a practical way to do certificate validation.
// People setting up servers shouldn't need to get a certificate valid for the public
// internet for an internal API.
queryAPI := api.NewRoomserverQueryAPIHTTP("http://"+string(cfg.Listen.RoomServer), nil)
accountDB, err := accounts.NewDatabase(string(cfg.Database.Account), cfg.Matrix.ServerName) accountDB, err := accounts.NewDatabase(string(cfg.Database.Account), cfg.Matrix.ServerName)
if err != nil { if err != nil {
log.Panicf("Failed to setup account database(%q): %s", cfg.Database.Account, err.Error()) log.Panicf("Failed to setup account database(%q): %s", cfg.Database.Account, err.Error())

View file

@ -63,11 +63,7 @@ func main() {
KeyDatabase: keyDB, KeyDatabase: keyDB,
} }
// Hard code the roomserver to talk HTTP for now. queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil)
// If we support HTTPS we need to think of a practical way to do certificate validation.
// People setting up servers shouldn't need to get a certificate valid for the public
// internet for an internal API.
queryAPI := api.NewRoomserverQueryAPIHTTP("http://"+string(cfg.Listen.RoomServer), nil)
roomserverProducer, err := producers.NewRoomserverProducer( roomserverProducer, err := producers.NewRoomserverProducer(
cfg.Kafka.Addresses, string(cfg.Kafka.Topics.InputRoomEvent), cfg.Kafka.Addresses, string(cfg.Kafka.Topics.InputRoomEvent),

View file

@ -358,3 +358,12 @@ func fingerprintPEM(data []byte) *gomatrixserverlib.TLSFingerprint {
} }
} }
} }
// RoomServerURL returns an HTTP URL for where the roomserver is listening.
func (config *Dendrite) RoomServerURL() string {
// Hard code the roomserver to talk HTTP for now.
// If we support HTTPS we need to think of a practical way to do certificate validation.
// People setting up servers shouldn't need to get a certificate valid for the public
// internet for an internal API.
return "http://" + string(config.Listen.RoomServer)
}

View file

@ -43,7 +43,7 @@ func NewOutputRoomEvent(cfg *config.Dendrite, n *sync.Notifier, store *storage.S
if err != nil { if err != nil {
return nil, err return nil, err
} }
roomserverURL := "http://" + string(cfg.Listen.RoomServer) roomServerURL := cfg.RoomServerURL()
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
@ -54,7 +54,7 @@ func NewOutputRoomEvent(cfg *config.Dendrite, n *sync.Notifier, store *storage.S
roomServerConsumer: &consumer, roomServerConsumer: &consumer,
db: store, db: store,
notifier: n, notifier: n,
query: api.NewRoomserverQueryAPIHTTP(roomserverURL, nil), query: api.NewRoomserverQueryAPIHTTP(roomServerURL, nil),
} }
consumer.ProcessMessage = s.onMessage consumer.ProcessMessage = s.onMessage