mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-06-02 05:52:18 +02:00
Always load backends in the order they are configured.
This commit is contained in:
parent
bef54339e3
commit
f7ed6addb7
|
@ -71,7 +71,7 @@ func NewBackendConfiguration(config *goconf.ConfigFile) (*BackendConfiguration,
|
||||||
compat: true,
|
compat: true,
|
||||||
}
|
}
|
||||||
} else if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
|
} else if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
|
||||||
for host, configuredBackends := range getConfiguredHosts(config) {
|
for host, configuredBackends := range getConfiguredHosts(backendIds, config) {
|
||||||
backends[host] = append(backends[host], configuredBackends...)
|
backends[host] = append(backends[host], configuredBackends...)
|
||||||
for _, be := range configuredBackends {
|
for _, be := range configuredBackends {
|
||||||
log.Printf("Backend %s added for %s", be.id, be.url)
|
log.Printf("Backend %s added for %s", be.id, be.url)
|
||||||
|
@ -146,26 +146,28 @@ func (b *BackendConfiguration) UpsertHost(host string, backends []*Backend) {
|
||||||
b.backends[host] = append(b.backends[host], backends...)
|
b.backends[host] = append(b.backends[host], backends...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfiguredBackendIDs(config *goconf.ConfigFile) (ids map[string]bool) {
|
func getConfiguredBackendIDs(backendIds string) (ids []string) {
|
||||||
ids = make(map[string]bool)
|
seen := make(map[string]bool)
|
||||||
|
|
||||||
if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
|
|
||||||
for _, id := range strings.Split(backendIds, ",") {
|
for _, id := range strings.Split(backendIds, ",") {
|
||||||
id = strings.TrimSpace(id)
|
id = strings.TrimSpace(id)
|
||||||
if id == "" {
|
if id == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ids[id] = true
|
if seen[id] {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
ids = append(ids, id)
|
||||||
|
seen[id] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfiguredHosts(config *goconf.ConfigFile) (hosts map[string][]*Backend) {
|
func getConfiguredHosts(backendIds string, config *goconf.ConfigFile) (hosts map[string][]*Backend) {
|
||||||
hosts = make(map[string][]*Backend)
|
hosts = make(map[string][]*Backend)
|
||||||
for id := range getConfiguredBackendIDs(config) {
|
for _, id := range getConfiguredBackendIDs(backendIds) {
|
||||||
u, _ := config.GetString(id, "url")
|
u, _ := config.GetString(id, "url")
|
||||||
if u == "" {
|
if u == "" {
|
||||||
log.Printf("Backend %s is missing or incomplete, skipping", id)
|
log.Printf("Backend %s is missing or incomplete, skipping", id)
|
||||||
|
@ -199,7 +201,7 @@ func getConfiguredHosts(config *goconf.ConfigFile) (hosts map[string][]*Backend)
|
||||||
|
|
||||||
func (b *BackendConfiguration) Reload(config *goconf.ConfigFile) {
|
func (b *BackendConfiguration) Reload(config *goconf.ConfigFile) {
|
||||||
if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
|
if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
|
||||||
configuredHosts := getConfiguredHosts(config)
|
configuredHosts := getConfiguredHosts(backendIds, config)
|
||||||
|
|
||||||
// remove backends that are no longer configured
|
// remove backends that are no longer configured
|
||||||
for hostname := range b.backends {
|
for hostname := range b.backends {
|
||||||
|
|
|
@ -165,6 +165,30 @@ func TestIsUrlAllowed_AllowAll(t *testing.T) {
|
||||||
testUrls(t, cfg, valid_urls, invalid_urls)
|
testUrls(t, cfg, valid_urls, invalid_urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ParseBackendIdsTestcase struct {
|
||||||
|
s string
|
||||||
|
ids []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseBackendIds(t *testing.T) {
|
||||||
|
testcases := []ParseBackendIdsTestcase{
|
||||||
|
ParseBackendIdsTestcase{"", nil},
|
||||||
|
ParseBackendIdsTestcase{"backend1", []string{"backend1"}},
|
||||||
|
ParseBackendIdsTestcase{" backend1 ", []string{"backend1"}},
|
||||||
|
ParseBackendIdsTestcase{"backend1,", []string{"backend1"}},
|
||||||
|
ParseBackendIdsTestcase{"backend1,backend1", []string{"backend1"}},
|
||||||
|
ParseBackendIdsTestcase{"backend1, backend2", []string{"backend1", "backend2"}},
|
||||||
|
ParseBackendIdsTestcase{"backend1,backend2, backend1", []string{"backend1", "backend2"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testcases {
|
||||||
|
ids := getConfiguredBackendIDs(test.s)
|
||||||
|
if !reflect.DeepEqual(ids, test.ids) {
|
||||||
|
t.Errorf("List of ids differs, expected %+v, got %+v", test.ids, ids)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackendReloadChangeExistingURL(t *testing.T) {
|
func TestBackendReloadChangeExistingURL(t *testing.T) {
|
||||||
original_config := goconf.NewConfigFile()
|
original_config := goconf.NewConfigFile()
|
||||||
original_config.AddOption("backend", "backends", "backend1, backend2")
|
original_config.AddOption("backend", "backends", "backend1, backend2")
|
||||||
|
|
Loading…
Reference in a new issue