Skip to content

Commit

Permalink
Like I need to understand this crap
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Oct 28, 2024
1 parent eb15334 commit 2f5d43e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 49 deletions.
10 changes: 4 additions & 6 deletions api/v1beta3/auth_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ type PatternExpression struct {
Value string `json:"value,omitempty"`
}

type CelExpression struct {
Expression string `json:"expression,omitempty"`
}
type CelExpression string

type CelPredicate struct {
Predicate string `json:"predicate,omitempty"`
Expand Down Expand Up @@ -208,7 +206,7 @@ type ValueOrSelector struct {
// The following Authorino custom modifiers are supported: @extract:{sep:" ",pos:0}, @replace{old:"",new:""}, @case:upper|lower, @base64:encode|decode and @strip.
Selector string `json:"selector,omitempty"`

Expression CelExpression `json:",omitempty"`
Expression CelExpression `json:"expression,omitempty"`
}

type CommonEvaluatorSpec struct {
Expand Down Expand Up @@ -413,7 +411,7 @@ type PlainIdentitySpec struct {
// The following Authorino custom modifiers are supported: @extract:{sep:" ",pos:0}, @replace{old:"",new:""}, @case:upper|lower, @base64:encode|decode and @strip.
Selector string `json:"selector"`

Expression CelExpression `json:",omitempty"`
Expression CelExpression `json:"expression,omitempty"`
}

type AnonymousAccessSpec struct{}
Expand Down Expand Up @@ -451,7 +449,7 @@ type HttpEndpointSpec struct {
// E.g. https://ext-auth-server.io/metadata?p={request.path}
Url string `json:"url"`

UrlExpression CelExpression `json:",omitempty"`
UrlExpression CelExpression `json:"urlExpression,omitempty"`

// HTTP verb used in the request to the service. Accepted values: GET (default), POST.
// When the request method is POST, the authorization JSON is passed in the body of the request.
Expand Down
19 changes: 0 additions & 19 deletions api/v1beta3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
for identityCfgName, identity := range authConfigIdentityConfigs {
extendedProperties := make([]evaluators.IdentityExtension, len(identity.Defaults)+len(identity.Overrides))
for propertyName, property := range identity.Defaults {
if property.Expression.Expression != "" {
if expression, err := cel.NewExpression(property.Expression.Expression); err == nil {
if property.Expression != "" {
if expression, err := cel.NewExpression(string(property.Expression)); err == nil {
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, expression, false))
} else {
return nil, err
Expand All @@ -197,8 +197,8 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
}
}
for propertyName, property := range identity.Overrides {
if property.Expression.Expression != "" {
if expression, err := cel.NewExpression(property.Expression.Expression); err == nil {
if property.Expression != "" {
if expression, err := cel.NewExpression(string(property.Expression)); err == nil {
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, expression, true))
} else {
return nil, err
Expand Down Expand Up @@ -298,12 +298,12 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
}

case api.PlainIdentityAuthentication:
if identity.Plain.Expression.Expression != "" {
expression, err := cel.NewStringExpression(identity.Plain.Expression.Expression)
if identity.Plain.Expression != "" {
expression, err := cel.NewStringExpression(string(identity.Plain.Expression))
if err != nil {
return nil, err
}
translatedIdentity.Plain = &identity_evaluators.Plain{Value: expression, Pattern: identity.Plain.Expression.Expression}
translatedIdentity.Plain = &identity_evaluators.Plain{Value: expression, Pattern: string(identity.Plain.Expression)}
} else {
translatedIdentity.Plain = &identity_evaluators.Plain{Value: &json.JSONValue{Pattern: identity.Plain.Selector}, Pattern: identity.Plain.Selector}
}
Expand Down Expand Up @@ -921,8 +921,8 @@ func (r *AuthConfigReconciler) buildGenericHttpEvaluator(ctx context.Context, ht
}

var dynamicEndpoint expressions.Value
if http.UrlExpression.Expression != "" {
endpoint, err := cel.NewStringExpression(http.UrlExpression.Expression)
if http.UrlExpression != "" {
endpoint, err := cel.NewStringExpression(string(http.UrlExpression))
if err != nil {
return nil, err
} else {
Expand Down Expand Up @@ -1074,9 +1074,9 @@ func getJsonFromStaticDynamic(value *api.ValueOrSelector) (expressions.Value, er
if value == nil {
return nil, nil
}

if value.Expression.Expression != "" {
return cel.NewExpression(value.Expression.Expression)
expression := string(value.Expression)
if expression != "" {
return cel.NewExpression(expression)
}

return &json.JSONValue{
Expand Down
12 changes: 6 additions & 6 deletions install/crd/authorino.kuadrant.io_authconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3011,8 +3011,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -3125,6 +3123,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down Expand Up @@ -3477,8 +3477,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -3587,6 +3585,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down Expand Up @@ -3780,8 +3780,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -3890,6 +3888,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down
12 changes: 6 additions & 6 deletions install/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3319,8 +3319,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -3433,6 +3431,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down Expand Up @@ -3833,8 +3833,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -3943,6 +3941,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down Expand Up @@ -4149,8 +4149,6 @@ spec:
- name
type: object
type: object
expression:
type: string
headers:
additionalProperties:
properties:
Expand Down Expand Up @@ -4259,6 +4257,8 @@ spec:
by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
E.g. https://ext-auth-server.io/metadata?p={request.path}
type: string
urlExpression:
type: string
required:
- url
type: object
Expand Down

0 comments on commit 2f5d43e

Please sign in to comment.