Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
add IsAny method for matchers package
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Dec 3, 2022
1 parent 667c814 commit 6c76619
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/runner/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func customs(options *common.Options) {
matchers.IsBlank(rules[j].Element, "Custom threat rules element")
elm := fmt.Sprint("$", rules[j].Element)

if !matchers.IsMatch(fmt.Sprint(`\`, elm), cfg.Logformat) {
if !matchers.IsAny(elm, cfg.Logformat) {
err = strings.Replace(errors.ErrNoElement, ":element", elm, -1)
err = strings.Replace(err, ":category", custom[i].Name, -1)

Expand Down
9 changes: 0 additions & 9 deletions pkg/matchers/fuzz.go

This file was deleted.

31 changes: 31 additions & 0 deletions pkg/matchers/matchers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package matchers

import (
"regexp"
"strings"

"github.com/sahilm/fuzzy"
)

func IsAny(substr string, s string) bool {
if strings.Index(s, substr) > 0 {
return false
}

return true
}

func IsMatch(pattern string, s string) bool {
defer func() {
_ = recover()
}()

re := regexp.MustCompile(pattern)
return re.FindString(s) != ""
}

func IsMatchFuzz(pattern string, s []string) bool {
matches := fuzzy.Find(pattern, s)

return len(matches) > 0
}
12 changes: 0 additions & 12 deletions pkg/matchers/regex.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/teler/teler.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func Analyze(options *common.Options, logs *gonx.Entry) (bool, map[string]string
cont = strings.ReplaceAll(cont, `.%EXT%`, ext)
}

match = matchers.IsMatch(trimFirst(req.Path), cont)
match = matchers.IsAny(trimFirst(req.Path), cont)
}
}

Expand Down

0 comments on commit 6c76619

Please sign in to comment.