Skip to content

Resolves #1864. Adds Native List as an option for configuring keys. #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lucqui
Copy link

@lucqui lucqui commented Jun 24, 2025

Resolves #1864. Adds Native List as an option for configuring keys in addition to the trailing comma option already given.

…keys in addition to the trailing comma option already given.

Signed-off-by: Lucas Earl <[email protected]>
@lucqui lucqui force-pushed the adding-native-list-support-for-keys branch from fdb34b7 to 02a8304 Compare June 24, 2025 06:13
@felixfontein felixfontein requested a review from a team June 25, 2025 18:26
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for picking this topic up! I think this is already looking great (and it worked well during testing)!

…keys in addition to the trailing comma option already given.

Signed-off-by: Lucas Earl <[email protected]>
case []interface{}:
result := make([]string, len(v))
for i, item := range v {
result[i] = fmt.Sprintf("%v", item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably also check here whether the value is actually a string (and error out if not).

}

// Utility function to handle both string and []string
func parseKeyField(field interface{}) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about providing the field's name to this function? Then it could be inserted into the error messages, which makes it a bit easier to find the source of the problem.

if err != nil {
return nil, err
}

if cRule.Age != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this if now involve ageKeys?

assert.Nil(t, err)
assert.Equal(t, k, conf.KeyGroups[0][0].ToString())
assert.Nil(t, conf)
assert.ErrorContains(t, err, "invalid age key configuration: invalid key field type: expected string, []string, or nil, got")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why is this now an error? The test should still succeed IMO with the same result as before.

t.Fatal("Expected configuration but got nil")
}

assert.True(t, len(conf.KeyGroups) > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be

Suggested change
assert.True(t, len(conf.KeyGroups) > 0)
assert.True(t, len(conf.KeyGroups) == 1)

?

case []string:
return v, nil
default:
return nil, fmt.Errorf("invalid key field type: expected string, []string, or nil, got %T", field)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you still need to check for nil and not error out if nil is received. nil is a prefectly valid value for a field that wans't specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow interpret keys as native list, not just CSV string
2 participants