MergeTemplate merge with template
()
| 446 | |
| 447 | // MergeTemplate merge with template |
| 448 | func (this *WAF) MergeTemplate() (changedItems []string, err error) { |
| 449 | changedItems = []string{} |
| 450 | |
| 451 | // compare versions |
| 452 | if !Tea.IsTesting() && this.CreatedVersion == teaconst.Version { |
| 453 | return |
| 454 | } |
| 455 | this.CreatedVersion = teaconst.Version |
| 456 | |
| 457 | template, err := Template() |
| 458 | if err != nil { |
| 459 | return nil, err |
| 460 | } |
| 461 | groups := []*RuleGroup{} |
| 462 | groups = append(groups, template.Inbound...) |
| 463 | groups = append(groups, template.Outbound...) |
| 464 | |
| 465 | var newGroupId int64 = 1_000_000_000 |
| 466 | |
| 467 | for _, group := range groups { |
| 468 | oldGroup := this.FindRuleGroupWithCode(group.Code) |
| 469 | if oldGroup == nil { |
| 470 | newGroupId++ |
| 471 | group.Id = newGroupId |
| 472 | this.AddRuleGroup(group) |
| 473 | changedItems = append(changedItems, "+group "+group.Name) |
| 474 | continue |
| 475 | } |
| 476 | |
| 477 | // check rule sets |
| 478 | for _, set := range group.RuleSets { |
| 479 | oldSet := oldGroup.FindRuleSetWithCode(set.Code) |
| 480 | if oldSet == nil { |
| 481 | oldGroup.AddRuleSet(set) |
| 482 | changedItems = append(changedItems, "+group "+group.Name+" rule set:"+set.Name) |
| 483 | } else if len(oldSet.Rules) < len(set.Rules) { |
| 484 | oldSet.Rules = set.Rules |
| 485 | changedItems = append(changedItems, "*group "+group.Name+" rule set:"+set.Name) |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | return |
| 490 | } |
nothing calls this directly
no test coverage detected