Skip to content

Commit

Permalink
Ensure render-templates only creates/truncates the "destination" if…
Browse files Browse the repository at this point in the history
… the template renders successfully.
  • Loading branch information
nathan-muir committed Oct 11, 2016
1 parent d56796a commit b15a1e8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions credsmash/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def cmd_render_template(
if not manifest_format:
manifest_format = detect_format(manifest, 'json')
for entry in parse_manifest(manifest, manifest_format):
with codecs.open(entry['source'], 'r', encoding='utf-8') as template, \
codecs.open(entry['destination'], 'w', encoding='utf-8') as destination:
with codecs.open(entry['source'], 'r', encoding='utf-8') as template:
output = env.from_string(template.read()).render(**{
obj_name: secrets
})
# Only open the file after rendering the template
# as we truncate the file when opening.
with codecs.open(entry['destination'], 'w', encoding='utf-8') as destination:
destination.write(output)

if 'mode' in entry:
Expand Down

0 comments on commit b15a1e8

Please sign in to comment.