dendrite/internal/config/config_clientapi.go
Neil Alexander c782197eed
Updates
2020-08-11 09:35:50 +01:00

65 lines
3 KiB
Go

package config
import (
"fmt"
"time"
)
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."`
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."`
RecaptchaPublicKey string `json:"RecaptchaPublicKey" comment:"This server's ReCAPTCHA public key."`
RecaptchaPrivateKey string `json:"RecaptchaPrivateKey" comment:"This server's ReCAPTCHA private key."`
RecaptchaBypassSecret string `json:"RecaptchaBypassSecret" comment:"Secret used to bypass ReCAPTCHA entirely."`
RecaptchaSiteVerifyAPI string `json:"RecaptchaSiteVerifyAPI" comment:"The URL to use for verifying if the ReCAPTCHA response was successful."`
TURN TURN `json:"TURN"`
}
func (c *ClientAPI) Defaults() {
c.Listen = "localhost:7771"
c.Bind = "localhost:7771"
c.RegistrationSharedSecret = ""
c.RecaptchaPublicKey = ""
c.RecaptchaPrivateKey = ""
c.RecaptchaEnabled = false
c.RecaptchaBypassSecret = ""
c.RecaptchaSiteVerifyAPI = ""
c.RegistrationDisabled = false
}
func (c *ClientAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
checkNotEmpty(configErrs, "ClientAPI.Listen", string(c.Listen))
checkNotEmpty(configErrs, "ClientAPI.Bind", string(c.Bind))
if c.RecaptchaEnabled {
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)
}
type TURN struct {
UserLifetime string `json:"UserLifetime" comment:"How long the TURN authorisation should last."`
URIs []string `json:"URIs" comment:"The list of TURN URIs to pass to clients."`
SharedSecret string `json:"SharedSecret" comment:"Authorisation shared secret from coturn."`
Username string `json:"Username" comment:"Authorisation static username."`
Password string `json:"Password" comment:"Authorisation static password."`
// TODO Guest Support
// AllowGuests bool `json:"AllowGuests" comment:"Whether or not guests can request TURN credentials."`
}
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", "ClientAPI.TURN.TURNUserLifetime", value))
}
}
}