mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
refactor(allowlist): use iota for condition (#1569)
This commit is contained in:
1 parent
12034a71c5
commit
5c03fa4a3e
4 files changed
+22
-15
No files matched your search
+10
-3
@@ -6,13 +6,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AllowlistMatchCondition string
|
||||
type AllowlistMatchCondition int
|
||||
|
||||
const (
|
||||
AllowlistMatchOr AllowlistMatchCondition = "OR"
|
||||
AllowlistMatchAnd = "AND"
|
||||
AllowlistMatchOr AllowlistMatchCondition = iota
|
||||
AllowlistMatchAnd
|
||||
)
|
||||
|
||||
func (a AllowlistMatchCondition) String() string {
|
||||
return [...]string{
|
||||
"OR",
|
||||
"AND",
|
||||
}[a]
|
||||
}
|
||||
|
||||
// Allowlist allows a rule to be ignored for specific
|
||||
// regexes, paths, and/or commits
|
||||
type Allowlist struct {
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestTranslate(t *testing.T) {
|
||||
Keywords: []string{},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Regexes: []*regexp.Regexp{regexp.MustCompile("123")},
|
||||
},
|
||||
},
|
||||
@@ -68,7 +68,7 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Regexes: []*regexp.Regexp{regexp.MustCompile("AKIALALEMEL33243OLIA")},
|
||||
},
|
||||
},
|
||||
@@ -87,7 +87,7 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Commits: []string{"allowthiscommit"},
|
||||
},
|
||||
},
|
||||
@@ -106,7 +106,7 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(".go")},
|
||||
},
|
||||
},
|
||||
@@ -184,11 +184,11 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
StopWords: []string{"fake"},
|
||||
},
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Commits: []string{"abcdefg1"},
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`ignore\.xaml`)},
|
||||
Regexes: []*regexp.Regexp{regexp.MustCompile(`foo.+bar`)},
|
||||
@@ -212,11 +212,11 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
StopWords: []string{"fake"},
|
||||
},
|
||||
{
|
||||
MatchCondition: "AND",
|
||||
MatchCondition: AllowlistMatchAnd,
|
||||
Commits: []string{"abcdefg1"},
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`ignore\.xaml`)},
|
||||
Regexes: []*regexp.Regexp{regexp.MustCompile(`foo.+bar`)},
|
||||
@@ -240,7 +240,7 @@ func TestTranslate(t *testing.T) {
|
||||
Tags: []string{"key", "AWS"},
|
||||
Allowlists: []Allowlist{
|
||||
{
|
||||
MatchCondition: "OR",
|
||||
MatchCondition: AllowlistMatchOr,
|
||||
Paths: []*regexp.Regexp{regexp.MustCompile(`something.py`)},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user