|
9 | 9 |
|
10 | 10 | ds_sqlite "github.com/ComplianceAsCode/cvetool/datastore/sqlite" |
11 | 11 | "github.com/quay/claircore/libvuln" |
| 12 | + "github.com/quay/claircore/libvuln/driver" |
12 | 13 | _ "github.com/quay/claircore/updater/defaults" |
13 | 14 | "github.com/urfave/cli/v2" |
14 | 15 | ) |
@@ -66,6 +67,32 @@ func update(c *cli.Context) error { |
66 | 67 | UpdaterSets: []string{"rhel-vex", "clair.cvss"}, |
67 | 68 | } |
68 | 69 |
|
| 70 | + // Check last update time |
| 71 | + updateOps, err := matcherStore.GetUpdateOperations(ctx, driver.VulnerabilityKind) |
| 72 | + if err != nil { |
| 73 | + return fmt.Errorf("error getting update operations: %v", err) |
| 74 | + } |
| 75 | + |
| 76 | + // Find the most recent update time across all updaters |
| 77 | + var lastUpdate time.Time |
| 78 | + for _, ops := range updateOps { |
| 79 | + if len(ops) > 0 { |
| 80 | + // ops are sorted by date descending, so first element is most recent |
| 81 | + if ops[0].Date.After(lastUpdate) { |
| 82 | + lastUpdate = ops[0].Date |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + if !lastUpdate.IsZero() { |
| 88 | + fmt.Printf("Last update: %s (%s ago)\n", lastUpdate.Format(time.RFC1123), time.Since(lastUpdate).Round(time.Second)) |
| 89 | + if time.Since(lastUpdate) > (24 * time.Hour * 30) { |
| 90 | + return fmt.Errorf("Database more than 30 days old, refusing to update. Delete the database and run this commmand again.") |
| 91 | + } |
| 92 | + } else { |
| 93 | + fmt.Println("No previous updates found in database") |
| 94 | + } |
| 95 | + |
69 | 96 | lv, err := libvuln.New(ctx, matcherOpts) |
70 | 97 | if err != nil { |
71 | 98 | return fmt.Errorf("error creating Libvuln: %v", err) |
|
0 commit comments