()
| 73 | } |
| 74 | |
| 75 | func (this *WAF) Init() (resultErrors []error) { |
| 76 | // checkpoint |
| 77 | this.checkpointsMap = map[string]checkpoints.CheckpointInterface{} |
| 78 | for _, def := range checkpoints.AllCheckpoints { |
| 79 | instance := reflect.New(reflect.Indirect(reflect.ValueOf(def.Instance)).Type()).Interface().(checkpoints.CheckpointInterface) |
| 80 | instance.Init() |
| 81 | instance.SetPriority(def.Priority) |
| 82 | this.checkpointsMap[def.Prefix] = instance |
| 83 | } |
| 84 | |
| 85 | // action map |
| 86 | this.actionMap = map[int64]ActionInterface{} |
| 87 | |
| 88 | // rules |
| 89 | this.hasInboundRules = len(this.Inbound) > 0 |
| 90 | this.hasOutboundRules = len(this.Outbound) > 0 |
| 91 | |
| 92 | if this.hasInboundRules { |
| 93 | for _, group := range this.Inbound { |
| 94 | // finder |
| 95 | for _, set := range group.RuleSets { |
| 96 | for _, rule := range set.Rules { |
| 97 | rule.SetCheckpointFinder(this.FindCheckpointInstance) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | err := group.Init(this) |
| 102 | if err != nil { |
| 103 | // 这里我们不阻止其他规则正常加入 |
| 104 | resultErrors = append(resultErrors, fmt.Errorf("init group '%d' failed: %w", group.Id, err)) |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if this.hasOutboundRules { |
| 110 | for _, group := range this.Outbound { |
| 111 | // finder |
| 112 | for _, set := range group.RuleSets { |
| 113 | for _, rule := range set.Rules { |
| 114 | rule.SetCheckpointFinder(this.FindCheckpointInstance) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | err := group.Init(this) |
| 119 | if err != nil { |
| 120 | // 这里我们不阻止其他规则正常加入 |
| 121 | resultErrors = append(resultErrors, err) |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | func (this *WAF) AddRuleGroup(ruleGroup *RuleGroup) { |
| 130 | if ruleGroup.IsInbound { |
nothing calls this directly
no test coverage detected