github.com/quay/claircore@v1.5.28/datastore/updater.go (about) 1 package datastore 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/google/uuid" 8 9 "github.com/quay/claircore" 10 "github.com/quay/claircore/libvuln/driver" 11 ) 12 13 // VulnerabilityIter is an [Iter] of vulnerabilities. 14 type VulnerabilityIter Iter[*claircore.Vulnerability] 15 16 // Updater is an interface exporting the necessary methods 17 // for updating a vulnerability database. 18 type Updater interface { 19 EnrichmentUpdater 20 21 // UpdateVulnerabilities creates a new UpdateOperation, inserts the provided 22 // vulnerabilities, and ensures vulnerabilities from previous updates are 23 // not queried by clients. 24 UpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability) (uuid.UUID, error) 25 // UpdateVulnerabilitiesIter performs the same operation as 26 // UpdateVulnerabilities, but accepting an iterator function. 27 UpdateVulnerabilitiesIter(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulnIter VulnerabilityIter) (uuid.UUID, error) 28 // DeltaUpdateVulnerabilities creates a new UpdateOperation consisting of existing 29 // vulnerabilities and new vulnerabilities. It also takes an array of deleted 30 // vulnerability names which should no longer be available to query. 31 DeltaUpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability, deletedVulns []string) (uuid.UUID, error) 32 // GetUpdateOperations returns a list of UpdateOperations in date descending 33 // order for the given updaters. 34 // 35 // The returned map is keyed by Updater implementation's unique names. 36 // 37 // If no updaters are specified, all UpdateOperations are returned. 38 GetUpdateOperations(context.Context, driver.UpdateKind, ...string) (map[string][]driver.UpdateOperation, error) 39 // GetLatestUpdateRefs reports the latest update reference for every known 40 // updater. 41 GetLatestUpdateRefs(context.Context, driver.UpdateKind) (map[string][]driver.UpdateOperation, error) 42 // GetLatestUpdateRef reports the latest update reference of any known 43 // updater. 44 GetLatestUpdateRef(context.Context, driver.UpdateKind) (uuid.UUID, error) 45 // DeleteUpdateOperations removes an UpdateOperation. 46 // A call to GC must be run after this to garbage collect vulnerabilities associated 47 // with the UpdateOperation. 48 // 49 // The number of UpdateOperations deleted is returned. 50 DeleteUpdateOperations(context.Context, ...uuid.UUID) (int64, error) 51 // GetUpdateOperationDiff reports the UpdateDiff of the two referenced 52 // Operations. 53 // 54 // In diff(1) terms, this is like 55 // 56 // diff prev cur 57 // 58 GetUpdateDiff(ctx context.Context, prev, cur uuid.UUID) (*driver.UpdateDiff, error) 59 // GC will delete any update operations for an updater which exceeds the provided keep 60 // value. 61 // 62 // Implementations may throttle the GC process for datastore efficiency reasons. 63 // 64 // The returned int64 value indicates the remaining number of update operations needing GC. 65 // Running this method till the returned value is 0 accomplishes a full GC of the vulnstore. 66 GC(ctx context.Context, keep int) (int64, error) 67 // Initialized reports whether the vulnstore contains vulnerabilities. 68 Initialized(context.Context) (bool, error) 69 // RecordUpdaterStatus records that an updater is up to date with vulnerabilities at this time 70 RecordUpdaterStatus(ctx context.Context, updaterName string, updateTime time.Time, fingerprint driver.Fingerprint, updaterError error) error 71 // RecordUpdaterSetStatus records that all updaters from an updater set are up to date with vulnerabilities at this time 72 RecordUpdaterSetStatus(ctx context.Context, updaterSet string, updateTime time.Time) error 73 }