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

feat: add go struct definitions of OSV record #333

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

michaelkedar
Copy link
Contributor

Moving the struct definitions of the OSV record from osv-scanner to this repository, since it makes more sense to live in the osvschema module.

I've also added the new upstream field to the struct. It's probably worth having a discussion on how to make sure these structs remain in-sync with any future changes to the schema.

//
// See: https://ossf.github.io/osv-schema/#affectedpackage-field
type Package struct {
Ecosystem Ecosystem `json:"ecosystem" yaml:"ecosystem"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if using the Ecosystem type is technically correct here. The constants are defined without the :<RELEASE> suffixes that ecosystems use
(e.g. EcosystemAlpine Ecosystem = "Alpine", but this would hold Alpine:v3.16)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ecosystem should just be string here I believe. On osv-scanner's side we have the Parsed type, but that's not available in osv-schema (since it requires some opinionated decisions.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I've made it a string

Signed-off-by: Michael Kedar <[email protected]>
Copy link
Collaborator

@andrewpollock andrewpollock left a comment

Choose a reason for hiding this comment

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

I personally think this is the right place to consolidate such code, so thanks for creating this PR. Some readability feedback.


// MarshalJSON implements the json.Marshaler interface.
//
// This method ensures times all times are formatted correctly according to the schema.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct comment grammar

Suggested change
// This method ensures times all times are formatted correctly according to the schema.
// This method ensures all times are formatted correctly according to the schema.

"time"
)

// Package identifies the affected code library or command provided by the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Standardize on the verb for consistency

Suggested change
// Package identifies the affected code library or command provided by the
// Package describes the affected code library or command provided by the

DatabaseSpecific map[string]interface{} `json:"database_specific,omitempty" yaml:"database_specific,omitempty"`
}

// Severity is used to describe the severity of a vulnerability for an affected
Copy link
Collaborator

Choose a reason for hiding this comment

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

Standardize for consistency.

Suggested change
// Severity is used to describe the severity of a vulnerability for an affected
// Severity describes the severity of a vulnerability for an affected


// MarshalJSON implements the json.Marshaler interface.
//
// This method ensures Package is only present if it is not equal to the zero value.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to also implicitly meet or explicitly enforce the need for an introduced event here? https://ossf.github.io/osv-schema/#requirements

I'm leaning towards implicitly adding a zero value in the absence of an explicit one over failing when one's absent, for user-friendliness, even though I'm normally very anti implicit behaviours. I'm not seeing any immediate downside from this approach...


// MarshalYAML implements the yaml.Marshaler interface.
//
// This method ensures times all times are formatted correctly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make consistent with MarshalJSON()

Suggested change
// This method ensures times all times are formatted correctly.
// This method ensures times all times are formatted correctly according to the schema.

// and so on about the vulnerability itself.
//
// See: https://ossf.github.io/osv-schema/#references-field
type Reference struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we consolidate all of the types before the funcs, for readability?

// in the life cycle of a vulnerability.
//
// See: https://ossf.github.io/osv-schema/#credits-fields
type Credit struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we consolidate all of the types before the funcs?

URL string `json:"url" yaml:"url"`
}

// Credit gives credit for the discovery, confirmation, patch, or other events
Copy link
Collaborator

Choose a reason for hiding this comment

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

Standardize for consistency.

Suggested change
// Credit gives credit for the discovery, confirmation, patch, or other events
// Credit describes who to give credit to for the discovery, confirmation, patch, or other events

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