Skip to content

Commit

Permalink
Added strings extension to CEL interpreter
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <alex@wcgw.dev>
  • Loading branch information
alexsnaps committed Nov 5, 2024
1 parent 7de618a commit ff905d6
Show file tree
Hide file tree
Showing 3 changed files with 11 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)
}
6 changes: 3 additions & 3 deletions tests/v1beta3/authconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ 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":","}
expresssion: request.headers["x-forwarded-for"].split(",")[0]
user-info:
userInfo:
identitySource: keycloak
Expand Down Expand Up @@ -179,7 +179,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 ff905d6

Please sign in to comment.