Skip to content

Commit

Permalink
libvuln: implement DeltaUpdateVulnerabilities for jsonblob store
Browse files Browse the repository at this point in the history
This change ensures that any updater that implement the delta update
flow also have their vulnerabilities persisted in the jsonblob store.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
  • Loading branch information
crozzy committed May 21, 2024
1 parent 5b7c8e0 commit 9cf6649
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libvuln/jsonblob/jsonblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ func (s *Store) RecordUpdaterSetStatus(ctx context.Context, updaterSet string, u
return nil
}

// DeltaUpdateVulnerabilities is a noop
// DeltaUpdateVulnerabilities just calls UpdateVulnerabilities. In the jsonblob flow it is assumed that
// we're always starting from zero.
// Note: deleted is ignored.
func (s *Store) DeltaUpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability, deleted []string) (uuid.UUID, error) {
return uuid.Nil, nil
return s.UpdateVulnerabilities(ctx, updater, fingerprint, vulns)
}

// UpdateEnrichmentsIter is unimplemented.
Expand Down
29 changes: 29 additions & 0 deletions libvuln/jsonblob/jsonblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,32 @@ func TestEnrichments(t *testing.T) {
}
t.Logf("wrote:\n%s", buf.String())
}

func TestDeltaUpdaters(t *testing.T) {
s, err := New()
if err != nil {
t.Fatal(err)
}
ctx := context.Background()

numVulns := 10
vs := test.GenUniqueVulnerabilities(numVulns, "test")
ref, err := s.DeltaUpdateVulnerabilities(ctx, "test", "", vs, []string{})
if err != nil {
t.Error(err)
}
t.Logf("ref: %v", ref)

var buf bytes.Buffer
if err := s.Store(&buf); err != nil {
t.Error(err)
}
t.Logf("wrote:\n%s", buf.String())
lnCt := 0
for _, err := buf.ReadBytes('\n'); err == nil; _, err = buf.ReadBytes('\n') {
lnCt++
}
if lnCt != numVulns {
t.Errorf("expected %d vulns but got %d", numVulns, lnCt)
}
}

0 comments on commit 9cf6649

Please sign in to comment.