cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.58.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/git/filter.go

46lines · modecode

1package git
2
3import "regexp"
4
5func NewPathFilter(include, exclude, relaxed []*regexp.Regexp) PathFilter {
6 return PathFilter{
7 include: include,
8 exclude: exclude,
9 relaxed: relaxed,
10 }
11}
12
13type PathFilter struct {
14 include []*regexp.Regexp
15 exclude []*regexp.Regexp
16 relaxed []*regexp.Regexp
17}
18
19func (pf PathFilter) IsPathAllowed(path string) bool {
20 if len(pf.include) == 0 && len(pf.exclude) == 0 {
21 return true
22 }
23
24 for _, pattern := range pf.exclude {
25 if pattern.MatchString(path) {
26 return false
27 }
28 }
29
30 for _, pattern := range pf.include {
31 if pattern.MatchString(path) {
32 return true
33 }
34 }
35
36 return false
37}
38
39func (pf PathFilter) IsRelaxed(path string) bool {
40 for _, r := range pf.relaxed {
41 if v := r.MatchString(path); v {
42 return true
43 }
44 }
45 return false
46}
47