Skip to content

Commit

Permalink
Merge pull request #255 from Kuadrant/refactor/deny-with-values
Browse files Browse the repository at this point in the history
Refactor type of denyWith dynamic values (message and body)
  • Loading branch information
guicassolato authored Apr 8, 2022
2 parents 3a1b807 + 4879032 commit 8371356
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,13 @@ func buildAuthorinoDenyWithValues(denyWithSpec *api.DenyWithSpec) *evaluators.De
}
}

func getJsonFromStaticDynamic(value *api.StaticOrDynamicValue) *json.JSONProperty {
func getJsonFromStaticDynamic(value *api.StaticOrDynamicValue) *json.JSONValue {
if value == nil {
return nil
}

return &json.JSONProperty{
Value: json.JSONValue{
Static: value.Value,
Pattern: value.ValueFrom.AuthJSON,
},
return &json.JSONValue{
Static: value.Value,
Pattern: value.ValueFrom.AuthJSON,
}
}
4 changes: 2 additions & 2 deletions pkg/evaluators/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type DenyWith struct {

type DenyWithValues struct {
Code int32
Message *json.JSONProperty
Message *json.JSONValue
Headers []json.JSONProperty
Body *json.JSONProperty
Body *json.JSONValue
}
4 changes: 2 additions & 2 deletions pkg/service/auth_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ func (pipeline *AuthPipeline) customizeDenyWith(authResult auth.AuthResult, deny
authJSON := pipeline.GetAuthorizationJSON()

if denyWith.Message != nil {
authResult.Message, _ = json.StringifyJSON(denyWith.Message.Value.ResolveFor(authJSON))
authResult.Message, _ = json.StringifyJSON(denyWith.Message.ResolveFor(authJSON))
}

if denyWith.Body != nil {
authResult.Body, _ = json.StringifyJSON(denyWith.Body.Value.ResolveFor(authJSON))
authResult.Body, _ = json.StringifyJSON(denyWith.Body.ResolveFor(authJSON))
}

if len(denyWith.Headers) > 0 {
Expand Down
6 changes: 2 additions & 4 deletions pkg/service/auth_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,8 @@ func TestEvaluateWithCustomDenyOptions(t *testing.T) {
{Name: "X-Static-Header", Value: json.JSONValue{Static: "some-value"}},
{Name: "Location", Value: json.JSONValue{Pattern: "https://my-app.io/login?redirect_to=https://{context.request.http.host}{context.request.http.path}"}},
},
Body: &json.JSONProperty{
Value: json.JSONValue{
Static: authConfigStaticResponse,
},
Body: &json.JSONValue{
Static: authConfigStaticResponse,
},
},
},
Expand Down

0 comments on commit 8371356

Please sign in to comment.