Add support for verdict and decision reason context

This commit is contained in:
Patrick Pacher 2020-04-20 17:19:48 +02:00
parent eeb358425d
commit 8c5526a69b
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
17 changed files with 246 additions and 148 deletions

51
intel/block_reason.go Normal file
View file

@ -0,0 +1,51 @@
package intel
import (
"fmt"
"strings"
)
// ListMatch represents an entity that has been
// matched against filterlists.
type ListMatch struct {
Entity string
ActiveLists []string
InactiveLists []string
}
func (lm *ListMatch) String() string {
inactive := ""
if len(lm.InactiveLists) > 0 {
inactive = " and in deactivated lists " + strings.Join(lm.InactiveLists, ", ")
}
return fmt.Sprintf(
"%s in activated lists %s%s",
lm.Entity,
strings.Join(lm.ActiveLists, ","),
inactive,
)
}
// ListBlockReason is a list of list matches.
type ListBlockReason []ListMatch
func (br ListBlockReason) String() string {
if len(br) == 0 {
return ""
}
matches := make([]string, len(br))
for idx, lm := range br {
matches[idx] = lm.String()
}
return strings.Join(matches, " and ")
}
// Context returns br wrapped into a map. It implements
// the endpoints.Reason interface.
func (br ListBlockReason) Context() interface{} {
return map[string]interface{}{
"filterlists": br,
}
}