diff --git a/pkg/evaluators/response/dynamic_cel.go b/pkg/evaluators/response/dynamic_cel.go deleted file mode 100644 index dcd4e118..00000000 --- a/pkg/evaluators/response/dynamic_cel.go +++ /dev/null @@ -1,43 +0,0 @@ -package response - -import ( - "context" - - interpreter "github.com/google/cel-go/cel" - "github.com/kuadrant/authorino/pkg/auth" - "github.com/kuadrant/authorino/pkg/expressions/cel" -) - -func NewDynamicCelResponse(expression string) (*DynamicCEL, error) { - - cel_exp := DynamicCEL{} - - if program, err := cel.Compile(expression, nil); err != nil { - return nil, err - } else { - cel_exp.program = program - } - - return &cel_exp, nil -} - -type DynamicCEL struct { - program interpreter.Program -} - -func (c *DynamicCEL) Call(pipeline auth.AuthPipeline, ctx context.Context) (interface{}, error) { - input, err := cel.AuthJsonToCel(pipeline.GetAuthorizationJSON()) - if err != nil { - return nil, err - } - result, _, err := c.program.Eval(input) - if err != nil { - return nil, err - } - - if jsonVal, err := cel.ValueToJSON(result); err != nil { - return nil, err - } else { - return jsonVal, nil - } -} diff --git a/pkg/evaluators/response/dynamic_cel_test.go b/pkg/evaluators/response/dynamic_cel_test.go deleted file mode 100644 index 1089d444..00000000 --- a/pkg/evaluators/response/dynamic_cel_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package response - -import ( - "context" - "encoding/json" - "testing" - - mock_auth "github.com/kuadrant/authorino/pkg/auth/mocks" - "gotest.tools/assert" - - "github.com/golang/mock/gomock" -) - -func TestDynamicCELCall(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - celResponseEvaluator, _ := NewDynamicCelResponse(`{"prop1": "value1", "prop2": auth.identity.username}`) - - pipelineMock := mock_auth.NewMockAuthPipeline(ctrl) - pipelineMock.EXPECT().GetAuthorizationJSON().Return(`{"auth":{"identity":{"username":"john","evil": false}}}`) - - response, err := celResponseEvaluator.Call(pipelineMock, context.TODO()) - assert.NilError(t, err) - - // We need to parse this response: https://protobuf.dev/reference/go/faq/#unstable-json - result := struct { - Prop1 string `json:"prop1"` - Prop2 string `json:"prop2"` - }{} - assert.NilError(t, json.Unmarshal([]byte(response.(string)), &result)) - - assert.Equal(t, result.Prop1, "value1") - assert.Equal(t, result.Prop2, "john") -}