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

Plugin: Add example for SPDX SBOM generator plugin #307

Open
wants to merge 1 commit into
base: experimental
Choose a base branch
from

Conversation

nishakm
Copy link
Collaborator

@nishakm nishakm commented Jan 12, 2024

  • Includes the plugin package which is an interface to be implemented by plugins.
  • Includes an example of an implementation of a plugin where a pom.xml file is parsed and the data is used to create an SPDX 2.3 JSON document.

@nishakm
Copy link
Collaborator Author

nishakm commented Jan 12, 2024

@puerco @ba11b0y, this is my example of how we can write an SPDX plugin.

@rjb4standards
Copy link

rjb4standards commented Jan 12, 2024 via email

- Includes the `plugin` package which is an interface to be implemented
  by plugins.
- Includes an example of an implementation of a plugin where a pom.xml
  file is parsed and the data is used to create an SPDX 2.3 JSON
  document.

Signed-off-by: Nisha Kumar <nisha.kumar@oracle.com>
@nishakm
Copy link
Collaborator Author

nishakm commented Jan 13, 2024

@rjb4standards Hi Dick, wow really? I believe Tern and Syft can generate SPDX V 2.3 SBOMs now. This is just an example of how this particular project can be used as an entrypoint for which other file/package analyzers can write plugins for.

@rjb4standards
Copy link

rjb4standards commented Jan 13, 2024 via email

Copy link
Member

@puerco puerco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments!

Comment on lines +12 to +14
type Plugin interface {
GetSpdxDocument() (common.AnyDocument, error)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not leverage the plugin object we're putting together in the parsers project? It is the project's plugin afterall:

https://github.com/opensbom-generator/parsers/blob/b759eb1245d6c3ea39a27fd658fa3624a4dcb1bf/plugin/plugin.go#L7-L16


// plugins stores a mapping of the plugin name and its
// corresponding Plugin object
var plugins = make(map[string]Plugin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the name we're using to key supposed to be used? Will we support more than one plugin for each ecosystem? I see it is the argument to GetPlugin() but should we have a keying scheme tied to the specific ecosystem?

I expect to look for plugins based on what the generator finds in the code repository, so more than a name should this be an ecocystem label or another moniker?

// init function
func Register(name string, p Plugin) {
if p == nil {
panic("A Plugin object is required, but is nil")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a plugin system potentially used by third parties, don't panic here. Return an error and let the application handle it.


In this example, we will parse an example pom.xml file and create an SPDX document with the data. The plugin is called `mvnpom`. We use an existing pom.xml parser to get the data. We have restricted parsing to only SPDX 2.3 as the SPDX version and JSON as the data format, but other versions and formats can be supported.

The required function to implement for the plugin is the `GetSpdxDocument` method. This must return an object of type `AnyDocument`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think about it, the plugin's job is not to return the document. The plugin should only return a data structure representing the data it knows about (probably a package representing the code and its dependencies). That structure may be part of a document with more than one code repository, for example.

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.

None yet

3 participants