-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
verdict.go
41 lines (32 loc) · 854 Bytes
/
verdict.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Hubble
package filters
import (
"context"
flowpb "github.com/cilium/cilium/api/v1/flow"
v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
)
func filterByVerdicts(vs []flowpb.Verdict) FilterFunc {
return func(ev *v1.Event) bool {
flow := ev.GetFlow()
if flow == nil {
return false
}
for _, verdict := range vs {
if verdict == flow.GetVerdict() {
return true
}
}
return false
}
}
// VerdictFilter implements filtering based on forwarding verdict
type VerdictFilter struct{}
// OnBuildFilter builds a forwarding verdict filter
func (v *VerdictFilter) OnBuildFilter(ctx context.Context, ff *flowpb.FlowFilter) ([]FilterFunc, error) {
var fs []FilterFunc
if ff.GetVerdict() != nil {
fs = append(fs, filterByVerdicts(ff.GetVerdict()))
}
return fs, nil
}