Skip to content

Commit

Permalink
I know it's halloween, but still... we should rewrite this in Ruby
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Oct 24, 2024
1 parent b445436 commit a64198b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ 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 {
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, &json.JSONValue{
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, json.JSONValue{
Static: property.Value,
Pattern: property.Selector,
}, false))
}
for propertyName, property := range identity.Overrides {
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, &json.JSONValue{
extendedProperties = append(extendedProperties, evaluators.NewIdentityExtension(propertyName, json.JSONValue{
Static: property.Value,
Pattern: property.Selector,
}, true))
Expand Down
10 changes: 6 additions & 4 deletions pkg/evaluators/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ func (config *IdentityConfig) ResolveExtendedProperties(pipeline auth.AuthPipeli
authJSON := pipeline.GetAuthorizationJSON()

for _, extendedProperty := range config.ExtendedProperties {
resolved, err := extendedProperty.ResolveFor(extendedIdentityObject, authJSON)
if err != nil {
return nil, err
if extendedProperty.Value != nil {
resolved, err := extendedProperty.ResolveFor(extendedIdentityObject, authJSON)
if err != nil {
return nil, err
}
extendedIdentityObject[extendedProperty.Name] = resolved
}
extendedIdentityObject[extendedProperty.Name] = resolved
}

return extendedIdentityObject, nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/evaluators/identity_extension.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package evaluators

import (
"github.com/kuadrant/authorino/pkg/expressions"
"github.com/kuadrant/authorino/pkg/json"
)

func NewIdentityExtension(name string, value expressions.Value, overwrite bool) IdentityExtension {
func NewIdentityExtension(name string, value json.JSONValue, overwrite bool) IdentityExtension {
return IdentityExtension{
JSONProperty: json.JSONProperty{
Name: name,
Value: value,
Value: &value,
},
Overwrite: overwrite,
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/evaluators/identity_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,62 @@ func TestResolveIdentityExtension(t *testing.T) {
}{
{
name: "static value for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Static: "foo"}, false),
input: NewIdentityExtension("username", json.JSONValue{Static: "foo"}, false),
expected: "beth",
},
{
name: "static value for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Static: "foo"}, false),
input: NewIdentityExtension("uid", json.JSONValue{Static: "foo"}, false),
expected: "foo",
},
{
name: "static value for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Static: "foo"}, true),
input: NewIdentityExtension("username", json.JSONValue{Static: "foo"}, true),
expected: "foo",
},
{
name: "static value for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Static: "foo"}, true),
input: NewIdentityExtension("uid", json.JSONValue{Static: "foo"}, true),
expected: "foo",
},
{
name: "existing pattern for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Pattern: "auth.identity.sub"}, false),
input: NewIdentityExtension("username", json.JSONValue{Pattern: "auth.identity.sub"}, false),
expected: "beth",
},
{
name: "existing pattern for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Pattern: "auth.identity.sub"}, false),
input: NewIdentityExtension("uid", json.JSONValue{Pattern: "auth.identity.sub"}, false),
expected: "1234567890",
},
{
name: "existing pattern for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Pattern: "auth.identity.sub"}, true),
input: NewIdentityExtension("username", json.JSONValue{Pattern: "auth.identity.sub"}, true),
expected: "1234567890",
},
{
name: "existing pattern for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Pattern: "auth.identity.sub"}, true),
input: NewIdentityExtension("uid", json.JSONValue{Pattern: "auth.identity.sub"}, true),
expected: "1234567890",
},
{
name: "missing pattern for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Pattern: "auth.identity.full_name"}, false),
input: NewIdentityExtension("username", json.JSONValue{Pattern: "auth.identity.full_name"}, false),
expected: "beth",
},
{
name: "missing pattern for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Pattern: "auth.identity.full_name"}, false),
input: NewIdentityExtension("uid", json.JSONValue{Pattern: "auth.identity.full_name"}, false),
expected: "",
},
{
name: "missing pattern for existing property without overwrite",
input: NewIdentityExtension("username", &json.JSONValue{Pattern: "auth.identity.full_name"}, true),
input: NewIdentityExtension("username", json.JSONValue{Pattern: "auth.identity.full_name"}, true),
expected: "",
},
{
name: "missing pattern for missing property without overwrite",
input: NewIdentityExtension("uid", &json.JSONValue{Pattern: "auth.identity.full_name"}, true),
input: NewIdentityExtension("uid", json.JSONValue{Pattern: "auth.identity.full_name"}, true),
expected: "",
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/evaluators/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestIdentityConfig_ResolveExtendedProperties(t *testing.T) {
Name: "test",
KubernetesAuth: &identity.KubernetesAuth{},
ExtendedProperties: []IdentityExtension{
NewIdentityExtension("prop1", &json.JSONValue{Static: "value1"}, true),
NewIdentityExtension("prop2", &json.JSONValue{Pattern: "auth.identity.sub"}, true),
NewIdentityExtension("prop1", json.JSONValue{Static: "value1"}, true),
NewIdentityExtension("prop2", json.JSONValue{Pattern: "auth.identity.sub"}, true),
},
}

Expand Down

0 comments on commit a64198b

Please sign in to comment.