-
Notifications
You must be signed in to change notification settings - Fork 20
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
Using the include directive in vault template #113
Comments
I never imagined something like this would be done, but it's not unreasonable. I'm guessing you'd be expecting a Would you be willing to make a PR for this ? it doesn't have to be perfect, and we'll be available to help along the way. Otherwise, we can do it too. |
By the way, what should the search path be for the loader, according to you ? The folder of the templated file ? The current folder ? |
Hello, Being able to use |
I believe so, this would be most consistent with how
This is indeed tricky; Jinja2 docs don't even clarify whether I would be inclined to assume that the parameter to |
Thanks for the pointers :D I can't help but notice a question you left behind:
I'm really comfortable doing it if you don't feel like it, but wouldn't want to miss an opportunity to onboard people on the project |
He he, indeed. I was trying to work out if I can do as part of my day job, so as usual it takes a few hoops and loops to jump through. But yes, I just got that approved. BTW, I started drafting something and it seems slightly more complicated than I expected, but of course no rocket science either. Seems like there'll be two slightly different cases depending if input is a file or STDIN. |
@ewjoachim please see the 2 drafts above - do the approaches make sense (and if yes, which of them better fits into design of vault-cli) ? |
Hello :) First allow me to say how sorry I am for not answering you quicker. Last week has been quite a ride as the company I work with (PeopleDoc, which has been sponsoring this project so far) held a week-long event, during which I had nearly no access to a computer :) Now that's over, I want to thank you for taking the time to do this. Reviewing your PRs will among my priorities of today. |
Hello, And no worries at all! I'm fully aware that you're most likely donating a lot of your private time to this and other projects, so I appreciate a lot that vault-cli is available at all in the first place. Take your time and once I have your opinion, I'll see how to make the better of options into something more civilised (and tested). Of course, if you have any other approach in mind, happy to switch to that instead. |
For the record: I was worried that using FileSystemLoader might make it not possible to load a template directly from stdin, but there seems to be a way. Example: from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('./'))
rtemplate = env.from_string("{% include('foo.j2') %} Baz")
templ = env.get_template('foo.j2')
print(templ.render(a='aaaa'))
print(rtemplate.render(a='bbb')) |
Ha yes, I was looking at the doc and was about to suggest using environment.from_string, I’m happy that you reached the same conclusion, this should allow implementing the issue at hand with minimal change in the architecture, so I’m definitely a huge supporter of this way ! Thank you a lot for all the work so far. I’m really glad you could make it. Let’s see what a PR with this solution would look like :) At any point, if you feel like you do not want to continue, just say it. Otherwise, GO FOR IT :D |
Hello, I'm not sure if I was clear in what I advocated in the previous message. I think the way to go is to modify only return jinja2.Template(template).render(vault=vault) have something along the lines of: env = jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
return env.from_string(template).render(vault=vault) Then, we just need an integration test, a quick mention in the README and we're good :) |
Ah, indeed! Let me try that. The one potential issue I see with that would be always using a path relative to the current working directory. From CLI's point of view it makes sense, however for a writer of the templates this might be a bit awkward (while writing a template, you can't anticipate the working directory of someone using that template). It might get especially awkward to use if someone did e.g.
P. S. For me personally. it would be sufficient - so if you're happy with that (documented) limitation, that works for me ;-) |
CC: @bradphipps @jrg1381 |
I'm happy to start that way. Also, we could expose an additional This way, we get the best of both worlds. |
I like the idea of additional parameter; it kind of follows the "explicit rather than implicit" rule (at least in the library part), at the same time being convenient enough to use in CLI. I suppose if there's ever demand, an extra sub-option could be added to the @ewjoachim please see #116 then :-) hopefully it's getting closer? |
Yes, we're almost there :) |
vault template
command crashes with a stacktrace when you try to use it against a Jinja2 template file which containsinclude
, for example:file1:
file2:
The problematic code is here: https://github.com/peopledoc/vault-cli/blob/master/vault_cli/client.py#L465
From https://jinja.palletsprojects.com/en/2.10.x/api/#jinja2.Template
See a discussion on similar subject here: https://stackoverflow.com/questions/39288706/jinja2-load-template-from-string-typeerror-no-loader-for-this-environment-spec
Sample stacktrace:
The text was updated successfully, but these errors were encountered: