Simplify MatchUserWithAllowedRegexes

This used to return an error back when it was dealing with wildcards
(which may or may not have compiled to a valid regex).

But it now deals with pre-compiled regexes and has no chance of failing,
so we need no `error` returns.
This commit is contained in:
Slavi Pantaleev
2022-08-26 10:19:33 +03:00
parent f8a168b8e7
commit bb754f9aa8
2 changed files with 5 additions and 8 deletions

View File

@@ -23,19 +23,19 @@ func WildcardUserPatternsToRegexPatterns(wildCardPatterns []string) (*[]*regexp.
// MatchUserWithAllowedRegexes tells if the given user id is allowed to use the bot, according to the given whitelist
// An empty whitelist means "everyone is allowed"
func MatchUserWithAllowedRegexes(userID string, allowed []*regexp.Regexp) (bool, error) {
func MatchUserWithAllowedRegexes(userID string, allowed []*regexp.Regexp) bool {
// No whitelisted users means everyone is whitelisted
if len(allowed) == 0 {
return true, nil
return true
}
for _, regex := range allowed {
if regex.MatchString(userID) {
return true, nil
return true
}
}
return false, nil
return false
}
// parseAllowedUserRule parses a user whitelisting rule and returns a regular expression which corresponds to it