def template( client_obj: client.VaultClientBase, template: TextIO, output: TextIO ) -> None: """ Render the given template and insert secrets in it. Rendering is done with jinja2. A vault() function is exposed that recieves a path and outputs the secret at this path. If template is -, standard input will be read. """ result = client_obj.render_template(template.read()) output.write(result)
def template(client_obj: client.VaultClientBase, template: str, output: TextIO) -> None: """ Render the given template and insert secrets in it. Rendering is done with Jinja2. A vault() function is exposed that receives a path and outputs the secret at this path. Search path (see https://jinja.palletsprojects.com/en/2.10.x/api/#jinja2.FileSystemLoader) for possible Jinja2 `{% include() %}` statement is set to the template's directory. If template is -, standard input will be read and the current working directory becomes the search path. """ if template == "-": template_text = sys.stdin.read() search_path = pathlib.Path.cwd() else: template_path = pathlib.Path(template) template_text = template_path.read_text() search_path = template_path.parent result = client_obj.render_template(template_text, search_path=search_path) output.write(result)