Skip to content

Get json input, pass it via Jinja2 template and render it. Examples focused on how to get html output for AWS ECR scans, wagoodman/dive, skopeo and others.

License

Notifications You must be signed in to change notification settings

nvtkaszpir/python-json-via-jinja2-render

Repository files navigation

About

Very simple script to get json input, pass it via Jinja2 template to get the output.

Why? Sometimes I got some simple json file and I want to process it into something easier to read, for example text file or html.

Other tools usually do too much already, like extra connecting to internet idk why...

Known limitations

  • not providing pip package, I'm too lazy and this is too simple to package it anyway.... or docker, yeaaaaaaahhh ;)
  • template used is TOTALLY dependent on json file used as input, see examples

Requirements

  • pretty sure it requires python, possibly may work on python 2.x but never tested
  • requires Jinja2

Usage

render.py --help

Examples

  • Just see test.sh for exact usage.
  • See test_extra.sh for more complex examples, also see at the bottom some intereting use cases.
  • For results see examples/ and `'templates/' directory for input/output and template files.
Name Input Template Output
wagoodman/dive HTML input template output
wagoodman/dive plain text input template output
AWS ECR security scan CSV input template output
AWS ECR security scan CSV for failed scan input template output
AWS ECR security scan HTML input template output
AWS ECR security scan HTML for failed scan input template output
AWS ECR security scan plaintext long input template output
AWS ECR security scan plaintext long for failed scan input template output
AWS ECR security scan plaintext short input template output
AWS ECR security scan plaintext short for failed scan input template output
docker inspect plain text to simulate YAML cause we can! input template output
skopeo stdout plaintext as MarkDown input template output

Docker

cat examples/aws_ecr_scan_result.json \
| docker run -v $(pwd)/templates/:/app/templates:ro \
  -i quay.io/kaszpir/python-json-via-jinja2-render \
  -t templates/aws_ecr_scan_result_html.j2 \
> output.html

or with stdin/stdout:

docker run \
    -v "$(pwd)/templates/:/app/templates:ro" \
    -i quay.io/kaszpir/python-json-via-jinja2-render \
        -t templates/aws_ecr_scan_result_html.j2 \
        <examples/aws_ecr_scan_result.json \
        >output.html

Running in container with custom templates

  • Create my_template dir with desired template
  • write my_template/custom.j2 file which is tailored to your json input files
  • Run command to get output to stdout:
cat examples/aws_ecr_scan_result.json \
| docker run -v $(pwd)/my_template/:/app/templates:ro \
  -i quay.io/kaszpir/python-json-via-jinja2-render \
  -t templates/custom.j2 \
>output.html

Testing

  • Run under linux
  • install yq
  • install docker
  • run ./test.sh
  • see generated files, commit and make PR

About

Get json input, pass it via Jinja2 template and render it. Examples focused on how to get html output for AWS ECR scans, wagoodman/dive, skopeo and others.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published