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(interpolation): add fromFile interpolation helper #7214

Closed
wants to merge 1 commit into from

Conversation

LuBashQ
Copy link

@LuBashQ LuBashQ commented Nov 9, 2024

  1. Description

Add interpolation helper that reads a file path and returns the contents of the file if exists, empty string otherwise. The method is intended to be used for example chained to toJSON helper, given a correctly formatted JSON file.

  1. Related issues

#7213

  1. About tests

Added unit tests with both existing and non-existing paths.

Add interpolation helper that reads a file path and returns the contents of the file if exists, empty otherwise

Signed-off-by: LuBashQ <[email protected]>
@richardlt
Copy link
Member

Hi, I understand your request about Venom but as this interpolation is also used by CDS api we can't safely approve the PR as we don't want this interpolate to read files in that context.
Venom should use its own set of helpers for that purpose, you can submit a PR on Venom repository if needed.

@richardlt richardlt closed this Nov 15, 2024
@LuBashQ
Copy link
Author

LuBashQ commented Nov 15, 2024

The reason why the PR was opened here is that venom uses cds' interpolate package to resolve helper functions https://github.com/ovh/venom/blob/f3548d1573594480413f728e4a57f0f5130b36e8/types_executor.go#L275, which are filled in here

t, err := template.New("input").Funcs(InterpolateHelperFuncs).Parse(input)
.

My question now is? Would it be then a good option to treat the return from interpolate.Do() in Venom as a template and then further process it with the venom-specific helper functions? Correct me if I'm wrong, but from what I understand interpolate.Do() in case of unknown helpers, it will just keep them as-is

if !defaultIsUsed && (len(unknownVariables) > 0 || len(unknownHelpers) > 0) {
for _, s := range quotedStuff {
q := strings.Replace(sm[i][1], `"`+s+`"`, `\"`+s+`\"`, -1)
input = strings.Replace(input, sm[i][1], q, 1)
sm[i][1] = q
}
input = strings.Replace(input, sm[i][1], "{{\""+sm[i][1]+"\"}}", -1)
, so could it then be processed further by venom?

@LuBashQ LuBashQ deleted the fromFile-interpolate-helper branch November 15, 2024 09:08
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