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

Method ConvertWAF

internal/waf/waf_manager.go:54–251  ·  view source on GitHub ↗

ConvertWAF 将Policy转换为WAF

(policy *firewallconfigs.HTTPFirewallPolicy)

Source from the content-addressed store, hash-verified

52
53// ConvertWAF 将Policy转换为WAF
54func (this *WAFManager) ConvertWAF(policy *firewallconfigs.HTTPFirewallPolicy) (*WAF, error) {
55 if policy == nil {
56 return nil, errors.New("policy should not be nil")
57 }
58 if len(policy.Mode) == 0 {
59 policy.Mode = firewallconfigs.FirewallModeDefend
60 }
61 var w = &WAF{
62 Id: policy.Id,
63 IsOn: policy.IsOn,
64 Name: policy.Name,
65 Mode: policy.Mode,
66 UseLocalFirewall: policy.UseLocalFirewall,
67 SYNFlood: policy.SYNFlood,
68 }
69
70 // inbound
71 if policy.Inbound != nil && policy.Inbound.IsOn {
72 for _, group := range policy.Inbound.Groups {
73 g := &RuleGroup{
74 Id: group.Id,
75 IsOn: group.IsOn,
76 Name: group.Name,
77 Description: group.Description,
78 Code: group.Code,
79 IsInbound: true,
80 }
81
82 // rule sets
83 for _, set := range group.Sets {
84 s := &RuleSet{
85 Id: set.Id,
86 Code: set.Code,
87 IsOn: set.IsOn,
88 Name: set.Name,
89 Description: set.Description,
90 Connector: set.Connector,
91 IgnoreLocal: set.IgnoreLocal,
92 }
93 for _, a := range set.Actions {
94 s.AddAction(a.Code, a.Options)
95 }
96
97 // rules
98 for _, rule := range set.Rules {
99 r := &Rule{
100 Id: rule.Id,
101 Description: rule.Description,
102 Param: rule.Param,
103 ParamFilters: []*ParamFilter{},
104 Operator: rule.Operator,
105 Value: rule.Value,
106 IsCaseInsensitive: rule.IsCaseInsensitive,
107 CheckpointOptions: rule.CheckpointOptions,
108 }
109
110 for _, paramFilter := range rule.ParamFilters {
111 r.ParamFilters = append(r.ParamFilters, &ParamFilter{

Callers 3

UpdatePoliciesMethod · 0.95
TestWAFManager_convertFunction · 0.80
TemplateFunction · 0.80

Calls 3

NewFunction · 0.92
InitMethod · 0.65
AddActionMethod · 0.45

Tested by 1

TestWAFManager_convertFunction · 0.64