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 osv output lockfile + refactor #505

Merged
merged 14 commits into from
Aug 30, 2023

Conversation

another-rex
Copy link
Collaborator

Introduces the osv-scanner results lockfile format (feel free to suggest a better name for this),

This also refactors the models folder slightly to move some of the helper functions out to a separate internal crate. This stops the models package from pulling in the lockfile package, causing cyclic imports.

I also added another field to PackageDetails, Source, a currently optional string to specify the location the dependency is actually specified. The only times it will be different from the lockfile location currently is:

  • Python requirements.txt -r
  • This new osv-scanner format, it stores the lockfile path parsed in the output results.

@G-Rath

This comment was marked as resolved.

"github.com/google/osv-scanner/pkg/models"
)

const OSVScannerEcosystem Ecosystem = "OSV-Scanner-Results"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this required to be defined? IT doesn't seem to be used anywhere, and seems like a weird fit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, removed it now.

pkg/lockfile/parse-requirements-txt.go Outdated Show resolved Hide resolved
@another-rex another-rex mentioned this pull request Aug 28, 2023
another-rex added a commit that referenced this pull request Aug 28, 2023
Pulled refactor out to a separate PR as suggested here: #505 

In this PR:
- Refactored models package to no longer depend on lockfile
- Moved functions that required lockfile types into separate internal
package under `utility/vulns`
- Copied over OSV url from `osv` package to avoid dependency on `osv`
from `output`/`reporter`

I went through and graphed out the dependencies, 

- `models` no longer depends on any internal dependencies
- `lockfile` doesn't depend on any internal dependencies apart from
`cacheexp`
- `osv` brings in both `lockfiles` and `models`. This is probably the
most problematic one. Ideally `osv` should only be referencing `models`,
but it'll be a breaking change to change this API. This is one of the
main things we should change for V2 (related to #442) (TODO: Make
separate issue for this
- `reporter` depends on the internal `output`, which depends on `osv`.
This dependency causes `lockfile` to be pulled into everywhere that
needs to print out anything. This can be decoupled without too much
trouble by copying in the OSV url. I did so in this PR.
- `config` package references `reporter`, with the above change it also
no longer depends on `lockfile`.
@@ -55,11 +78,12 @@ func expectPackage(t *testing.T, packages []lockfile.PackageDetails, pkg lockfil
}
}

func findMissingPackages(actualPackages []lockfile.PackageDetails, expectedPackages []lockfile.PackageDetails) []lockfile.PackageDetails {
func findMissingPackages(t *testing.T, actualPackages []lockfile.PackageDetails, expectedPackages []lockfile.PackageDetails) []lockfile.PackageDetails {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is good by itself along with the hasPackage one, so if you can be bothered I'd favor landing it in its own PR so that this diff is reduced rather than have it wait around for the rest of the changes to get reviewed

Copy link
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

Change itself LGTM, but I have some remaining questions about the Source field we added.

pkg/lockfile/parse-requirements-txt.go Outdated Show resolved Hide resolved
cmd/osv-scanner/main_test.go Outdated Show resolved Hide resolved
@another-rex another-rex merged commit 540b301 into google:main Aug 30, 2023
7 checks passed
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.

4 participants