Skip to content
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

feat: json dump funcs for cel #19

Merged
merged 2 commits into from
Aug 28, 2023
Merged

feat: json dump funcs for cel #19

merged 2 commits into from
Aug 28, 2023

Conversation

yashmehrotra
Copy link
Member

No description provided.

Comment on lines +80 to +82
if err != nil {
return types.String(err.Error())
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is intentional, no other way to propagate the error to the users

@@ -58,6 +66,46 @@ func k8sIsHealthy() cel.EnvOption {
)
}

func jsonArrayDump() cel.EnvOption {
return cel.Function("data.JSONArrayDump",
Copy link
Member

Choose a reason for hiding this comment

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

can we remove the prefix and use camelCase e.g. toJson ? with type overloading ?

Don't we already have this method from gomplate e.g. https://github.com/flanksource/gomplate/blob/main/funcs/data_gen.go#L29 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't we already have this method from gomplate e.g. https://github.com/flanksource/gomplate/blob/main/funcs/data_gen.go#L29 ?

This does not work as we want it to, we want to return a string type and the function should accept a dyn type which then needs to be converted to map[string]any. Also, that function returns the wrong result. It converts the dyn type to string incorrectly

can we remove the prefix and use camelCase e.g. toJson ? with type overloading ?
cool, will try that

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the dyn in the first place?

If those functions don't work, we should add tests for them and then exclude them so that we know its WIP

Copy link
Member Author

@yashmehrotra yashmehrotra Aug 26, 2023

Choose a reason for hiding this comment

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

Why do we need the dyn in the first place?

Its not a hard requirement. dyn supports functions like map, filter etc. so as a user it is easy to work with that. We can accept a any type as well here as well, it wont break anything

If those functions don't work, we should add tests for them and then exclude them so that we know its WIP

Have created an issue to track that: #20

@moshloop moshloop merged commit 41f8577 into main Aug 28, 2023
5 checks passed
@yashmehrotra yashmehrotra deleted the cel-json-dump-funcs branch August 28, 2023 05:48
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.

2 participants