MCPcopy
hub / github.com/crowdsecurity/crowdsec / CompileWLs

Method CompileWLs

pkg/parser/whitelist.go:112–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110}
111
112func (n *Node) CompileWLs() (bool, error) {
113 for _, v := range n.Whitelist.Ips {
114 addr, err := netip.ParseAddr(v)
115 if err != nil {
116 return false, fmt.Errorf("parsing whitelist: %w", err)
117 }
118
119 n.Whitelist.B_Ips = append(n.Whitelist.B_Ips, addr)
120 n.Logger.Debugf("adding ip %s to whitelists", addr)
121 }
122
123 for _, v := range n.Whitelist.Cidrs {
124 tnet, err := netip.ParsePrefix(v)
125 if err != nil {
126 return false, fmt.Errorf("parsing whitelist: %w", err)
127 }
128 n.Whitelist.B_Cidrs = append(n.Whitelist.B_Cidrs, tnet)
129 n.Logger.Debugf("adding cidr %s to whitelists", tnet)
130 }
131
132 for _, filter := range n.Whitelist.Exprs {
133 var err error
134 expression := &ExprWhitelist{}
135 expression.Filter, err = expr.Compile(filter, exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...)
136 if err != nil {
137 return false, fmt.Errorf("unable to compile whitelist expression '%s' : %v", filter, err)
138 }
139 n.Whitelist.B_Exprs = append(n.Whitelist.B_Exprs, expression)
140 n.Logger.Debugf("adding expression %s to whitelists", filter)
141 }
142 return n.ContainsWLs(), nil
143}
144
145func (n *Node) bumpWhitelistMetric(counter *prometheus.CounterVec, p *pipeline.Event) {
146 // better safe than sorry

Callers 3

TestWhitelistCompileFunction · 0.95
TestWhitelistCheckFunction · 0.95
compileMethod · 0.95

Calls 3

ContainsWLsMethod · 0.95
GetExprOptionsFunction · 0.92
CompileMethod · 0.45

Tested by 2

TestWhitelistCompileFunction · 0.76
TestWhitelistCheckFunction · 0.76