-
Notifications
You must be signed in to change notification settings - Fork 4
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
Validating data #103
Comments
Nice idea! Jinja tests have a different purpose, they enable things like def validate_addressing(value: str) -> None:
try:
netaddr.IPNetwork(value)
except netaddr.core.AddrFormatError as e:
raise ValueError("Help message") from e
class Loader:
def __init__(self, data):
validate_addressing(data.bootstrap_cluster_cidr)
validate_addressing(data.bootstrap_service_cidr) In essence, you pass the data you receive in the init function to some custom function that then checks your constraints and raises an exception if necessary. You may also alter the logic (e.g., print some message and then exit the program instead of raising a new exception), so feel free to adjust this snippet as needed. Does that fulfill your use case? |
I believe this will fit my usecase! I was noodling last night with the
|
Yeah, that exception makes sense.
Jinja supports the dot-based notation, but pure Python code sadly does not. Sorry for the mistake. |
Ah I was scratching my head trying to figure out why that wasn't working but makes total sense. Thanks This is great and definitely covers my usecase <3 |
I wanted to share my progress with this in you are interested. It is coming along very nice: onedr0p/cluster-template#1214 If you would be okay with this I would love to PR my repo to your readme under a "Who's using makejinja?" section at the bottom. I know I would be very happy to look at how other people are using makejinja if I discovered you repo for the first time 😄 |
Thanks for sharing, I am quite surprised that you were able to completely switch from Ansible to makejinja! I would appreciate such a PR. At the moment, I am making some smaller modifications to the README locally, I will let you know once I am finished so you can create the PR 😄 |
Another area where you could help me: I would love to add a small comparison between Ansible and makejinja to the readme so that others know what separates Ansible templates from this project. Since you used these quite extensively and now have some experience with makejinja I would love to hear about the most important reasons for your switch. Feel free to contact me privately (my mail is stated in my GitHub profile) or open a discussion in this repo. |
@onedr0p I just started a new discussion (#106) to collect projects using makejinja. In addition, we can still add some featured projects to the readme, but I hope that giving an easy way for people to link to their repo is an advantage and lowers the barrier. I also just the changes to the README, I think the "featured projects" should ideally be added between "highlights" and "installation". |
Is your feature request related to a problem? Please describe.
I was wondering if it currently possible to validate data items before the templating happens. I was poking around the docs and I see Tests but not sure if that is what I should be looking at.
Describe the solution you'd like
I would love to be able run validation on user supplied variables from the data or data-vars flags.
For example, I was wondering if something like this pseudo-code was possible:
The text was updated successfully, but these errors were encountered: