Skip to content
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

Provide the default template under the templates path #2171

Open
samueloph opened this issue Oct 8, 2024 · 3 comments
Open

Provide the default template under the templates path #2171

samueloph opened this issue Oct 8, 2024 · 3 comments
Labels
enhancement New feature or request needs-discussion
Milestone

Comments

@samueloph
Copy link

What would you like to be added:
I would love if the default template for the json output format was provided under the templates path: https://github.com/anchore/grype/tree/main/templates

Even better if all the other formats were provided there as examples too.

Why is this needed:
It makes it much easier to craft my own template as I can start from the json one and just remove the fields I don't want.

Additional context:

@samueloph samueloph added the enhancement New feature or request label Oct 8, 2024
@willmurphyscode
Copy link
Contributor

Thanks @samueloph! I've added needs-discussion so that we can talk at an upcoming community meeting about how best to implement this. Right now, there isn't a "default template," but rather Grype JSON serializes some golang structs.

I agree that it would be good change this to using a template so that it's less opaque to users, and we are hoping to stabilize and document the JSON output schema as we work towards grype 1.0, so this all seems to fit together nicely.

@willmurphyscode willmurphyscode added this to the Grype 1.0 milestone Oct 9, 2024
@willmurphyscode
Copy link
Contributor

We discussed this at our livestream community gardening on 10 October 2024.

Some notes:

  1. We do not want to write Go templating language that writes JSON - we want to stick to serializing Go structs natively
  2. We would be interested in providing some query flags, like --fields and --filter, so subset Grype's output directly, without templating
  3. We'd like to add a JSON schema document to Grype, and add some structs whose purpose is to be models used to serialize for the output as part of this.

@samueloph if you could run something like grype -o json --filter "severity>medium" --fields "package.type, vulnerability.fixed_in_versions" or something, would that meet your needs?

@samueloph
Copy link
Author

@willmurphyscode

if you could run something like grype -o json --filter "severity>medium" --fields "package.type, vulnerability.fixed_in_versions" or something, would that meet your needs?

It would, my use case is that I'm running grype against roughly 300 different images constantly and I'm storing its results for metrics purposes.

Since I have to store so many results, I'm trying to redact some of the fields that I don't need, and I struggled a bit with understanding from which template to start with.

For reference, the workaround I'm doing right now is to json.loads the dict in my python script and then calling del to remove the fields for each report. It can be slightly costly because I need to iterate on the matches of each report (while iterating on each report), but it's saving me roughly 150MB of output for each run (I'm only doing the bare minimum filtering through the script).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-discussion
Projects
Status: No status
Development

No branches or pull requests

2 participants