-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
immutable fields + allowedNamespaces
- Loading branch information
Eneman Donatien
authored and
Eneman Donatien
committed
Sep 13, 2024
1 parent
34b85b3
commit 9940007
Showing
17 changed files
with
216 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package glob | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/InseeFrLab/s3-operator/internal/utils/regex" | ||
"github.com/gobwas/glob" | ||
) | ||
|
||
const ( | ||
EXACT = "exact" | ||
GLOB = "glob" | ||
REGEXP = "regexp" | ||
) | ||
|
||
func Match(pattern, text string, separators ...rune) bool { | ||
compiledGlob, err := glob.Compile(pattern, separators...) | ||
if err != nil { | ||
return false | ||
} | ||
return compiledGlob.Match(text) | ||
} | ||
|
||
// MatchStringInList will return true if item is contained in list. | ||
// patternMatch; can be set to exact, glob, regexp. | ||
// If patternMatch; is set to exact, the item must be an exact match. | ||
// If patternMatch; is set to glob, the item must match a glob pattern. | ||
// If patternMatch; is set to regexp, the item must match a regular expression or glob. | ||
func MatchStringInList(list []string, item string, patternMatch string) bool { | ||
for _, ll := range list { | ||
// If string is wrapped in "/", assume it is a regular expression. | ||
if patternMatch == REGEXP && strings.HasPrefix(ll, "/") && strings.HasSuffix(ll, "/") && regex.Match(ll[1:len(ll)-1], item) { | ||
return true | ||
} else if (patternMatch == REGEXP || patternMatch == GLOB) && Match(ll, item) { | ||
return true | ||
} else if patternMatch == EXACT && item == ll { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package regex | ||
|
||
import ( | ||
"github.com/dlclark/regexp2" | ||
) | ||
|
||
func Match(pattern, text string) bool { | ||
compiledRegex, err := regexp2.Compile(pattern, 0) | ||
if err != nil { | ||
return false | ||
} | ||
regexMatch, err := compiledRegex.MatchString(text) | ||
if err != nil { | ||
return false | ||
} | ||
return regexMatch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.