-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feature(builtins): add a new builtin function to render templated strings #6411
feature(builtins): add a new builtin function to render templated strings #6411
Conversation
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
bbdfbfd
to
02236bb
Compare
0db7400
to
5c787f1
Compare
66f2a9c
to
7e10ee6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RDVasavada thanks for the contribution. Few comments inline.
Thanks for your feedback @ashutosh-narkar. I have addressed your comments -- let me know if you have any additional feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@RDVasavada can you please squash your commits and we can get this in. Thanks! |
Check this link if you need pointers to craft a good commit message. |
Added a unit test for non-string template var inputs and added back the template docs link as requested by @johanfylling, please let me know if there's any other feedback before I squash, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
8185718
to
76f6d7c
Compare
@ashutosh-narkar rebased and squashed |
76f6d7c
to
1417763
Compare
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
1417763
to
21598e6
Compare
Why the changes in this PR are needed?
closes: #6371
Adds a builtin function for template rendering.
What are the changes in this PR?
Adds a new builtin function that accepts a templated string and a mapping of vars to inject, and returns the rendered string with the vars injected.
Notes to assist PR review:
For this builtin function, I've set the
missingkey
option toerror
, so that if the template contains a variable that is not present in the given variable mapping, the function will not attempt to render the template and return an error. This was done to prevent silent failures from occurring.