Skip to content

Commit

Permalink
Merge pull request #503 from Kuadrant/cel_strings
Browse files Browse the repository at this point in the history
Added strings extension to CEL interpreter
  • Loading branch information
alexsnaps authored Nov 5, 2024
2 parents 7de618a + a8465f1 commit 25c9702
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/expressions/cel/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/cel-go/cel"
"github.com/google/cel-go/checker/decls"
"github.com/google/cel-go/common/types/ref"
"github.com/google/cel-go/ext"
"github.com/tidwall/gjson"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -100,6 +101,7 @@ func Compile(expression string, expectedType *cel.Type, opts ...cel.EnvOption) (
decls.NewConst(RootDestinationBinding, decls.NewObjectType("google.protobuf.Struct"), nil),
decls.NewConst(RootAuthBinding, decls.NewObjectType("google.protobuf.Struct"), nil),
)}, opts...)
envOpts = append(envOpts, ext.Strings())
env, env_err := cel.NewEnv(envOpts...)
if env_err != nil {
return nil, env_err
Expand Down
6 changes: 6 additions & 0 deletions pkg/expressions/cel/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ func TestPredicate(t *testing.T) {
response, err = predicate.Matches(pipelineMock.GetAuthorizationJSON())
assert.NilError(t, err)
assert.Equal(t, response, true)

predicate, err = NewPredicate(`"GET".lowerAscii() == "get"`)
assert.NilError(t, err)
response, err = predicate.Matches("{}")
assert.NilError(t, err)
assert.Equal(t, response, true)
}
7 changes: 4 additions & 3 deletions tests/v1beta3/authconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ spec:
Accept:
value: application/json
method: GET
url: http://ip-location.authorino.svc.cluster.local:3000/{context.request.http.headers.x-forwarded-for.@extract:{"sep":","}}
urlExpression: |
"http://ip-location.authorino.svc.cluster.local:3000/" + request.headers["x-forwarded-for"].split(",")[0]
cache:
key:
selector: request.http.headers.x-forwarded-for.@extract:{"sep":","}
expression: request.headers["x-forwarded-for"].split(",")[0]
user-info:
userInfo:
identitySource: keycloak
Expand Down Expand Up @@ -179,7 +180,7 @@ spec:
uri:
expression: request.path
scope:
selector: request.http.method.@case:lower
expression: request.method.lowerAscii()
signingKeyRefs:
- name: wristband-signing-key
algorithm: ES256
Expand Down

0 comments on commit 25c9702

Please sign in to comment.