File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -192,18 +192,28 @@ func (v NetworkMatcher) Apply(ctx routing.Context) bool {
192192}
193193
194194type UserMatcher struct {
195- user []string
195+ user []string
196+ pattern []* regexp.Regexp
196197}
197198
198199func NewUserMatcher (users []string ) * UserMatcher {
199200 usersCopy := make ([]string , 0 , len (users ))
201+ patternsCopy := make ([]* regexp.Regexp , 0 , len (users ))
200202 for _ , user := range users {
201203 if len (user ) > 0 {
204+ if len (user ) > 7 && strings .HasPrefix (user , "regexp:" ) {
205+ if re , err := regexp .Compile (user [7 :]); err != nil {
206+ patternsCopy = append (patternsCopy , re )
207+ }
208+ // Items of users slice with an invalid regexp syntax are ignored.
209+ continue
210+ }
202211 usersCopy = append (usersCopy , user )
203212 }
204213 }
205214 return & UserMatcher {
206- user : usersCopy ,
215+ user : usersCopy ,
216+ pattern : patternsCopy ,
207217 }
208218}
209219
@@ -218,6 +228,11 @@ func (v *UserMatcher) Apply(ctx routing.Context) bool {
218228 return true
219229 }
220230 }
231+ for _ , re := range v .pattern {
232+ if re .MatchString (user ) {
233+ return true
234+ }
235+ }
221236 return false
222237}
223238
You can’t perform that action at this time.
0 commit comments