-
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
fix(java): check if a version exists when determining GAV by file name for jar
files
#5630
fix(java): check if a version exists when determining GAV by file name for jar
files
#5630
Conversation
pkg/javadb/client.go
Outdated
@@ -142,37 +142,49 @@ func (d *DB) SearchBySHA1(sha1 string) (jar.Properties, error) { | |||
}, nil | |||
} | |||
|
|||
func (d *DB) SearchByArtifactID(artifactID string) (string, error) { | |||
func (d *DB) SearchByArtifactID(artifactID, version string) (string, error) { | |||
indexes, err := d.driver.SelectIndexesByArtifactIDAndFileType(artifactID, types.JarType) |
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.
What if changing this method to match the version as well as the artifact ID?
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.
Do you mean just to move the following logic to trivy-java-db
?
Lines 157 to 188 in 2f10ed1
func foundGroupID(version string, indexes []types.Index) string { | |
var groupID, maxGroupID string | |
var count, maxCount int | |
var versionFound bool | |
sort.Slice(indexes, func(i, j int) bool { | |
return indexes[i].GroupID < indexes[j].GroupID | |
}) | |
for _, index := range indexes { | |
if index.GroupID != groupID { | |
// save a new GroupID with the max number of indexes (if this GroupID contains the required version) | |
if count > maxCount && versionFound { | |
maxGroupID = groupID | |
maxCount = count | |
} | |
count = 0 | |
versionFound = false | |
} | |
// iterate over all indexes of the current GroupID | |
groupID = index.GroupID | |
count++ | |
if index.Version == version { | |
versionFound = true | |
} | |
} | |
// save latest groupID | |
if count > maxCount && versionFound { | |
maxGroupID = groupID | |
} | |
return maxGroupID | |
} |
Or update our sql query in trivy-java-db
?
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.
I meant SQL query. Is it possible?
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.
I need more knowledge on SQL.
I will try to do this and then write to you.
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.
I created aquasecurity/trivy-java-db#23 and updated this PR.
Take a look, when you have time, please.
…ck-version-when-search-gav-by-filename
…ck-version-when-search-gav-by-filename
@knqyf263 i updated |
Description
See #5627
Related issues
Related PRs
Checklist