Skip to content

Commit

Permalink
notifier: optionally disable per-manifest summary
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Dec 1, 2020
1 parent c18563d commit dd2e16d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
5 changes: 3 additions & 2 deletions notifier/postgres/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/jmoiron/sqlx"
"github.com/quay/clair/v4/notifier"
"github.com/quay/claircore"
cctest "github.com/quay/claircore/test"
"github.com/quay/claircore/test/integration"

"github.com/quay/clair/v4/notifier"
)

const (
Expand All @@ -27,7 +28,7 @@ func TestE2E(t *testing.T) {
notificationID := uuid.New()
// this function puts a single noification undertest
vuln, vsummary := cctest.GenUniqueVulnerabilities(1, updater)[0], notifier.VulnSummary{}
vsummary.FromVulnerability(*vuln)
vsummary.FromVulnerability(vuln)
notifications := []notifier.Notification{
{
Manifest: digest,
Expand Down
38 changes: 25 additions & 13 deletions notifier/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"fmt"

"github.com/google/uuid"
clairerror "github.com/quay/clair/v4/clair-error"
"github.com/quay/clair/v4/indexer"
"github.com/quay/clair/v4/matcher"
"github.com/quay/claircore"
"github.com/quay/claircore/libvuln/driver"
"github.com/quay/claircore/pkg/distlock"
"github.com/rs/zerolog"

clairerror "github.com/quay/clair/v4/clair-error"
"github.com/quay/clair/v4/indexer"
"github.com/quay/clair/v4/matcher"
)

// Processor listen for new UOIDs, creates notifications, and persists
Expand All @@ -21,6 +22,12 @@ import (
// Processor(s) create atomic boundaries, no two Processor(s) will be creating
// notifications for the same UOID at once.
type Processor struct {
// NoSummary controls whether per-manifest vulnerability summarization
// should happen.
NoSummary bool
// NoSummary is a little awkward to use, but reversing the boolean this way
// makes the defaults line up better.

// distributed lock used for mutual exclusion
distLock distlock.Locker
// a handle to an indexer service
Expand Down Expand Up @@ -146,21 +153,26 @@ func (p *Processor) create(ctx context.Context, e Event, prev uuid.UUID) error {
notifications := []Notification{}
create := func(r Reason, affected claircore.AffectedManifests) error {
for manifest, vulns := range affected.VulnerableManifests {
// summarize most severe vuln affecting manifest
// the vulns array will be sorted by most severe
vuln := affected.Vulnerabilities[vulns[0]]

digest, err := claircore.ParseDigest(manifest)
if err != nil {
return err
}
n := Notification{
Manifest: digest,
Reason: r,
}
n.Vulnerability.FromVulnerability(*vuln)
// The vulns slice is sorted most severe to lease severe.
for i := range vulns {
vuln := affected.Vulnerabilities[vulns[i]]

n := Notification{
Manifest: digest,
Reason: r,
}
n.Vulnerability.FromVulnerability(vuln)

notifications = append(notifications, n)
notifications = append(notifications, n)

if !p.NoSummary {
break
}
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion notifier/vulnsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type VulnSummary struct {
Links string `json:"links"`
}

func (vs *VulnSummary) FromVulnerability(v claircore.Vulnerability) {
func (vs *VulnSummary) FromVulnerability(v *claircore.Vulnerability) {
*vs = VulnSummary{
Name: v.Name,
Description: v.Description,
Expand Down

0 comments on commit dd2e16d

Please sign in to comment.