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 ability to merge matches #602

Merged
merged 6 commits into from Jan 25, 2022
Merged

Add ability to merge matches #602

merged 6 commits into from Jan 25, 2022

Conversation

wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Jan 25, 2022

Primarily this PR adds the ability to merge two matches that have the same vulnerability-package pair, but the matching details may be different (what was searched by, what attribute was matched on, the matcher that found the result, etc). In the case of merging the list of match.Details is combined and one match object is kept.

This PR additionally makes the following adjustments:

  • updates tests fixtures that use package objects to have package IDs
  • updates the match.NewMatches() constructor to take an initial variadic list of matches
  • renames/moves the matchers.common package to search which makes usage less awkward and more semantically correct (the matchers use search utilities, not common utilities... e.g. common.FindMatchesByPackageLanguage(...) --> search.ByPackageLanguage(...))
  • adds search.ByCriteria to reduce the code for each matcher object. This turns the old approach:
	var matches = make([]match.Match, 0)
	langMatches, err := common.FindMatchesByPackageLanguage(store, p.Language, p, m.Type())
	if err != nil {
		return nil, err
	}
	matches = append(matches, langMatches...)

	cpeMatches, err := common.FindMatchesByPackageCPE(store, p, m.Type())
	if err != nil {
		return nil, err
	}
	matches = append(matches, cpeMatches...)
        return matches, nil

into:

       return search.ByCriteria(store, d, p, m.Type(), search.ByLanguage, search.ByCPE)

This work is loosely related to #395

@wagoodman wagoodman requested a review from a team January 25, 2022 14:22
@wagoodman wagoodman self-assigned this Jan 25, 2022
@wagoodman wagoodman added the enhancement New feature or request label Jan 25, 2022
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Copy link
Contributor

@spiffcs spiffcs left a comment

Choose a reason for hiding this comment

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

No nits or large comments. This is a huge upgrade that people can start using immediately both within the binary and when they consume grype as a library

cmd/root_test.go Show resolved Hide resolved
grype/match/type.go Show resolved Hide resolved
grype/matcher/ruby/matcher.go Show resolved Hide resolved
@wagoodman wagoodman merged commit 2f8682b into main Jan 25, 2022
@wagoodman wagoodman deleted the handle-match-merging branch January 25, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants