mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-14 18:33:09 -06:00
Clean things up and fix yaml declaration
This commit is contained in:
parent
be44e13efd
commit
e015f1410b
|
|
@ -60,7 +60,7 @@ type ApplicationService struct {
|
||||||
// "users", "aliases" or "rooms"
|
// "users", "aliases" or "rooms"
|
||||||
NamespaceMap map[string][]ApplicationServiceNamespace `yaml:"namespaces"`
|
NamespaceMap map[string][]ApplicationServiceNamespace `yaml:"namespaces"`
|
||||||
// Whether rate limiting is applied to each application service user
|
// Whether rate limiting is applied to each application service user
|
||||||
RateLimited bool `yaml:"rate_limited`
|
RateLimited bool `yaml:"rate_limited"`
|
||||||
// Any custom protocols that this application service provides (e.g. IRC)
|
// Any custom protocols that this application service provides (e.g. IRC)
|
||||||
Protocols []string `yaml:"protocols"`
|
Protocols []string `yaml:"protocols"`
|
||||||
}
|
}
|
||||||
|
|
@ -173,18 +173,30 @@ func checkErrors(config *Dendrite) (err error) {
|
||||||
var idMap = make(map[string]bool)
|
var idMap = make(map[string]bool)
|
||||||
var tokenMap = make(map[string]bool)
|
var tokenMap = make(map[string]bool)
|
||||||
|
|
||||||
|
// Compile regexp object for checking groupIDs
|
||||||
|
groupIDRegexp := regexp.MustCompile(`\+.*:.*`)
|
||||||
|
|
||||||
// Check each application service for any config errors
|
// Check each application service for any config errors
|
||||||
for _, appservice := range config.Derived.ApplicationServices {
|
for _, appservice := range config.Derived.ApplicationServices {
|
||||||
// Check if GroupID is in the correct format
|
// Check that namespace(s) are valid regex
|
||||||
for _, userNamespace := range appservice.NamespaceMap["users"] {
|
for key, namespaceSlice := range appservice.NamespaceMap {
|
||||||
if userNamespace.GroupID != "" {
|
for _, namespace := range namespaceSlice {
|
||||||
correctFormat, err := regexp.MatchString("\\+.*:.*", userNamespace.GroupID)
|
if !IsValidRegex(namespace.Regex) {
|
||||||
if err != nil || !correctFormat {
|
|
||||||
return configErrors([]string{fmt.Sprintf(
|
return configErrors([]string{fmt.Sprintf(
|
||||||
"Invalid user group_id field for application service %s.",
|
"Invalid regex string for Application Service %s", appservice.ID,
|
||||||
appservice.ID,
|
|
||||||
)})
|
)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if GroupID for the users namespace is in the correct format
|
||||||
|
if key == "users" && namespace.GroupID != "" {
|
||||||
|
correctFormat := groupIDRegexp.MatchString(namespace.GroupID)
|
||||||
|
if !correctFormat {
|
||||||
|
return configErrors([]string{fmt.Sprintf(
|
||||||
|
"Invalid user group_id field for application service %s.",
|
||||||
|
appservice.ID,
|
||||||
|
)})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,19 +232,6 @@ func checkErrors(config *Dendrite) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that namespace(s) are valid regex
|
|
||||||
for _, appservice := range config.Derived.ApplicationServices {
|
|
||||||
for _, namespaceSlice := range appservice.NamespaceMap {
|
|
||||||
for _, namespace := range namespaceSlice {
|
|
||||||
if !IsValidRegex(namespace.Regex) {
|
|
||||||
return configErrors([]string{fmt.Sprintf(
|
|
||||||
"Invalid regex string for Application Service %s", appservice.ID,
|
|
||||||
)})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return setupRegexps(config)
|
return setupRegexps(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue