Skip to content

Commit

Permalink
Merge pull request #501 from Kuadrant/fix/rawextension-to-str
Browse files Browse the repository at this point in the history
fix: RawExtension to string conversion
  • Loading branch information
guicassolato authored Nov 4, 2024
2 parents 82d7619 + 113717d commit 7de618a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
19 changes: 16 additions & 3 deletions pkg/evaluators/authorization/authzed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/kuadrant/authorino/pkg/auth"
"github.com/kuadrant/authorino/pkg/expressions"
"github.com/kuadrant/authorino/pkg/json"
"google.golang.org/grpc"
insecuregrpc "google.golang.org/grpc/credentials/insecure"

Expand Down Expand Up @@ -60,10 +61,14 @@ func (a *Authzed) Call(pipeline auth.AuthPipeline, ctx gocontext.Context) (inter
if err != nil {
return nil, err
}
permissionStr, err := json.StringifyJSON(permission)
if err != nil {
return nil, err
}
resp, err := client.CheckPermission(ctx, &authzedpb.CheckPermissionRequest{
Resource: resource,
Subject: &authzedpb.SubjectReference{Object: object},
Permission: fmt.Sprintf("%s", permission),
Permission: permissionStr,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -91,12 +96,20 @@ func authzedObjectFor(name, kind expressions.Value, authJSON string) (*authzedpb
if err != nil {
return nil, err
}
objectIdStr, err := json.StringifyJSON(objectId)
if err != nil {
return nil, err
}
objectType, err := kind.ResolveFor(authJSON)
if err != nil {
return nil, err
}
objectTypeStr, err := json.StringifyJSON(objectType)
if err != nil {
return nil, err
}
return &authzedpb.ObjectReference{
ObjectId: fmt.Sprintf("%s", objectId),
ObjectType: fmt.Sprintf("%s", objectType),
ObjectId: objectIdStr,
ObjectType: objectTypeStr,
}, nil
}
3 changes: 2 additions & 1 deletion pkg/evaluators/authorization/kubernetes_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kuadrant/authorino/pkg/auth"
"github.com/kuadrant/authorino/pkg/context"
"github.com/kuadrant/authorino/pkg/expressions"
"github.com/kuadrant/authorino/pkg/json"
"github.com/kuadrant/authorino/pkg/log"

kubeAuthz "k8s.io/api/authorization/v1"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (k *KubernetesAuthz) Call(pipeline auth.AuthPipeline, ctx gocontext.Context
if err != nil {
return "", err
}
return fmt.Sprintf("%s", resolved), nil
return json.StringifyJSON(resolved)
}

user, err := jsonValueToStr(k.User)
Expand Down
6 changes: 5 additions & 1 deletion pkg/evaluators/metadata/generic_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ func (h *GenericHttp) buildRequest(ctx gocontext.Context, endpoint, authJSON str
if err != nil {
return nil, err
}
req.Header.Set(header.Name, fmt.Sprintf("%s", headerValue))
headerValueStr, err := json.StringifyJSON(headerValue)
if err != nil {
return nil, err
}
req.Header.Set(header.Name, headerValueStr)
}

req.Header.Set("Content-Type", contentType)
Expand Down
4 changes: 4 additions & 0 deletions pkg/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func ReplaceJSONPlaceholders(source string, jsonData string) string {
}

func StringifyJSON(data interface{}) (string, error) {
_, ok := data.(string)
if ok {
return data.(string), nil
}
if dataAsJSON, err := json.Marshal(data); err != nil {
return "", err
} else {
Expand Down

0 comments on commit 7de618a

Please sign in to comment.