diff --git a/cmd/mediaapi-integration-tests/main.go b/cmd/mediaapi-integration-tests/main.go index 4c584979c..c867a7126 100644 --- a/cmd/mediaapi-integration-tests/main.go +++ b/cmd/mediaapi-integration-tests/main.go @@ -24,9 +24,9 @@ import ( "path/filepath" "time" + "github.com/hjson/hjson-go" "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/gomatrixserverlib" - "gopkg.in/yaml.v2" ) var ( @@ -45,22 +45,32 @@ var ( kafkaURI = test.Defaulting(os.Getenv("KAFKA_URIS"), "localhost:9092") ) -var thumbnailSizes = (` -- width: 32 - height: 32 - method: crop -- width: 96 - height: 96 - method: crop -- width: 320 - height: 240 - method: scale -- width: 640 - height: 480 - method: scale -- width: 800 - height: 600 - method: scale +var thumbnailSizes = (`[ +{ + Width: 32 + Height: 32 + Method: crop +} +{ + Width: 96 + Height: 96 + Method: crop +} +{ + Width: 320 + Height: 240 + Method: scale +} +{ + Width: 640 + Height: 480 + Method: scale +} +{ + Width: 800 + Height: 600 + Method: scale +} `) const serverType = "media-api" @@ -90,7 +100,7 @@ func startMediaAPI(suffix string, dynamicThumbnails bool) (*exec.Cmd, chan error } cfg.Global.ServerName = gomatrixserverlib.ServerName(proxyAddr) cfg.MediaAPI.DynamicThumbnails = dynamicThumbnails - if err = yaml.Unmarshal([]byte(thumbnailSizes), &cfg.MediaAPI.ThumbnailSizes); err != nil { + if err = hjson.Unmarshal([]byte(thumbnailSizes), &cfg.MediaAPI.ThumbnailSizes); err != nil { panic(err) } diff --git a/internal/config/config.go b/internal/config/config.go index 38b84e8b5..10f3af7eb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,11 +25,11 @@ import ( "regexp" "strings" + "github.com/hjson/hjson-go" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" "golang.org/x/crypto/ed25519" - yaml "gopkg.in/yaml.v2" jaegerconfig "github.com/uber/jaeger-client-go/config" jaegermetrics "github.com/uber/jaeger-lib/metrics" @@ -191,7 +191,7 @@ func loadConfig( c.Defaults() var err error - if err = yaml.Unmarshal(configData, &c); err != nil { + if err = hjson.Unmarshal(configData, &c); err != nil { return nil, err } diff --git a/internal/config/config_appservice.go b/internal/config/config_appservice.go index 68845fb57..183b4b6ed 100644 --- a/internal/config/config_appservice.go +++ b/internal/config/config_appservice.go @@ -43,9 +43,9 @@ func (c *AppServiceAPI) Defaults() { } func (c *AppServiceAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "app_service_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "app_service_api.bind", string(c.Bind)) - checkNotEmpty(configErrs, "app_service_api.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "AppServiceAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "AppServiceAPI.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "AppServiceAPI.Database.ConnectionString", string(c.Database.ConnectionString)) } // ApplicationServiceNamespace is the namespace that a specific application diff --git a/internal/config/config_clientapi.go b/internal/config/config_clientapi.go index aadf06aea..9ca4e3fda 100644 --- a/internal/config/config_clientapi.go +++ b/internal/config/config_clientapi.go @@ -9,8 +9,8 @@ type ClientAPI struct { Matrix *Global `json:"-"` Derived *Derived `json:"-"` // TODO: Nuke Derived from orbit - Listen Address `json:"listen" comment:"The listen address for this component."` - Bind Address `json:"bind" comment:"The bind address for this component."` + Listen Address `json:"Listen" comment:"The listen address for this component."` + Bind Address `json:"Bind" comment:"The bind address for this component."` RegistrationDisabled bool `json:"RegistrationDisabled" comment:"Prevent new users from registering, except when using the shared secret from the\nRegistrationSharedSecret option below."` RegistrationSharedSecret string `json:"RegistrationSharedSecret" comment:"If set, allows registration by anyone who knows the shared secret, even if\nregistration is otherwise disabled."` RecaptchaEnabled bool `json:"RecaptchaEnabled" comment:"Whether to require ReCAPTCHA for registration."` @@ -34,12 +34,12 @@ func (c *ClientAPI) Defaults() { } func (c *ClientAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "client_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "client_api.bind", string(c.Bind)) + checkNotEmpty(configErrs, "ClientAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "ClientAPI.Bind", string(c.Bind)) if c.RecaptchaEnabled { - checkNotEmpty(configErrs, "client_api.recaptcha_public_key", string(c.RecaptchaPublicKey)) - checkNotEmpty(configErrs, "client_api.recaptcha_private_key", string(c.RecaptchaPrivateKey)) - checkNotEmpty(configErrs, "client_api.recaptcha_siteverify_api", string(c.RecaptchaSiteVerifyAPI)) + checkNotEmpty(configErrs, "ClientAPI.RecaptchaPublicKey", string(c.RecaptchaPublicKey)) + checkNotEmpty(configErrs, "ClientAPI.RecaptchaPrivateKey", string(c.RecaptchaPrivateKey)) + checkNotEmpty(configErrs, "ClientAPI.RecaptchaSiteVerifyAPI", string(c.RecaptchaSiteVerifyAPI)) } c.TURN.Verify(configErrs) } @@ -58,7 +58,7 @@ func (c *TURN) Verify(configErrs *ConfigErrors) { value := c.UserLifetime if value != "" { if _, err := time.ParseDuration(value); err != nil { - configErrs.Add(fmt.Sprintf("invalid duration for config key %q: %s", "client_api.turn.turn_user_lifetime", value)) + configErrs.Add(fmt.Sprintf("invalid duration for config key %q: %s", "ClientAPI.TURN.TURNUserLifetime", value)) } } } diff --git a/internal/config/config_currentstate.go b/internal/config/config_currentstate.go index 2f47b19e9..f250bb35d 100644 --- a/internal/config/config_currentstate.go +++ b/internal/config/config_currentstate.go @@ -3,8 +3,8 @@ package config type CurrentStateServer struct { Matrix *Global `json:"-"` - Listen Address `json:"listen" comment:"Listen address for this component."` - Bind Address `json:"bind" comment:"Bind address for this component."` + Listen Address `json:"Listen" comment:"Listen address for this component."` + Bind Address `json:"Bind" comment:"Bind address for this component."` Database DatabaseOptions `json:"Database" comment:"Database configuration for this component."` } @@ -16,7 +16,7 @@ func (c *CurrentStateServer) Defaults() { } func (c *CurrentStateServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "current_state_server.listen", string(c.Listen)) - checkNotEmpty(configErrs, "current_state_server.bind", string(c.Bind)) - checkNotEmpty(configErrs, "current_state_server.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "CurrentStateServer.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "CurrentStateServer.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "CurrentStateServer.Database.ConnectionString", string(c.Database.ConnectionString)) } diff --git a/internal/config/config_eduserver.go b/internal/config/config_eduserver.go index c8001c778..cdb352ec7 100644 --- a/internal/config/config_eduserver.go +++ b/internal/config/config_eduserver.go @@ -13,6 +13,6 @@ func (c *EDUServer) Defaults() { } func (c *EDUServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "edu_server.listen", string(c.Listen)) - checkNotEmpty(configErrs, "edu_server.bind", string(c.Bind)) + checkNotEmpty(configErrs, "EDUServer.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "EDUServer.Bind", string(c.Bind)) } diff --git a/internal/config/config_federationapi.go b/internal/config/config_federationapi.go index e7dfbf76c..7fc3b6da1 100644 --- a/internal/config/config_federationapi.go +++ b/internal/config/config_federationapi.go @@ -17,8 +17,8 @@ func (c *FederationAPI) Defaults() { } func (c *FederationAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "federation_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "federation_api.bind", string(c.Bind)) + checkNotEmpty(configErrs, "FederationAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "FederationAPI.Bind", string(c.Bind)) // TODO: not applicable always, e.g. in demos - //checkNotZero(configErrs, "federation_api.federation_certificates", int64(len(c.FederationCertificatePaths))) + //checkNotZero(configErrs, "FederationAPI.FederationCertificates", int64(len(c.FederationCertificatePaths))) } diff --git a/internal/config/config_federationsender.go b/internal/config/config_federationsender.go index 973c05148..819dccf31 100644 --- a/internal/config/config_federationsender.go +++ b/internal/config/config_federationsender.go @@ -24,9 +24,9 @@ func (c *FederationSender) Defaults() { } func (c *FederationSender) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "federation_sender.listen", string(c.Listen)) - checkNotEmpty(configErrs, "federation_sender.bind", string(c.Bind)) - checkNotEmpty(configErrs, "federation_sender.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "FederationSender.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "FederationSender.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "FederationSender.Database.ConnectionString", string(c.Database.ConnectionString)) } // The config for setting a proxy to use for server->server requests diff --git a/internal/config/config_global.go b/internal/config/config_global.go index ccbfb9c34..1b69c828d 100644 --- a/internal/config/config_global.go +++ b/internal/config/config_global.go @@ -31,8 +31,8 @@ func (c *Global) Defaults() { } func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "global.server_name", string(c.ServerName)) - checkNotEmpty(configErrs, "global.private_key", string(c.PrivateKeyPath)) + checkNotEmpty(configErrs, "Global.ServerName", string(c.ServerName)) + checkNotEmpty(configErrs, "Global.PrivateKeyPath", string(c.PrivateKeyPath)) c.Kafka.Verify(configErrs, isMonolith) c.Metrics.Verify(configErrs, isMonolith) diff --git a/internal/config/config_kafka.go b/internal/config/config_kafka.go index 4980d551f..9bc2e31b4 100644 --- a/internal/config/config_kafka.go +++ b/internal/config/config_kafka.go @@ -13,7 +13,7 @@ const ( type Kafka struct { Addresses []string `json:"Addresses" comment:"List of Kafka addresses to connect to."` - TopicPrefix string `json:"topic_prefix" comment:"The prefix to use for Kafka topic names for this homeserver. Change this only if\nyou are running more than one Dendrite homeserver on the same Kafka deployment."` + TopicPrefix string `json:"TopicPrefix" comment:"The prefix to use for Kafka topic names for this homeserver. Change this only if\nyou are running more than one Dendrite homeserver on the same Kafka deployment."` UseNaffka bool `json:"UseNaffka" comment:"Whether to use Naffka instead of Kafka. Only available in monolith mode."` Database DatabaseOptions `json:"NaffkaDatabase" comment:"Naffka database options. Not required when using Kafka."` } @@ -34,11 +34,11 @@ func (c *Kafka) Verify(configErrs *ConfigErrors, isMonolith bool) { if !isMonolith { configErrs.Add("naffka can only be used in a monolithic server") } - checkNotEmpty(configErrs, "global.kafka.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "Global.Kafka.Database.ConnectionString", string(c.Database.ConnectionString)) } else { // If we aren't using naffka then we need to have at least one kafka // server to talk to. - checkNotZero(configErrs, "global.kafka.addresses", int64(len(c.Addresses))) + checkNotZero(configErrs, "Global.Kafka.Addresses", int64(len(c.Addresses))) } - checkNotEmpty(configErrs, "global.kafka.topic_prefix", string(c.TopicPrefix)) + checkNotEmpty(configErrs, "Global.Kafka.TopicPrefix", string(c.TopicPrefix)) } diff --git a/internal/config/config_keyserver.go b/internal/config/config_keyserver.go index ad0f80af5..2e6c42484 100644 --- a/internal/config/config_keyserver.go +++ b/internal/config/config_keyserver.go @@ -16,7 +16,7 @@ func (c *KeyServer) Defaults() { } func (c *KeyServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "key_server.listen", string(c.Listen)) - checkNotEmpty(configErrs, "key_server.bind", string(c.Bind)) - checkNotEmpty(configErrs, "key_server.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "KeyServer.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "KeyServer.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "KeyServer.Database.ConnectionString", string(c.Database.ConnectionString)) } diff --git a/internal/config/config_mediaapi.go b/internal/config/config_mediaapi.go index 9170a8408..b6af91cb8 100644 --- a/internal/config/config_mediaapi.go +++ b/internal/config/config_mediaapi.go @@ -31,16 +31,16 @@ func (c *MediaAPI) Defaults() { } func (c *MediaAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "media_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "media_api.bind", string(c.Bind)) - checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "MediaAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "MediaAPI.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "MediaAPI.Database.ConnectionString", string(c.Database.ConnectionString)) - checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath)) - checkPositive(configErrs, "media_api.max_file_size_bytes", int64(*c.MaxFileSizeBytes)) - checkPositive(configErrs, "media_api.max_thumbnail_generators", int64(c.MaxThumbnailGenerators)) + checkNotEmpty(configErrs, "MediaAPI.BasePath", string(c.BasePath)) + checkPositive(configErrs, "MediaAPI.MaxFileSizeBytes", int64(*c.MaxFileSizeBytes)) + checkPositive(configErrs, "MediaAPI.MaxThumbnailGenerators", int64(c.MaxThumbnailGenerators)) for i, size := range c.ThumbnailSizes { - checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].width", i), int64(size.Width)) - checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].height", i), int64(size.Height)) + checkPositive(configErrs, fmt.Sprintf("MediaAPI.ThumbnailSizes[%d].Width", i), int64(size.Width)) + checkPositive(configErrs, fmt.Sprintf("MediaAPI.ThumbnailSizes[%d].Height", i), int64(size.Height)) } } diff --git a/internal/config/config_roomserver.go b/internal/config/config_roomserver.go index 42f858767..268fa86e6 100644 --- a/internal/config/config_roomserver.go +++ b/internal/config/config_roomserver.go @@ -16,7 +16,7 @@ func (c *RoomServer) Defaults() { } func (c *RoomServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "room_server.listen", string(c.Listen)) - checkNotEmpty(configErrs, "room_server.bind", string(c.Bind)) - checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "RoomServer.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "RoomServer.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "RoomServer.Database.ConnectionString", string(c.Database.ConnectionString)) } diff --git a/internal/config/config_serverkey.go b/internal/config/config_serverkey.go index 9ce315502..3e3437aab 100644 --- a/internal/config/config_serverkey.go +++ b/internal/config/config_serverkey.go @@ -19,9 +19,9 @@ func (c *ServerKeyAPI) Defaults() { } func (c *ServerKeyAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "server_key_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "server_key_api.bind", string(c.Bind)) - checkNotEmpty(configErrs, "server_key_api.database.connection_string", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "ServerKeyAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "ServerKeyAPI.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "ServerKeyAPI.Database.ConnectionString", string(c.Database.ConnectionString)) } // KeyPerspectives are used to configure perspective key servers for diff --git a/internal/config/config_syncapi.go b/internal/config/config_syncapi.go index a2d06aabd..e608cbd84 100644 --- a/internal/config/config_syncapi.go +++ b/internal/config/config_syncapi.go @@ -16,7 +16,7 @@ func (c *SyncAPI) Defaults() { } func (c *SyncAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "sync_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "sync_api.bind", string(c.Bind)) - checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString)) + checkNotEmpty(configErrs, "SyncAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "SyncAPI.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "SyncAPI.Database.ConnectionString", string(c.Database.ConnectionString)) } diff --git a/internal/config/config_userapi.go b/internal/config/config_userapi.go index f01eaf97b..4d117d5d2 100644 --- a/internal/config/config_userapi.go +++ b/internal/config/config_userapi.go @@ -19,8 +19,8 @@ func (c *UserAPI) Defaults() { } func (c *UserAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - checkNotEmpty(configErrs, "user_api.listen", string(c.Listen)) - checkNotEmpty(configErrs, "user_api.bind", string(c.Bind)) - checkNotEmpty(configErrs, "user_api.account_database.connection_string", string(c.AccountDatabase.ConnectionString)) - checkNotEmpty(configErrs, "user_api.device_database.connection_string", string(c.DeviceDatabase.ConnectionString)) + checkNotEmpty(configErrs, "UserAPI.Listen", string(c.Listen)) + checkNotEmpty(configErrs, "UserAPI.Bind", string(c.Bind)) + checkNotEmpty(configErrs, "UserAPI.AccountDatabase.ConnectionString", string(c.AccountDatabase.ConnectionString)) + checkNotEmpty(configErrs, "UserAPI.DeviceDatabase.ConnectionString", string(c.DeviceDatabase.ConnectionString)) }