update: compatible with v2board v1.7.1 route rules

This commit is contained in:
Senis John 2022-12-21 20:09:09 +08:00
parent be940fdcea
commit 4c699d86f2
No known key found for this signature in database
GPG Key ID: 845E9E4727C3E1A4

View File

@ -263,10 +263,22 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
for i, rule := range nodeInfoResponse.Get("routes").MustArray() {
r := rule.(map[string]any)
if r["action"] == "block" {
for ii := range r["match"].([]any) {
// todo remove at 2023.6.1, compatible with 1.7.1
switch r["match"].(type) {
case []any:
var s []string
for i := range r["match"].([]any) {
s = append(s, r["match"].([]any)[i].(string))
}
ruleList = append(ruleList, api.DetectRule{
ID: i,
Pattern: regexp.MustCompile(r["match"].([]any)[ii].(string)),
Pattern: regexp.MustCompile(strings.Join(s, "|")),
})
case string:
s := r["match"].(string)
ruleList = append(ruleList, api.DetectRule{
ID: i,
Pattern: regexp.MustCompile(strings.ReplaceAll(s, ",", "|")),
})
}
}