MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / MergeTemplate

Method MergeTemplate

internal/waf/waf.go:448–490  ·  view source on GitHub ↗

MergeTemplate merge with template

()

Source from the content-addressed store, hash-verified

446
447// MergeTemplate merge with template
448func (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}

Callers

nothing calls this directly

Calls 5

FindRuleGroupWithCodeMethod · 0.95
AddRuleGroupMethod · 0.95
TemplateFunction · 0.85
FindRuleSetWithCodeMethod · 0.80
AddRuleSetMethod · 0.80

Tested by

no test coverage detected