Skip to content

Commit

Permalink
CEL
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <alex@wcgw.dev>
  • Loading branch information
alexsnaps committed Oct 30, 2024
1 parent 44052a6 commit 4324134
Show file tree
Hide file tree
Showing 3 changed files with 5 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
6 changes: 1 addition & 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 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 4324134

Please sign in to comment.