Skip to content

Commit

Permalink
CEL
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Oct 30, 2024
1 parent 44052a6 commit 3e872c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func valueFrom(user *api.ValueOrSelector) (expressions.Value, error) {
var strValue expressions.Value
var err error
if user.Expression != "" {
if strValue, err = cel.NewExpression(string(user.Expression)); err != nil {
if strValue, err = cel.NewStringExpression(string(user.Expression)); err != nil {
return nil, err
}
} else {
Expand Down Expand Up @@ -1128,7 +1128,7 @@ func getJsonFromStaticDynamic(value *api.ValueOrSelector) (expressions.Value, er
}
expression := string(value.Expression)
if expression != "" {
return cel.NewExpression(expression)
return cel.NewStringExpression(expression)
}

return &json.JSONValue{
Expand Down
7 changes: 2 additions & 5 deletions pkg/expressions/cel/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ func (e *Expression) ResolveFor(json string) (interface{}, error) {
return nil, err
}

if jsonVal, err := ValueToJSON(result); err != nil {
return nil, err
} else {
return jsonVal, nil
}
return ValueToJSON(result)
}

func (e *StringExpression) ResolveFor(json string) (interface{}, error) {
Expand All @@ -108,6 +104,7 @@ func (e *Expression) Evaluate(json string) (ref.Val, *cel.EvalDetails, error) {
}

func (e *Expression) EvaluateStringValue(json string) (string, error) {
fmt.Printf(" ====>>> data: %s\n", json)
if result, _, err := e.Evaluate(json); err != nil {
return "", err
} else if !reflect.DeepEqual(result.Type(), cel.StringType) {
Expand Down
4 changes: 2 additions & 2 deletions tests/v1beta3/authconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
jwt-rbac:
value: true
roles:
expression: auth.identity.realm_access.roles
expression: "has(auth.identity.realm_access) ? auth.identity.realm_access.roles : []"
username:
expression: "has(auth.identity.preferred_username) ? auth.identity.preferred_username : 'unknown'"
oauth2-introspection:
Expand All @@ -53,7 +53,7 @@ spec:
jwt-rbac:
value: true
roles:
expression: auth.identity.realm_access.roles
expression: "has(auth.identity.realm_access) ? auth.identity.realm_access.roles : []"
username:
expression: "has(auth.identity.preferred_username) ? auth.identity.preferred_username : 'unknown'"
cache:
Expand Down

0 comments on commit 3e872c9

Please sign in to comment.