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

Ability to output to JSON #230

Merged
merged 6 commits into from
Nov 3, 2021
Merged

Conversation

amithkk
Copy link
Contributor

@amithkk amithkk commented Oct 3, 2021

This pull request adds support for creating JSON SPDX SBOMs (thereby resolving #117 if merged)

This is achieved by

  • Making the formatter/renderer modular (now implemented by a go interface)
  • Passing down the -f argument to the renderer so that it can use the appropriate implementation
  • Updating the Document and Package structs (which are now annotated as per the official JSON spec/example) to better resemble the structure specified by the SPDX spec
  • Updating the filename resolution logic to take into consideration the format passed down by the user

Additionally, this pull request also completes the todo item of reimplementing the tag-value format (.spdx) renderer as a go template.

Signed-off-by: Amith K K <amithkumaran@gmail.com>
Signed-off-by: Amith K K <amithkumaran@gmail.com>
@seabass-labrax
Copy link
Contributor

@amithkk, thank you for this pull request and welcome to SPDX! :)

We have a conference call meeting on Tuesday if you'd like to join - it's at 16:00 UTC; all the details are at https://wiki.spdx.org/view/Technical_Team. I'm sure everyone would love to see your contribution!

pkg/models/spdx.go Outdated Show resolved Hide resolved
@seabass-labrax
Copy link
Contributor

It seems as if the generated JSON may contain duplicate SPDX Elements. Running the command on this repository, there are multiple definitions of SPDXRef-Package-golang.org.x.sys-v0.0.0-20200302150141-5c8b2ff67527 for instance (see attached file sbom.txt).

… tag for struct

Signed-off-by: Amith K K <amithkumaran@gmail.com>
@amithkk
Copy link
Contributor Author

amithkk commented Oct 3, 2021

@seabass-labrax Thank you for the warm welcome 😄

Nice catch! That was caused by subpackages also being added to the document's packages array. I've updated the pull request to address that and the typo in the json tags.

Will try to join the technical meeting

@amithkk amithkk force-pushed the main branch 2 times, most recently from 018457e to b4a9852 Compare October 4, 2021 04:30
Signed-off-by: Amith K K <amithkumaran@gmail.com>
@seabass-labrax
Copy link
Contributor

Brilliant! There are just two things to change and then this should generate schema-valid SPDX JSON documents :)

  1. namespace on the Document Information section needs to be changed to documentNamespace for the JSON output (but not for the tag/value output)
  2. packages should have filesAnalyzed set to "False" since their individual files are not hashed for the PVC (Package Verification Code)

Your idea of using a template for generating the tag/value data is really nice too; it might be worth rebasing the commits to make this change more visible to other developers.

Looking forward to hearing from you at today's meeting if you can make it :)

Updated asserted package checksums to be in checksums[] array for JSON, update logic appropriately in Tag Value renderer

Signed-off-by: Amith K K <amithkumaran@gmail.com>
@amithkk
Copy link
Contributor Author

amithkk commented Oct 5, 2021

@seabass-labrax Thanks for the review! Addressed those comments in my previous commit. I've also updated the checksums[] array to appropriately render and have also validated the resulting SBOM against a JSONSchema validator to double check.

@seabass-labrax
Copy link
Contributor

@niravpatel27, would you be able to merge this please? Thanks :)

@niravpatel27
Copy link
Collaborator

@seabass-labrax sorry everyone, I got really busy on something and missed this one. I will be on it.

Signed-off-by: Amith <amithkumaran@gmail.com>
Signed-off-by: GitHub <noreply@github.com>
@amithkk
Copy link
Contributor Author

amithkk commented Oct 27, 2021

I've updated the branch to add the missing license identifiers for the two new code files

@amithkk
Copy link
Contributor Author

amithkk commented Nov 3, 2021

Hi @niravpatel27, hope you are doing well 😄 - any updates on this?

@niravpatel27 niravpatel27 merged commit 9ec8e17 into opensbom-generator:main Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants