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

Add a folder with go templates #1316

Closed
YevheniiPokhvalii opened this issue May 25, 2023 · 6 comments
Closed

Add a folder with go templates #1316

YevheniiPokhvalii opened this issue May 25, 2023 · 6 comments
Labels
enhancement New feature or request good-first-issue Good for newcomers

Comments

@YevheniiPokhvalii
Copy link
Contributor

YevheniiPokhvalii commented May 25, 2023

It would be nice to have a go templates folder with examples, like Trivy has: https://github.com/aquasecurity/trivy/tree/main/contrib

Their templates are not compatible with Grype, unfortunately.
I need an XML JUnit output format and it's a pain to create a template from scratch.

@YevheniiPokhvalii YevheniiPokhvalii added the enhancement New feature or request label May 25, 2023
@YevheniiPokhvalii
Copy link
Contributor Author

YevheniiPokhvalii commented May 26, 2023

I made a simple JUnit XML Go template that works with Grype. It might be useful to someone:

grype docker_image -o template -t grype-junit.tpl
<?xml version="1.0" ?>
<testsuites name="grype-junit">
{{- $failures := len $.Matches }}
    <testsuite tests="{{ $failures }}" failures="{{ $failures }}" name="{{ $.Distro.Name }}:{{ $.Distro.Version }}" errors="0" skipped="0">
        <properties>
            <property name="type" value="{{ $.Distro.Name }}"></property>
        </properties>
        {{- range .Matches }}
        <testcase classname="{{ .Artifact.Name }}-{{ .Artifact.Version }} ({{ .Artifact.Type }})" name="[{{ .Vulnerability.Severity }}] {{ .Vulnerability.ID }}">
            <failure message="{{ .Artifact.Name }}: {{ .Vulnerability.ID }}" type="description">{{ .Vulnerability.Description }} {{ .Artifact.CPEs }} {{ .Vulnerability.DataSource }}</failure>
        </testcase>
        {{- end }}
    </testsuite>
</testsuites>

@spiffcs spiffcs added the good-first-issue Good for newcomers label Jun 8, 2023
@spiffcs
Copy link
Contributor

spiffcs commented Jun 8, 2023

This sounds like a good idea! I'll throw it into our backlog for a team member to grab when they have cycles.

We also would love to have community PR that gets this effort started -

The best kind of PR would be an example CSV or HTML template that we could use to help people get started

If someone contributes this please put your name at the top of the template so users can understand who to query if there are any future issues =)

@spiffcs
Copy link
Contributor

spiffcs commented Jun 9, 2023

@YevheniiPokhvalii #1343 was merged - so we now have a folder where you can contribute your Junit template along with some starter documentation. Let me know if you need help getting it contributed!

@spiffcs spiffcs closed this as completed Jun 9, 2023
@willmurphyscode willmurphyscode changed the title A folder with go templates like in Trivy repo Add a folder with go templates Jun 21, 2023
@anaynayak
Copy link

Thanks @YevheniiPokhvalii for sharing that snippet. Are you planning to contribute that template? Otherwise I don't mind helping and would love to see it integrated into grype.

@kzantow
Copy link
Contributor

kzantow commented Aug 8, 2023

Yeah, that looks like a great one to add to the sample templates here: https://github.com/anchore/grype/tree/main/templates -- I'd love to see you get credit for the contribution @YevheniiPokhvalii !

@YevheniiPokhvalii
Copy link
Contributor Author

Thank you. Since this one is useful, I created a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good-first-issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

4 participants