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 dotnet deps parsing #258

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

Add dotnet deps parsing #258

wants to merge 3 commits into from

Conversation

noqcks
Copy link

@noqcks noqcks commented Sep 20, 2023

Signed-off-by: Benji Visser <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Sep 20, 2023

CLA assistant check
All committers have signed the CLA.

@DmitriyLewen
Copy link
Collaborator

Hello @noqcks
Thanks for your work!

I will check your PR and write to you.

@DmitriyLewen DmitriyLewen self-requested a review September 21, 2023 02:39
Copy link
Collaborator

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

Hello @noqcks
Left some comments. Take a look, when you have time, please

pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
if !strings.EqualFold(lib.Type, "package") {
var deps []types.Dependency
for pkgNameVersion, target := range depsFile.Targets[depsFile.RuntimeTarget.Name] {
library, ok := depsFile.Libraries[pkgNameVersion]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we discuss about this:

It looks like we can take package name and version from pkgNameVersion.
Do we need to check "Libraries"?
Is this necessary for backwards compatibility?

Copy link
Author

Choose a reason for hiding this comment

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

I think I did this initially because I wanted to keep track of whether a Library was a project or not and then be able to set the CycloneDX componentType in response, but I don't think go-dep-parser keeps track of this? I don't see any field on the Library struct that would allow us to set something resembling componentType

Copy link
Author

Choose a reason for hiding this comment

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

So, in this case, we don't need to check Libraries at all

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think go-dep-parser keeps track of this

We set componentType in Trivy.

I wanted to keep track of whether a Library was a project or not

We currently take only packages -

if !strings.EqualFold(lib.Type, "package") {

For project we use application type with filepath as name:

➜  trivy -d fs -f cyclonedx pkg/dotnet/core_deps/testdata/ExampleApp1.deps.json | jq '.components[] | select(.type == "application")'
...
{
  "bom-ref": "908ce44b-3644-44ce-b282-8f0d44566e20",
  "type": "application",
  "name": "ExampleApp1.deps.json",
  "properties": [
    {
      "name": "aquasecurity:trivy:Class",
      "value": "lang-pkgs"
    },
    {
      "name": "aquasecurity:trivy:Type",
      "value": "dotnet-core"
    }
  ]
}

pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
pkg/dotnet/core_deps/parse.go Outdated Show resolved Hide resolved
pkg/dotnet/core_deps/parse_test.go Show resolved Hide resolved
{
file: "testdata/MyExample.deps.json",
wantLibs: []types.Library{
{ID: "[email protected]", Name: "MyWebApp", Version: "1.0.0", Locations: []types.Location{{StartLine: 148, EndLine: 152}}},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there reason to add project to result?
We didn't include this earlier:

if !strings.EqualFold(lib.Type, "package") {

Copy link
Author

Choose a reason for hiding this comment

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

yes, because otherwise you can't extract a full and complete dependency tree if you need to parse the SBOM

Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes sense for SBOM, but can be confusing when used by default (like json format).
We save project in dependencies. This can be confusing.

Perhaps we need to add new type or field for Library for project name/version. But I think it is change for another PR.

We use application componentType for SBOM - #258 (comment)
Previously this was enough.

@noqcks noqcks requested a review from DmitriyLewen October 10, 2023 17:04
Signed-off-by: Benji Visser <[email protected]>
@noqcks
Copy link
Author

noqcks commented Oct 10, 2023

@DmitriyLewen ready for another review

Copy link
Collaborator

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

I left 2 small comment. Take a look, please.

Also i understood that MyExample.deps.json already contains dependencies.
Do we need new test file or will MyExample.deps.json be enough?

@@ -19,6 +21,20 @@ func NewParser() types.Parser {
return &Parser{}
}

func packageID(name, version string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func packageID(name, version string) string {
// .NET uses `<name>/<version>` ID format:
// https://github.com/dotnet/cli/blob/f0ee1e44114f161ce9268103d18ce32d2a995d0f/Documentation/specs/runtime-configuration-file.md?plain=1#L87
func packageID(name, version string) string {

}

return libraries, nil, nil
return libraries, deps, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Libraries and Dependencies can be sorted.

Suggested change
return libraries, deps, nil
sort.Sort(types.Libraries(libs))
sort.Sort(types.Dependencies(deps))
return libraries, deps, nil

After these changes you can remove sorting from tests.

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.

Incorrect .NET deps parsing
3 participants