Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/cvetool/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

ds_sqlite "github.com/ComplianceAsCode/cvetool/datastore/sqlite"
"github.com/quay/claircore/libvuln"
"github.com/quay/claircore/libvuln/driver"
_ "github.com/quay/claircore/updater/defaults"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -66,6 +67,32 @@ func update(c *cli.Context) error {
UpdaterSets: []string{"rhel-vex", "clair.cvss"},
}

// Check last update time
updateOps, err := matcherStore.GetUpdateOperations(ctx, driver.VulnerabilityKind)
if err != nil {
return fmt.Errorf("error getting update operations: %v", err)
}

// Find the most recent update time across all updaters
var lastUpdate time.Time
for _, ops := range updateOps {
if len(ops) > 0 {
// ops are sorted by date descending, so first element is most recent
if ops[0].Date.After(lastUpdate) {
lastUpdate = ops[0].Date
}
}
}

if !lastUpdate.IsZero() {
fmt.Printf("Last update: %s (%s ago)\n", lastUpdate.Format(time.RFC1123), time.Since(lastUpdate).Round(time.Second))
if time.Since(lastUpdate) > (24 * time.Hour * 30) {
return fmt.Errorf("Database more than 30 days old, refusing to update. Delete the database and run this commmand again.")
}
} else {
fmt.Println("No previous updates found in database")
}

lv, err := libvuln.New(ctx, matcherOpts)
if err != nil {
return fmt.Errorf("error creating Libvuln: %v", err)
Expand Down