-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(go): construct dependencies of go.mod
main module in the parser
#7977
Conversation
return pkg.ID, pkg.Relationship == ftypes.RelationshipDirect | ||
}) | ||
|
||
if len(dependsOn) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to put empty elements in CycloneDX, shouldn't we include this relationship regardless of whether len(dependsOn)
is empty?
Components or services that do not have their own dependencies must be declared as empty elements within the graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference now .
pkg.DependsOn
will be nil
(with len(dependsOn) > 0
check) or empty slice (without this check):
trivy/pkg/fanal/analyzer/language/analyze.go
Line 103 in 1f5f348
pkgs[i].DependsOn = deps[pkg.ID] |
When we add relationships in BOM core - we just check length of
DependsOn
field:Lines 249 to 261 in 5dd94eb
for _, dep := range pkg.DependsOn { | |
dependsOn, ok := dependencies[dep] | |
if !ok { | |
continue | |
} | |
e.bom.AddRelationship(c, dependsOn, core.RelationshipDependsOn) | |
} | |
// Components that do not have their own dependencies MUST be declared as empty elements within the graph. | |
// TODO: Should check if the component has actually no dependencies or the dependency graph is not supported. | |
if len(pkg.DependsOn) == 0 { | |
e.bom.AddRelationship(c, nil, "") | |
} |
But it can help with TODO: Should check if the component has actually no dependencies or the dependency graph is not supported.
.
empty slice - pkg supports dependency graph, but doesn't have dependencies.
nil - pkg doesn't support dependency graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 29d73fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some cases, the dependency relationships cannot be correctly identified due to missing $GOPATH or $GOPATH/**/go.mod. We need to add a relationship between a main module and those indirect packages.
trivy/pkg/fanal/analyzer/language/golang/mod/mod.go
Lines 129 to 135 in 29d73fb
// $GOPATH/pkg/mod | |
modPath := filepath.Join(gopath, "pkg", "mod") | |
if !fsutils.DirExists(modPath) { | |
a.logger.Debug("GOPATH not found. Need 'go mod download' to fill licenses and dependency relationships", | |
log.String("GOPATH", modPath)) | |
return nil | |
} |
trivy/pkg/fanal/analyzer/language/golang/mod/mod.go
Lines 167 to 169 in 29d73fb
} else if dep.ID == "" { | |
// go.mod not found | |
continue |
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
539b6ab
to
ef467df
Compare
Signed-off-by: knqyf263 <[email protected]>
Description
Continuation of #7973
Related PRs
workspaceRelationship
#7889Checklist