39 lines
840 B
Go
39 lines
840 B
Go
package automation
|
|
|
|
import "strings"
|
|
|
|
// matchProxies filters proxies down to those satisfying every non-empty
|
|
// dimension of m.
|
|
func matchProxies(proxies []ProxyRef, m MatchRule) []ProxyRef {
|
|
var out []ProxyRef
|
|
for _, p := range proxies {
|
|
if len(m.Subscriptions) > 0 && !containsFold(m.Subscriptions, p.Subscription) {
|
|
continue
|
|
}
|
|
if len(m.NameContains) > 0 && !anyContainsFold(m.NameContains, p.OriginalName) {
|
|
continue
|
|
}
|
|
out = append(out, p)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func containsFold(list []string, s string) bool {
|
|
for _, item := range list {
|
|
if strings.EqualFold(item, s) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func anyContainsFold(keywords []string, s string) bool {
|
|
lower := strings.ToLower(s)
|
|
for _, kw := range keywords {
|
|
if strings.Contains(lower, strings.ToLower(kw)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|