-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added helpers for predicates and filters #1536
base: master
Are you sure you want to change the base?
Added helpers for predicates and filters #1536
Conversation
59ecf8b
to
a72e40c
Compare
acfd671
to
612e8f9
Compare
for i := range p.Args { | ||
s, ok := p.Args[i].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("expected argument of type string, %s", p.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a separate error, such that errors.Is()
can match the formated error for example you can do: fmt.Errorf( "%w, %s", errNotAString, p.Name)
and later check for errors.Is(errNotAString, err)
(positions of args could be different, did not checked them)
From my side looks good. What do others think @aryszka @AlexanderYastrebov ? |
Thanks! As the direction, it looks good to me. I have currently two rather burocratic remarks:
|
Hi @aryszka, Thanks for your feedback!
I agree, I'm not super happy with the For predicates I think it's easy to fix, as it's just the error that's causing it, but for the
I agree that the KVPair is a bit overkill, the only benefit it gives is that it guarantees an even number of arguments. I added them to have consistency with the But using these kind of constructs are something think we shouldn't have, I can remove them, you just lose some compiler help. What do you think? // JWTPayloadAnyKVRegexp
func JWTPayloadAnyKVRegexp(pairs ...helpers.KVRegexPair) *eskip.Predicate {
return &eskip.Predicate{
Name: auth.MatchJWTPayloadAnyKVRegexpName,
Args: helpers.KVRegexPairToArgs(pairs),
}
} |
612e8f9
to
d9d43ed
Compare
Signed-off-by: Peter Klijn <[email protected]>
The helpers in the predicates and filters packages caused an import cycle. Moved them to their own package to fix this. Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
…ate package Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
Signed-off-by: Peter Klijn <[email protected]>
d9d43ed
to
68633c0
Compare
Draft PR related to feature request 1537
This PR includes:
Added filter and predicate helpers for all filters and predicates (except deprecated ones).
All helpers are in
helpers/filters/filters.go
andhelpers/predicates/predicates.go
as placing them in thepredicates
andfilter
packages creates circular dependency errors :(All helpers have tests, most that call the
PredicateSpec.Create
andFilterSpec.CreateFilter
methods to validate that the arguments are valid (some filters are very hard to test, and predicates don't have a PredicateSpec).Some predicate and filter logic has been moved or made public in order to be able to test them, mostly the names.
How the helpers differ from the
eskip
predicates/filtersThe goal is to keep the code helpers as close to the eskip implementations as possible, throughout the helpers you'll see 2 types of ways how they differ:
Cookie()
andCookieWithSettings
.regexp.Regepx
,time.Time
,time.Duration
, etc.Still to do