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 cataloger for rust crates from Cargo.lock files #345

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

westonsteimel
Copy link
Contributor

Fixes #338

Signed-off-by: Weston Steimel [email protected]

@luhring luhring requested a review from a team March 18, 2021 15:31
Version: "0.3.9",
Language: pkg.Rust,
Type: pkg.RustPkg,
Licenses: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

is licenses not a thing with Rust packages? if it is, it would be useful to capture that in these tests

Copy link
Contributor Author

@westonsteimel westonsteimel Mar 18, 2021

Choose a reason for hiding this comment

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

No, there isn't any information about licenses available in the Cargo lock file, at least not that I'm aware of

Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting question! I'm very new to Rust 😃 . From what I can tell, @westonsteimel is right about licenses not being stored in cargo.lock files. It looks like they are stored in cargo.toml files (akin to a package.json file), but that'd be a different parser than what's tackled here. We could handle that down the road.

Cargo.toml vs Cargo.lock

The Manifest Format (cargo.toml)

Copy link
Contributor Author

@westonsteimel westonsteimel Mar 18, 2021

Choose a reason for hiding this comment

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

Yes, you can also use the cargo metadata command to output json with everything about all crates and dependencies in the workspace, but that would require executing a command

syft/pkg/metadata.go Outdated Show resolved Hide resolved

import "github.com/anchore/syft/syft/pkg"

type CargoMetadataPackage struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be great raw information to capture onto Package.Metadata (and hint the type via the new MetadataType you added onto Package.MetadataType).

This also implies that we should migrate the struct to the syft/pkg package and rename the struct to CargoPackageMetadata to mirror the naming scheme for other metadata structs in the syft/pkg package.

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'll try to look at that a bit over the weekend. I was a bit unsure on this as I think I was mostly looking at the go modules one as an example (and the python poetry file parser for the toml bits) and it didn't have a metadata component defined under pkg.

Copy link
Contributor

Choose a reason for hiding this comment

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

no problem! Taking a look at the poetry metadata we could have done the same thing (moved it up to pkg/ and expose it via Package.Metadata) but it seems like we didn't (I admit we're being somewhat inconsistent here).

We can also merge this PR as is without capturing the extra cargo metadata onto Package.Metadata --we can always do that in a follow up PR if we find we really need it. Let us know which direction you want to go in, either is OK 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I had a try at this in another branch westonsteimel@8b620de, but I'm running into issues getting the tests to pass. First the unit tests passed, but the integration tests did not, and I was able to figure out that I needed to increment and generate a new json schema file (1.0.3). I did that and the integration tests now pass, but the TestJsonDirsPresenter and TestJsonImgsPresenter unit tests fail because they expect json schema file version 1.0.2 and now get 1.0.3, and I haven't yet figured out how to resolve that one.

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome! I cherry picked that commit over and made a couple minor adjustments:

  • We have snapshots of expected output for the json presenter tests. We use test flags to update the test snapshots: go test ./syft/presenters/json -update and then manually ensure the snapshots are what we expect before committing (I did this already, so no need to update)
  • I updated the MetadataType to reflect where the information was parsed from (a cargo package section)

Copy link
Contributor

@wagoodman wagoodman left a comment

Choose a reason for hiding this comment

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

Solid work, thanks for the contribution! 🚀

@wagoodman wagoodman merged commit cb5e7d0 into anchore:main Mar 22, 2021
@westonsteimel westonsteimel deleted the rust-cargo-cataloger branch March 22, 2021 14:04
@alfredodeza
Copy link
Contributor

congrats @westonsteimel ! Excellent work

@westonsteimel
Copy link
Contributor Author

Thanks everyone!

GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
add cataloger for rust crates from Cargo.lock files
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.

Cataloger for Rust crates from Cargo.lock
4 participants