feat: support merging multiple subscriptions

This commit is contained in:
2026-07-19 23:58:02 +08:00
parent fb4d927220
commit 087869d84f
17 changed files with 1341 additions and 60 deletions

View File

@ -0,0 +1,42 @@
package automation
import "fmt"
// buildProxyGroups implements the "proxy-groups" ssm feature: for each rule,
// filter the merged proxy pool by rule.Match and append a new proxy-group
// containing the matched proxies' display names.
func buildProxyGroups(finalConfig map[string]interface{}, rules []ProxyGroupRule, proxies []ProxyRef) {
for _, rule := range rules {
matched := matchProxies(proxies, rule.Match)
names := make([]interface{}, 0, len(matched))
for _, p := range matched {
names = append(names, p.DisplayName)
}
if len(matched) == 0 {
fmt.Printf(" ssm: proxy-group '%s' matched 0 proxies\n", rule.Name)
}
group := map[string]interface{}{
"name": rule.Name,
"type": defaultString(rule.Type, "select"),
"proxies": names,
}
for k, v := range rule.Extra {
group[k] = v
}
appendProxyGroup(finalConfig, group)
}
}
func defaultString(v, fallback string) string {
if v == "" {
return fallback
}
return v
}
func appendProxyGroup(finalConfig map[string]interface{}, group map[string]interface{}) {
existing, _ := finalConfig["proxy-groups"].([]interface{})
finalConfig["proxy-groups"] = append(existing, group)
}