add flatten to manipulate arrays of arrays
This commit is contained in:
parent
54fd2e4e70
commit
b33ba277bf
|
@ -20,6 +20,11 @@ var exprFuncs = []exprCustomFunc{
|
||||||
new(func(string) (*cticlient.SmokeItem, error)),
|
new(func(string) (*cticlient.SmokeItem, error)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Flatten",
|
||||||
|
function: Flatten,
|
||||||
|
signature: []interface{}{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Distance",
|
name: "Distance",
|
||||||
function: Distance,
|
function: Distance,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -172,6 +173,26 @@ func FileInit(fileFolder string, filename string, fileType string) error {
|
||||||
|
|
||||||
// Expr helpers
|
// Expr helpers
|
||||||
|
|
||||||
|
func Flatten(params ...any) (any, error) {
|
||||||
|
return flatten(nil, reflect.ValueOf(params)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func flatten(args []interface{}, v reflect.Value) []interface{} {
|
||||||
|
if v.Kind() == reflect.Interface {
|
||||||
|
v = v.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Kind() == reflect.Array || v.Kind() == reflect.Slice {
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
args = flatten(args, v.Index(i))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args = append(args, v.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
// func Get(arr []string, index int) string {
|
// func Get(arr []string, index int) string {
|
||||||
func Get(params ...any) (any, error) {
|
func Get(params ...any) (any, error) {
|
||||||
arr := params[0].([]string)
|
arr := params[0].([]string)
|
||||||
|
|
|
@ -9,7 +9,7 @@ const PAPIVersion = "v1"
|
||||||
const PAPIPollUrl = "/decisions/stream/poll"
|
const PAPIPollUrl = "/decisions/stream/poll"
|
||||||
const PAPIPermissionsUrl = "/permissions"
|
const PAPIPermissionsUrl = "/permissions"
|
||||||
|
|
||||||
const CAPIBaseURL = "https://api.crowdsec.net/"
|
const CAPIBaseURL = "https://api.dev.crowdsec.net/"
|
||||||
|
|
||||||
const CscliOrigin = "cscli"
|
const CscliOrigin = "cscli"
|
||||||
const CrowdSecOrigin = "crowdsec"
|
const CrowdSecOrigin = "crowdsec"
|
||||||
|
|
|
@ -155,6 +155,7 @@ func (w WaapEvent) ByTagRx(rx string) WaapEvent {
|
||||||
}
|
}
|
||||||
for _, rule := range w {
|
for _, rule := range w {
|
||||||
for _, tag := range rule["tags"].([]string) {
|
for _, tag := range rule["tags"].([]string) {
|
||||||
|
log.Infof("ByTagRx: %s = %s -> %t", rx, tag, re.MatchString(tag))
|
||||||
if re.MatchString(tag) {
|
if re.MatchString(tag) {
|
||||||
waap = append(waap, rule)
|
waap = append(waap, rule)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue