From 004dd394e4358f412e8359306c545d9ef4a2a871 Mon Sep 17 00:00:00 2001 From: crozzy Date: Mon, 17 Mar 2025 13:28:55 -0700 Subject: [PATCH] dev: todo: indexer data API Need to split and update. Signed-off-by: crozzy --- datastore/postgres/additionaldata.go | 64 ++++++ .../migrations/indexer/09-indexer-data.sql | 24 +++ datastore/postgres/migrations/migrations.go | 4 + indexer/layerscanner.go | 24 ++- indexer/packagescanner.go | 6 + indexer/repositoryscanner.go | 6 + indexer/store.go | 9 + libindex/libindex.go | 34 +++ libindex/options.go | 6 + rhel/indexerupdater.go | 148 +++++++++++++ rhel/indexerupdater_test.go | 41 ++++ test/mock/datastore/mocks.go | 197 +++++++++--------- test/mock/driver/mocks.go | 17 +- test/mock/indexer/mocks.go | 183 +++++++++------- test/mock/updater/driver/v1/mocks.go | 4 + test/mock/updater/mocks.go | 25 +-- updater/driver/v1/interfaces.go | 5 + updater/driver/v1/types.go | 6 + updater/interfaces.go | 5 + updater/offline_v1.go | 8 +- updater/updater.go | 57 +++-- 21 files changed, 670 insertions(+), 203 deletions(-) create mode 100644 datastore/postgres/additionaldata.go create mode 100644 datastore/postgres/migrations/indexer/09-indexer-data.sql create mode 100644 rhel/indexerupdater.go create mode 100644 rhel/indexerupdater_test.go diff --git a/datastore/postgres/additionaldata.go b/datastore/postgres/additionaldata.go new file mode 100644 index 000000000..f013cb1bc --- /dev/null +++ b/datastore/postgres/additionaldata.go @@ -0,0 +1,64 @@ +package postgres + +import ( + "context" + "fmt" + "io" + + "github.com/jackc/pgx/v4" + "github.com/quay/claircore/updater/driver/v1" +) + +func (s *IndexerStore) GetData(ctx context.Context, namespace string, key string, dec func(context.Context, io.Reader) (any, error)) (any, error) { + return dec(ctx, nil) // I don't remember how this works +} + +// TODO(crozzy): accept an iter here? +// TODO(crozzy): add tracing +func (s *IndexerStore) UpdateIndexerData(ctx context.Context, _ driver.Fingerprint, ds []driver.IndexerData) error { + const ( + upsertAdditionalData = ` + INSERT INTO additional_data ( + namespace, + lookup_key, + data + ) VALUES ( + $1, + $2, + $3 + ) + ON CONFLICT (namespace, lookup_key) + DO UPDATE SET data = EXCLUDED.data; + ` + ) + tx, err := s.pool.Begin(ctx) + if err != nil { + return fmt.Errorf("failed to create transaction: %w", err) + } + defer tx.Rollback(ctx) + + for _, d := range ds { + // Deal with large object + // TODO(crozzy): How to check for duplicate large objects in this process? + lo := tx.LargeObjects() + oid, err := lo.Create(ctx, 0) + if err != nil { + return fmt.Errorf("failed to create large object: %w", err) + } + obj, err := lo.Open(ctx, oid, pgx.LargeObjectModeWrite) + if err != nil { + return fmt.Errorf("failed to open large object: %w", err) + } + if _, err = obj.Write(d.Value); err != nil { + return fmt.Errorf("failed to write large object: %w", err) + } + if _, err := tx.Exec(ctx, upsertAdditionalData, d.Namespace, d.Key, oid); err != nil { + return fmt.Errorf("failed to upsert additional data: %w", err) + } + } + if err = tx.Commit(ctx); err != nil { + return fmt.Errorf("failed to commit transaction: %w", err) + } + + return nil +} diff --git a/datastore/postgres/migrations/indexer/09-indexer-data.sql b/datastore/postgres/migrations/indexer/09-indexer-data.sql new file mode 100644 index 000000000..af57abc2e --- /dev/null +++ b/datastore/postgres/migrations/indexer/09-indexer-data.sql @@ -0,0 +1,24 @@ +-- additional_data +CREATE EXTENSION IF NOT EXISTS lo; +CREATE TABLE IF NOT EXISTS additional_data ( + namespace TEXT, + lookup_key TEXT, + data lo +); +CREATE UNIQUE INDEX IF NOT EXISTS additional_data_unique_idx ON additional_data (namespace, lookup_key); + +-- Trigger needed to clean up orphaned objects +-- see: https://www.postgresql.org/docs/current/lo.html#LO-HOW-TO-USE +-- Can't IF NOT EXISTS a trigger, so have to manually delete and recreate. +DO $$ +BEGIN + -- Drop the trigger if it exists + IF EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 't_data') THEN + DROP TRIGGER t_data ON additional_data; + END IF; + + -- Create the trigger + CREATE TRIGGER t_data BEFORE UPDATE OR DELETE ON additional_data + FOR EACH ROW EXECUTE FUNCTION lo_manage(data); +END; +$$ LANGUAGE plpgsql; diff --git a/datastore/postgres/migrations/migrations.go b/datastore/postgres/migrations/migrations.go index fa52113c4..b755ada4b 100644 --- a/datastore/postgres/migrations/migrations.go +++ b/datastore/postgres/migrations/migrations.go @@ -61,6 +61,10 @@ var IndexerMigrations = []migrate.Migration{ ID: 8, Up: runFile("indexer/08-index-manifest_layer.sql"), }, + { + ID: 9, + Up: runFile("indexer/09-indexer-data.sql"), + }, } var MatcherMigrations = []migrate.Migration{ diff --git a/indexer/layerscanner.go b/indexer/layerscanner.go index f7eb9bfca..fbeb6229c 100644 --- a/indexer/layerscanner.go +++ b/indexer/layerscanner.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "iter" "net" "runtime" @@ -201,7 +202,7 @@ func (ls *LayerScanner) scanLayer(ctx context.Context, l *claircore.Layer, s Ver } var result result - if err := result.Do(ctx, s, l); err != nil { + if err := result.Do(ctx, s, l, ls.store); err != nil { return err } @@ -227,7 +228,7 @@ type result struct { // Do asserts the Scanner back to having a Scan method, and then calls it. // // The success value is captured and the error value is returned by Do. -func (r *result) Do(ctx context.Context, s VersionedScanner, l *claircore.Layer) error { +func (r *result) Do(ctx context.Context, s VersionedScanner, l *claircore.Layer, dl DataLookup) error { var err error switch s := s.(type) { case PackageScanner: @@ -243,6 +244,25 @@ func (r *result) Do(ctx context.Context, s VersionedScanner, l *claircore.Layer) r.repos, err = s.Scan(ctx, l) case FileScanner: r.files, err = s.Scan(ctx, l) + case ComplexPackageDetector: + // TODO (crozzy): separate generic function here? + var ps iter.Seq2[claircore.Package, error] + ps, err = s.Analyze(ctx, dl, l) + for p, iErr := range ps { + if iErr != nil { + zlog.Warn(ctx).Str("detector", s.Name()).Err(iErr).Msg("error detecting package") + } + r.pkgs = append(r.pkgs, &p) + } + case ComplexRepositoryDetector: + var repos iter.Seq2[claircore.Repository, error] + repos, err = s.Analyze(ctx, dl, l) + for repo, iErr := range repos { + if iErr != nil { + zlog.Warn(ctx).Str("detector", s.Name()).Err(iErr).Msg("error detecting repository") + } + r.repos = append(r.repos, &repo) + } default: panic(fmt.Sprintf("programmer error: unknown type %T used as scanner", s)) } diff --git a/indexer/packagescanner.go b/indexer/packagescanner.go index 295478f76..a7240317b 100644 --- a/indexer/packagescanner.go +++ b/indexer/packagescanner.go @@ -2,6 +2,7 @@ package indexer import ( "context" + "iter" "github.com/quay/claircore" ) @@ -53,3 +54,8 @@ func NewPackageScannerMock(name, version, kind string) PackageScanner { type DefaultRepoScanner interface { DefaultRepository(context.Context) *claircore.Repository } + +type ComplexPackageDetector interface { + VersionedScanner + Analyze(context.Context, DataLookup, *claircore.Layer) (iter.Seq2[claircore.Package, error], error) +} diff --git a/indexer/repositoryscanner.go b/indexer/repositoryscanner.go index e8ef4d7c6..1d64a7560 100644 --- a/indexer/repositoryscanner.go +++ b/indexer/repositoryscanner.go @@ -2,6 +2,7 @@ package indexer import ( "context" + "iter" "github.com/quay/claircore" ) @@ -10,3 +11,8 @@ type RepositoryScanner interface { VersionedScanner Scan(context.Context, *claircore.Layer) ([]*claircore.Repository, error) } + +type ComplexRepositoryDetector interface { + VersionedScanner + Analyze(context.Context, DataLookup, *claircore.Layer) (iter.Seq2[claircore.Repository, error], error) +} diff --git a/indexer/store.go b/indexer/store.go index f4009e7e0..1f0763afd 100644 --- a/indexer/store.go +++ b/indexer/store.go @@ -2,8 +2,11 @@ package indexer import ( "context" + "io" "github.com/quay/claircore" + + "github.com/quay/claircore/updater/driver/v1" ) // Store is an interface for dealing with objects libindex needs to persist. @@ -12,6 +15,7 @@ type Store interface { Setter Querier Indexer + DataLookup // Close frees any resources associated with the Store. Close(context.Context) error } @@ -86,3 +90,8 @@ type Indexer interface { // IndexManifest should index the coalesced manifest's content given an IndexReport. IndexManifest(ctx context.Context, ir *claircore.IndexReport) error } + +type DataLookup interface { + GetData(ctx context.Context, namespace string, key string, dec func(context.Context, io.Reader) (any, error)) (any, error) + UpdateIndexerData(ctx context.Context, fp driver.Fingerprint, d []driver.IndexerData) error +} diff --git a/libindex/libindex.go b/libindex/libindex.go index b9e8874a1..63934b94a 100644 --- a/libindex/libindex.go +++ b/libindex/libindex.go @@ -27,6 +27,8 @@ import ( "github.com/quay/claircore/rhel/rhcc" "github.com/quay/claircore/rpm" "github.com/quay/claircore/ruby" + "github.com/quay/claircore/updater" + "github.com/quay/claircore/updater/driver/v1" "github.com/quay/claircore/whiteout" ) @@ -160,6 +162,38 @@ func New(ctx context.Context, opts *Options, cl *http.Client) (*Libindex, error) return nil, err } + if opts.UpdaterConfigs == nil { + opts.UpdaterConfigs = make(map[string]driver.ConfigUnmarshaler) + } + + u, err := updater.New(ctx, &updater.Options{ + IndexerStore: l.store, + Locker: l.locker, + Client: l.client, + Factories: []driver.UpdaterFactory{ + &rhel.UpdaterFactory{}, + }, + Configs: opts.UpdaterConfigs, + }) + if err != nil { + return nil, err + } + + if opts.UpdateInterval < time.Duration(24*time.Hour) { + // Update interval is either unset or unrealistically small + opts.UpdateInterval = DefaultInterval + } + + m := Manager{ + // TODO(crozzy): Review naming here + updater: u, + interval: opts.UpdateInterval, + additionalDataURL: opts.UpdateBundleURL, + additionalDataPath: opts.UpdateBundlePath, + } + + go m.Start(ctx) + return l, nil } diff --git a/libindex/options.go b/libindex/options.go index 4814fb029..7f86fee7b 100644 --- a/libindex/options.go +++ b/libindex/options.go @@ -4,6 +4,7 @@ import ( "time" "github.com/quay/claircore/indexer" + "github.com/quay/claircore/updater/driver/v1" ) const ( @@ -49,4 +50,9 @@ type Options struct { Package, Dist, Repo, File map[string]func(interface{}) error } Resolvers []indexer.Resolver + // Updater specific configs + UpdaterConfigs map[string]driver.ConfigUnmarshaler + UpdateInterval time.Duration + UpdateBundleURL string + UpdateBundlePath string } diff --git a/rhel/indexerupdater.go b/rhel/indexerupdater.go new file mode 100644 index 000000000..3e990b36b --- /dev/null +++ b/rhel/indexerupdater.go @@ -0,0 +1,148 @@ +package rhel + +import ( + "archive/zip" + "context" + "encoding/json" + "fmt" + "io" + "io/fs" + "net/http" + "reflect" + + "github.com/quay/claircore/rhel/rhcc" + "github.com/quay/claircore/updater/driver/v1" + + "github.com/quay/zlog" +) + +type mappingFile2 struct { + Data map[string]interface{} +} + +type UpdaterFactory struct{} + +func (uf *UpdaterFactory) Name() string { + // TODO(crozzy): Make important? + return "rhel-file-updater-factory" +} + +func (uf *UpdaterFactory) Create(ctx context.Context, cm driver.ConfigUnmarshaler) ([]driver.Updater, error) { + mf := &mappingFile2{} + return []driver.Updater{ + NewIndexerUpdater("repo-to-cpe", DefaultRepo2CPEMappingURL, mf), + NewIndexerUpdater("container-name-to-repo", rhcc.DefaultName2ReposMappingURL, mf), + }, nil +} + +type genericFileUpdater struct { + namespace string + url string + lastModified string + typ reflect.Type + client *http.Client +} + +type IndexerUpdaterConfig struct { + URL string +} + +var _ driver.Updater = (*genericFileUpdater)(nil) + +func NewIndexerUpdater(namespace string, url string, init interface{}) *genericFileUpdater { + return &genericFileUpdater{ + url: url, + typ: reflect.TypeOf(init).Elem(), + namespace: namespace, + } +} + +func (u *genericFileUpdater) Name() string { + return u.namespace + "-updater" +} +func (u *genericFileUpdater) Configure(ctx context.Context, cf driver.ConfigUnmarshaler, c *http.Client) error { + var cfg IndexerUpdaterConfig + if err := cf(&cfg); err != nil { + return err + } + if cfg.URL != "" { + u.url = cfg.URL + zlog.Info(ctx). + Str("component", "rhel/genericFileUpdater.Configure"). + Str("updater", u.Name()). + Msg("configured url") + } + u.client = c + return nil +} + +func (u *genericFileUpdater) Fetch(ctx context.Context, zw *zip.Writer, f driver.Fingerprint, c *http.Client) (driver.Fingerprint, error) { + ctx = zlog.ContextWithValues(ctx, + "component", "rhel/genericFileUpdater/Updater.Fetch", + "url", u.url) + zlog.Debug(ctx).Msg("attempting fetch of mapping file") + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.url, nil) + if err != nil { + return "", err + } + if u.lastModified != "" { + req.Header.Set("if-modified-since", u.lastModified) + } + + resp, err := c.Do(req) + if err != nil { + return "", err + } + defer resp.Body.Close() + switch resp.StatusCode { + case http.StatusOK: + case http.StatusNotModified: + zlog.Debug(ctx). + Str("since", u.lastModified). + Msg("response not modified; no update necessary") + return "", nil + default: + return "", fmt.Errorf("received status code %d querying mapping url", resp.StatusCode) + } + + u.lastModified = resp.Header.Get("last-modified") + w, err := zw.Create(u.namespace) + if err != nil { + return "", err + } + _, err = io.Copy(w, resp.Body) + if err != nil { + return "", err + } + return "", nil +} + +// TODO(crozzy): +// - docs +// - +func (u *genericFileUpdater) ParseIndexerData(ctx context.Context, f fs.FS) ([]driver.IndexerData, error) { + b, err := f.Open(u.namespace) + if err != nil { + // TODO: explaining error + return nil, err + } + mf := &mappingFile2{} + if err := json.NewDecoder(b).Decode(mf); err != nil { + return nil, fmt.Errorf("failed to decode mapping file: %w", err) + } + ds := []driver.IndexerData{} + for k, v := range mf.Data { + d := driver.IndexerData{ + Namespace: u.namespace, + Key: k, + } + var err error + d.Value, err = json.Marshal(v) + if err != nil { + return nil, err + } + ds = append(ds, d) + } + return ds, nil +} diff --git a/rhel/indexerupdater_test.go b/rhel/indexerupdater_test.go new file mode 100644 index 000000000..e75ad1d63 --- /dev/null +++ b/rhel/indexerupdater_test.go @@ -0,0 +1,41 @@ +package rhel + +import ( + "archive/zip" + "bytes" + "context" + "net/http" + "os" + "testing" + + "github.com/quay/zlog" +) + +func TestUpdater(t *testing.T) { + ctx := zlog.Test(context.Background(), t) + + gfu := genericFileUpdater{ + url: DefaultName2ReposMappingURL, + name: "repo-to-cpe", + } + if gfu.Name() != "generic-repo-to-cpe" { + t.Fatal("name wrong") + } + + var buf bytes.Buffer + zipWriter := zip.NewWriter(&buf) + + _, err := gfu.Fetch(ctx, zipWriter, "", http.DefaultClient) + if err != nil { + t.Error(err) + } + err = zipWriter.Close() + if err != nil { + t.Error(err) + } + + err = os.WriteFile("output.zip", buf.Bytes(), 0644) + if err != nil { + panic(err) + } +} diff --git a/test/mock/datastore/mocks.go b/test/mock/datastore/mocks.go index ec074afcc..6ca3ad5e3 100644 --- a/test/mock/datastore/mocks.go +++ b/test/mock/datastore/mocks.go @@ -25,6 +25,7 @@ import ( type MockEnrichment struct { ctrl *gomock.Controller recorder *MockEnrichmentMockRecorder + isgomock struct{} } // MockEnrichmentMockRecorder is the mock recorder for MockEnrichment. @@ -45,24 +46,25 @@ func (m *MockEnrichment) EXPECT() *MockEnrichmentMockRecorder { } // GetEnrichment mocks base method. -func (m *MockEnrichment) GetEnrichment(arg0 context.Context, arg1 string, arg2 []string) ([]driver.EnrichmentRecord, error) { +func (m *MockEnrichment) GetEnrichment(ctx context.Context, kind string, tags []string) ([]driver.EnrichmentRecord, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetEnrichment", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetEnrichment", ctx, kind, tags) ret0, _ := ret[0].([]driver.EnrichmentRecord) ret1, _ := ret[1].(error) return ret0, ret1 } // GetEnrichment indicates an expected call of GetEnrichment. -func (mr *MockEnrichmentMockRecorder) GetEnrichment(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockEnrichmentMockRecorder) GetEnrichment(ctx, kind, tags any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnrichment", reflect.TypeOf((*MockEnrichment)(nil).GetEnrichment), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnrichment", reflect.TypeOf((*MockEnrichment)(nil).GetEnrichment), ctx, kind, tags) } // MockEnrichmentUpdater is a mock of EnrichmentUpdater interface. type MockEnrichmentUpdater struct { ctrl *gomock.Controller recorder *MockEnrichmentUpdaterMockRecorder + isgomock struct{} } // MockEnrichmentUpdaterMockRecorder is the mock recorder for MockEnrichmentUpdater. @@ -83,39 +85,40 @@ func (m *MockEnrichmentUpdater) EXPECT() *MockEnrichmentUpdaterMockRecorder { } // UpdateEnrichments mocks base method. -func (m *MockEnrichmentUpdater) UpdateEnrichments(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []driver.EnrichmentRecord) (uuid.UUID, error) { +func (m *MockEnrichmentUpdater) UpdateEnrichments(ctx context.Context, kind string, fingerprint driver.Fingerprint, enrichments []driver.EnrichmentRecord) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichments", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichments", ctx, kind, fingerprint, enrichments) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichments indicates an expected call of UpdateEnrichments. -func (mr *MockEnrichmentUpdaterMockRecorder) UpdateEnrichments(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockEnrichmentUpdaterMockRecorder) UpdateEnrichments(ctx, kind, fingerprint, enrichments any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockEnrichmentUpdater)(nil).UpdateEnrichments), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockEnrichmentUpdater)(nil).UpdateEnrichments), ctx, kind, fingerprint, enrichments) } // UpdateEnrichmentsIter mocks base method. -func (m *MockEnrichmentUpdater) UpdateEnrichmentsIter(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 datastore.EnrichmentIter) (uuid.UUID, error) { +func (m *MockEnrichmentUpdater) UpdateEnrichmentsIter(ctx context.Context, kind string, fingerprint driver.Fingerprint, enIter datastore.EnrichmentIter) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", ctx, kind, fingerprint, enIter) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichmentsIter indicates an expected call of UpdateEnrichmentsIter. -func (mr *MockEnrichmentUpdaterMockRecorder) UpdateEnrichmentsIter(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockEnrichmentUpdaterMockRecorder) UpdateEnrichmentsIter(ctx, kind, fingerprint, enIter any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockEnrichmentUpdater)(nil).UpdateEnrichmentsIter), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockEnrichmentUpdater)(nil).UpdateEnrichmentsIter), ctx, kind, fingerprint, enIter) } // MockMatcherStore is a mock of MatcherStore interface. type MockMatcherStore struct { ctrl *gomock.Controller recorder *MockMatcherStoreMockRecorder + isgomock struct{} } // MockMatcherStoreMockRecorder is the mock recorder for MockMatcherStore. @@ -156,63 +159,63 @@ func (mr *MockMatcherStoreMockRecorder) DeleteUpdateOperations(arg0 any, arg1 .. } // DeltaUpdateVulnerabilities mocks base method. -func (m *MockMatcherStore) DeltaUpdateVulnerabilities(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []*claircore.Vulnerability, arg4 []string) (uuid.UUID, error) { +func (m *MockMatcherStore) DeltaUpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability, deletedVulns []string) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeltaUpdateVulnerabilities", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "DeltaUpdateVulnerabilities", ctx, updater, fingerprint, vulns, deletedVulns) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // DeltaUpdateVulnerabilities indicates an expected call of DeltaUpdateVulnerabilities. -func (mr *MockMatcherStoreMockRecorder) DeltaUpdateVulnerabilities(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) DeltaUpdateVulnerabilities(ctx, updater, fingerprint, vulns, deletedVulns any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeltaUpdateVulnerabilities", reflect.TypeOf((*MockMatcherStore)(nil).DeltaUpdateVulnerabilities), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeltaUpdateVulnerabilities", reflect.TypeOf((*MockMatcherStore)(nil).DeltaUpdateVulnerabilities), ctx, updater, fingerprint, vulns, deletedVulns) } // GC mocks base method. -func (m *MockMatcherStore) GC(arg0 context.Context, arg1 int) (int64, error) { +func (m *MockMatcherStore) GC(ctx context.Context, keep int) (int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GC", arg0, arg1) + ret := m.ctrl.Call(m, "GC", ctx, keep) ret0, _ := ret[0].(int64) ret1, _ := ret[1].(error) return ret0, ret1 } // GC indicates an expected call of GC. -func (mr *MockMatcherStoreMockRecorder) GC(arg0, arg1 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) GC(ctx, keep any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GC", reflect.TypeOf((*MockMatcherStore)(nil).GC), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GC", reflect.TypeOf((*MockMatcherStore)(nil).GC), ctx, keep) } // Get mocks base method. -func (m *MockMatcherStore) Get(arg0 context.Context, arg1 []*claircore.IndexRecord, arg2 datastore.GetOpts) (map[string][]*claircore.Vulnerability, error) { +func (m *MockMatcherStore) Get(ctx context.Context, records []*claircore.IndexRecord, opts datastore.GetOpts) (map[string][]*claircore.Vulnerability, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "Get", ctx, records, opts) ret0, _ := ret[0].(map[string][]*claircore.Vulnerability) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get. -func (mr *MockMatcherStoreMockRecorder) Get(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) Get(ctx, records, opts any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockMatcherStore)(nil).Get), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockMatcherStore)(nil).Get), ctx, records, opts) } // GetEnrichment mocks base method. -func (m *MockMatcherStore) GetEnrichment(arg0 context.Context, arg1 string, arg2 []string) ([]driver.EnrichmentRecord, error) { +func (m *MockMatcherStore) GetEnrichment(ctx context.Context, kind string, tags []string) ([]driver.EnrichmentRecord, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetEnrichment", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetEnrichment", ctx, kind, tags) ret0, _ := ret[0].([]driver.EnrichmentRecord) ret1, _ := ret[1].(error) return ret0, ret1 } // GetEnrichment indicates an expected call of GetEnrichment. -func (mr *MockMatcherStoreMockRecorder) GetEnrichment(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) GetEnrichment(ctx, kind, tags any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnrichment", reflect.TypeOf((*MockMatcherStore)(nil).GetEnrichment), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnrichment", reflect.TypeOf((*MockMatcherStore)(nil).GetEnrichment), ctx, kind, tags) } // GetLatestUpdateRef mocks base method. @@ -246,18 +249,18 @@ func (mr *MockMatcherStoreMockRecorder) GetLatestUpdateRefs(arg0, arg1 any) *gom } // GetUpdateDiff mocks base method. -func (m *MockMatcherStore) GetUpdateDiff(arg0 context.Context, arg1, arg2 uuid.UUID) (*driver.UpdateDiff, error) { +func (m *MockMatcherStore) GetUpdateDiff(ctx context.Context, prev, cur uuid.UUID) (*driver.UpdateDiff, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUpdateDiff", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetUpdateDiff", ctx, prev, cur) ret0, _ := ret[0].(*driver.UpdateDiff) ret1, _ := ret[1].(error) return ret0, ret1 } // GetUpdateDiff indicates an expected call of GetUpdateDiff. -func (mr *MockMatcherStoreMockRecorder) GetUpdateDiff(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) GetUpdateDiff(ctx, prev, cur any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpdateDiff", reflect.TypeOf((*MockMatcherStore)(nil).GetUpdateDiff), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpdateDiff", reflect.TypeOf((*MockMatcherStore)(nil).GetUpdateDiff), ctx, prev, cur) } // GetUpdateOperations mocks base method. @@ -296,97 +299,98 @@ func (mr *MockMatcherStoreMockRecorder) Initialized(arg0 any) *gomock.Call { } // RecordUpdaterSetStatus mocks base method. -func (m *MockMatcherStore) RecordUpdaterSetStatus(arg0 context.Context, arg1 string, arg2 time.Time) error { +func (m *MockMatcherStore) RecordUpdaterSetStatus(ctx context.Context, updaterSet string, updateTime time.Time) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RecordUpdaterSetStatus", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "RecordUpdaterSetStatus", ctx, updaterSet, updateTime) ret0, _ := ret[0].(error) return ret0 } // RecordUpdaterSetStatus indicates an expected call of RecordUpdaterSetStatus. -func (mr *MockMatcherStoreMockRecorder) RecordUpdaterSetStatus(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) RecordUpdaterSetStatus(ctx, updaterSet, updateTime any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterSetStatus", reflect.TypeOf((*MockMatcherStore)(nil).RecordUpdaterSetStatus), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterSetStatus", reflect.TypeOf((*MockMatcherStore)(nil).RecordUpdaterSetStatus), ctx, updaterSet, updateTime) } // RecordUpdaterStatus mocks base method. -func (m *MockMatcherStore) RecordUpdaterStatus(arg0 context.Context, arg1 string, arg2 time.Time, arg3 driver.Fingerprint, arg4 error) error { +func (m *MockMatcherStore) RecordUpdaterStatus(ctx context.Context, updaterName string, updateTime time.Time, fingerprint driver.Fingerprint, updaterError error) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RecordUpdaterStatus", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "RecordUpdaterStatus", ctx, updaterName, updateTime, fingerprint, updaterError) ret0, _ := ret[0].(error) return ret0 } // RecordUpdaterStatus indicates an expected call of RecordUpdaterStatus. -func (mr *MockMatcherStoreMockRecorder) RecordUpdaterStatus(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) RecordUpdaterStatus(ctx, updaterName, updateTime, fingerprint, updaterError any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterStatus", reflect.TypeOf((*MockMatcherStore)(nil).RecordUpdaterStatus), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterStatus", reflect.TypeOf((*MockMatcherStore)(nil).RecordUpdaterStatus), ctx, updaterName, updateTime, fingerprint, updaterError) } // UpdateEnrichments mocks base method. -func (m *MockMatcherStore) UpdateEnrichments(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []driver.EnrichmentRecord) (uuid.UUID, error) { +func (m *MockMatcherStore) UpdateEnrichments(ctx context.Context, kind string, fingerprint driver.Fingerprint, enrichments []driver.EnrichmentRecord) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichments", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichments", ctx, kind, fingerprint, enrichments) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichments indicates an expected call of UpdateEnrichments. -func (mr *MockMatcherStoreMockRecorder) UpdateEnrichments(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) UpdateEnrichments(ctx, kind, fingerprint, enrichments any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockMatcherStore)(nil).UpdateEnrichments), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockMatcherStore)(nil).UpdateEnrichments), ctx, kind, fingerprint, enrichments) } // UpdateEnrichmentsIter mocks base method. -func (m *MockMatcherStore) UpdateEnrichmentsIter(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 datastore.EnrichmentIter) (uuid.UUID, error) { +func (m *MockMatcherStore) UpdateEnrichmentsIter(ctx context.Context, kind string, fingerprint driver.Fingerprint, enIter datastore.EnrichmentIter) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", ctx, kind, fingerprint, enIter) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichmentsIter indicates an expected call of UpdateEnrichmentsIter. -func (mr *MockMatcherStoreMockRecorder) UpdateEnrichmentsIter(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) UpdateEnrichmentsIter(ctx, kind, fingerprint, enIter any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockMatcherStore)(nil).UpdateEnrichmentsIter), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockMatcherStore)(nil).UpdateEnrichmentsIter), ctx, kind, fingerprint, enIter) } // UpdateVulnerabilities mocks base method. -func (m *MockMatcherStore) UpdateVulnerabilities(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []*claircore.Vulnerability) (uuid.UUID, error) { +func (m *MockMatcherStore) UpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateVulnerabilities", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateVulnerabilities", ctx, updater, fingerprint, vulns) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateVulnerabilities indicates an expected call of UpdateVulnerabilities. -func (mr *MockMatcherStoreMockRecorder) UpdateVulnerabilities(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) UpdateVulnerabilities(ctx, updater, fingerprint, vulns any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockMatcherStore)(nil).UpdateVulnerabilities), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockMatcherStore)(nil).UpdateVulnerabilities), ctx, updater, fingerprint, vulns) } // UpdateVulnerabilitiesIter mocks base method. -func (m *MockMatcherStore) UpdateVulnerabilitiesIter(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 datastore.VulnerabilityIter) (uuid.UUID, error) { +func (m *MockMatcherStore) UpdateVulnerabilitiesIter(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulnIter datastore.VulnerabilityIter) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateVulnerabilitiesIter", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateVulnerabilitiesIter", ctx, updater, fingerprint, vulnIter) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateVulnerabilitiesIter indicates an expected call of UpdateVulnerabilitiesIter. -func (mr *MockMatcherStoreMockRecorder) UpdateVulnerabilitiesIter(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockMatcherStoreMockRecorder) UpdateVulnerabilitiesIter(ctx, updater, fingerprint, vulnIter any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilitiesIter", reflect.TypeOf((*MockMatcherStore)(nil).UpdateVulnerabilitiesIter), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilitiesIter", reflect.TypeOf((*MockMatcherStore)(nil).UpdateVulnerabilitiesIter), ctx, updater, fingerprint, vulnIter) } // MockUpdater is a mock of Updater interface. type MockUpdater struct { ctrl *gomock.Controller recorder *MockUpdaterMockRecorder + isgomock struct{} } // MockUpdaterMockRecorder is the mock recorder for MockUpdater. @@ -427,33 +431,33 @@ func (mr *MockUpdaterMockRecorder) DeleteUpdateOperations(arg0 any, arg1 ...any) } // DeltaUpdateVulnerabilities mocks base method. -func (m *MockUpdater) DeltaUpdateVulnerabilities(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []*claircore.Vulnerability, arg4 []string) (uuid.UUID, error) { +func (m *MockUpdater) DeltaUpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability, deletedVulns []string) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeltaUpdateVulnerabilities", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "DeltaUpdateVulnerabilities", ctx, updater, fingerprint, vulns, deletedVulns) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // DeltaUpdateVulnerabilities indicates an expected call of DeltaUpdateVulnerabilities. -func (mr *MockUpdaterMockRecorder) DeltaUpdateVulnerabilities(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) DeltaUpdateVulnerabilities(ctx, updater, fingerprint, vulns, deletedVulns any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeltaUpdateVulnerabilities", reflect.TypeOf((*MockUpdater)(nil).DeltaUpdateVulnerabilities), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeltaUpdateVulnerabilities", reflect.TypeOf((*MockUpdater)(nil).DeltaUpdateVulnerabilities), ctx, updater, fingerprint, vulns, deletedVulns) } // GC mocks base method. -func (m *MockUpdater) GC(arg0 context.Context, arg1 int) (int64, error) { +func (m *MockUpdater) GC(ctx context.Context, keep int) (int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GC", arg0, arg1) + ret := m.ctrl.Call(m, "GC", ctx, keep) ret0, _ := ret[0].(int64) ret1, _ := ret[1].(error) return ret0, ret1 } // GC indicates an expected call of GC. -func (mr *MockUpdaterMockRecorder) GC(arg0, arg1 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) GC(ctx, keep any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GC", reflect.TypeOf((*MockUpdater)(nil).GC), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GC", reflect.TypeOf((*MockUpdater)(nil).GC), ctx, keep) } // GetLatestUpdateRef mocks base method. @@ -487,18 +491,18 @@ func (mr *MockUpdaterMockRecorder) GetLatestUpdateRefs(arg0, arg1 any) *gomock.C } // GetUpdateDiff mocks base method. -func (m *MockUpdater) GetUpdateDiff(arg0 context.Context, arg1, arg2 uuid.UUID) (*driver.UpdateDiff, error) { +func (m *MockUpdater) GetUpdateDiff(ctx context.Context, prev, cur uuid.UUID) (*driver.UpdateDiff, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUpdateDiff", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetUpdateDiff", ctx, prev, cur) ret0, _ := ret[0].(*driver.UpdateDiff) ret1, _ := ret[1].(error) return ret0, ret1 } // GetUpdateDiff indicates an expected call of GetUpdateDiff. -func (mr *MockUpdaterMockRecorder) GetUpdateDiff(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) GetUpdateDiff(ctx, prev, cur any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpdateDiff", reflect.TypeOf((*MockUpdater)(nil).GetUpdateDiff), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUpdateDiff", reflect.TypeOf((*MockUpdater)(nil).GetUpdateDiff), ctx, prev, cur) } // GetUpdateOperations mocks base method. @@ -537,97 +541,98 @@ func (mr *MockUpdaterMockRecorder) Initialized(arg0 any) *gomock.Call { } // RecordUpdaterSetStatus mocks base method. -func (m *MockUpdater) RecordUpdaterSetStatus(arg0 context.Context, arg1 string, arg2 time.Time) error { +func (m *MockUpdater) RecordUpdaterSetStatus(ctx context.Context, updaterSet string, updateTime time.Time) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RecordUpdaterSetStatus", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "RecordUpdaterSetStatus", ctx, updaterSet, updateTime) ret0, _ := ret[0].(error) return ret0 } // RecordUpdaterSetStatus indicates an expected call of RecordUpdaterSetStatus. -func (mr *MockUpdaterMockRecorder) RecordUpdaterSetStatus(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) RecordUpdaterSetStatus(ctx, updaterSet, updateTime any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterSetStatus", reflect.TypeOf((*MockUpdater)(nil).RecordUpdaterSetStatus), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterSetStatus", reflect.TypeOf((*MockUpdater)(nil).RecordUpdaterSetStatus), ctx, updaterSet, updateTime) } // RecordUpdaterStatus mocks base method. -func (m *MockUpdater) RecordUpdaterStatus(arg0 context.Context, arg1 string, arg2 time.Time, arg3 driver.Fingerprint, arg4 error) error { +func (m *MockUpdater) RecordUpdaterStatus(ctx context.Context, updaterName string, updateTime time.Time, fingerprint driver.Fingerprint, updaterError error) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RecordUpdaterStatus", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "RecordUpdaterStatus", ctx, updaterName, updateTime, fingerprint, updaterError) ret0, _ := ret[0].(error) return ret0 } // RecordUpdaterStatus indicates an expected call of RecordUpdaterStatus. -func (mr *MockUpdaterMockRecorder) RecordUpdaterStatus(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) RecordUpdaterStatus(ctx, updaterName, updateTime, fingerprint, updaterError any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterStatus", reflect.TypeOf((*MockUpdater)(nil).RecordUpdaterStatus), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordUpdaterStatus", reflect.TypeOf((*MockUpdater)(nil).RecordUpdaterStatus), ctx, updaterName, updateTime, fingerprint, updaterError) } // UpdateEnrichments mocks base method. -func (m *MockUpdater) UpdateEnrichments(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []driver.EnrichmentRecord) (uuid.UUID, error) { +func (m *MockUpdater) UpdateEnrichments(ctx context.Context, kind string, fingerprint driver.Fingerprint, enrichments []driver.EnrichmentRecord) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichments", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichments", ctx, kind, fingerprint, enrichments) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichments indicates an expected call of UpdateEnrichments. -func (mr *MockUpdaterMockRecorder) UpdateEnrichments(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) UpdateEnrichments(ctx, kind, fingerprint, enrichments any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockUpdater)(nil).UpdateEnrichments), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockUpdater)(nil).UpdateEnrichments), ctx, kind, fingerprint, enrichments) } // UpdateEnrichmentsIter mocks base method. -func (m *MockUpdater) UpdateEnrichmentsIter(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 datastore.EnrichmentIter) (uuid.UUID, error) { +func (m *MockUpdater) UpdateEnrichmentsIter(ctx context.Context, kind string, fingerprint driver.Fingerprint, enIter datastore.EnrichmentIter) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateEnrichmentsIter", ctx, kind, fingerprint, enIter) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateEnrichmentsIter indicates an expected call of UpdateEnrichmentsIter. -func (mr *MockUpdaterMockRecorder) UpdateEnrichmentsIter(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) UpdateEnrichmentsIter(ctx, kind, fingerprint, enIter any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockUpdater)(nil).UpdateEnrichmentsIter), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichmentsIter", reflect.TypeOf((*MockUpdater)(nil).UpdateEnrichmentsIter), ctx, kind, fingerprint, enIter) } // UpdateVulnerabilities mocks base method. -func (m *MockUpdater) UpdateVulnerabilities(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 []*claircore.Vulnerability) (uuid.UUID, error) { +func (m *MockUpdater) UpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateVulnerabilities", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateVulnerabilities", ctx, updater, fingerprint, vulns) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateVulnerabilities indicates an expected call of UpdateVulnerabilities. -func (mr *MockUpdaterMockRecorder) UpdateVulnerabilities(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) UpdateVulnerabilities(ctx, updater, fingerprint, vulns any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockUpdater)(nil).UpdateVulnerabilities), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockUpdater)(nil).UpdateVulnerabilities), ctx, updater, fingerprint, vulns) } // UpdateVulnerabilitiesIter mocks base method. -func (m *MockUpdater) UpdateVulnerabilitiesIter(arg0 context.Context, arg1 string, arg2 driver.Fingerprint, arg3 datastore.VulnerabilityIter) (uuid.UUID, error) { +func (m *MockUpdater) UpdateVulnerabilitiesIter(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulnIter datastore.VulnerabilityIter) (uuid.UUID, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateVulnerabilitiesIter", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateVulnerabilitiesIter", ctx, updater, fingerprint, vulnIter) ret0, _ := ret[0].(uuid.UUID) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateVulnerabilitiesIter indicates an expected call of UpdateVulnerabilitiesIter. -func (mr *MockUpdaterMockRecorder) UpdateVulnerabilitiesIter(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockUpdaterMockRecorder) UpdateVulnerabilitiesIter(ctx, updater, fingerprint, vulnIter any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilitiesIter", reflect.TypeOf((*MockUpdater)(nil).UpdateVulnerabilitiesIter), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilitiesIter", reflect.TypeOf((*MockUpdater)(nil).UpdateVulnerabilitiesIter), ctx, updater, fingerprint, vulnIter) } // MockVulnerability is a mock of Vulnerability interface. type MockVulnerability struct { ctrl *gomock.Controller recorder *MockVulnerabilityMockRecorder + isgomock struct{} } // MockVulnerabilityMockRecorder is the mock recorder for MockVulnerability. @@ -648,16 +653,16 @@ func (m *MockVulnerability) EXPECT() *MockVulnerabilityMockRecorder { } // Get mocks base method. -func (m *MockVulnerability) Get(arg0 context.Context, arg1 []*claircore.IndexRecord, arg2 datastore.GetOpts) (map[string][]*claircore.Vulnerability, error) { +func (m *MockVulnerability) Get(ctx context.Context, records []*claircore.IndexRecord, opts datastore.GetOpts) (map[string][]*claircore.Vulnerability, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "Get", ctx, records, opts) ret0, _ := ret[0].(map[string][]*claircore.Vulnerability) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get. -func (mr *MockVulnerabilityMockRecorder) Get(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockVulnerabilityMockRecorder) Get(ctx, records, opts any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockVulnerability)(nil).Get), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockVulnerability)(nil).Get), ctx, records, opts) } diff --git a/test/mock/driver/mocks.go b/test/mock/driver/mocks.go index 81bc79821..9ed99fcb6 100644 --- a/test/mock/driver/mocks.go +++ b/test/mock/driver/mocks.go @@ -22,6 +22,7 @@ import ( type MockMatcher struct { ctrl *gomock.Controller recorder *MockMatcherMockRecorder + isgomock struct{} } // MockMatcherMockRecorder is the mock recorder for MockMatcher. @@ -42,17 +43,17 @@ func (m *MockMatcher) EXPECT() *MockMatcherMockRecorder { } // Filter mocks base method. -func (m *MockMatcher) Filter(arg0 *claircore.IndexRecord) bool { +func (m *MockMatcher) Filter(record *claircore.IndexRecord) bool { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Filter", arg0) + ret := m.ctrl.Call(m, "Filter", record) ret0, _ := ret[0].(bool) return ret0 } // Filter indicates an expected call of Filter. -func (mr *MockMatcherMockRecorder) Filter(arg0 any) *gomock.Call { +func (mr *MockMatcherMockRecorder) Filter(record any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Filter", reflect.TypeOf((*MockMatcher)(nil).Filter), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Filter", reflect.TypeOf((*MockMatcher)(nil).Filter), record) } // Name mocks base method. @@ -84,16 +85,16 @@ func (mr *MockMatcherMockRecorder) Query() *gomock.Call { } // Vulnerable mocks base method. -func (m *MockMatcher) Vulnerable(arg0 context.Context, arg1 *claircore.IndexRecord, arg2 *claircore.Vulnerability) (bool, error) { +func (m *MockMatcher) Vulnerable(ctx context.Context, record *claircore.IndexRecord, vuln *claircore.Vulnerability) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Vulnerable", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "Vulnerable", ctx, record, vuln) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // Vulnerable indicates an expected call of Vulnerable. -func (mr *MockMatcherMockRecorder) Vulnerable(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockMatcherMockRecorder) Vulnerable(ctx, record, vuln any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Vulnerable", reflect.TypeOf((*MockMatcher)(nil).Vulnerable), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Vulnerable", reflect.TypeOf((*MockMatcher)(nil).Vulnerable), ctx, record, vuln) } diff --git a/test/mock/indexer/mocks.go b/test/mock/indexer/mocks.go index 59b61f738..7eb300b4d 100644 --- a/test/mock/indexer/mocks.go +++ b/test/mock/indexer/mocks.go @@ -11,10 +11,12 @@ package mock_indexer import ( context "context" + io "io" reflect "reflect" claircore "github.com/quay/claircore" indexer "github.com/quay/claircore/indexer" + driver "github.com/quay/claircore/updater/driver/v1" gomock "go.uber.org/mock/gomock" ) @@ -22,6 +24,7 @@ import ( type MockStore struct { ctrl *gomock.Controller recorder *MockStoreMockRecorder + isgomock struct{} } // MockStoreMockRecorder is the mock recorder for MockStore. @@ -42,18 +45,18 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { } // AffectedManifests mocks base method. -func (m *MockStore) AffectedManifests(arg0 context.Context, arg1 claircore.Vulnerability, arg2 claircore.CheckVulnernableFunc) ([]claircore.Digest, error) { +func (m *MockStore) AffectedManifests(ctx context.Context, v claircore.Vulnerability, f claircore.CheckVulnernableFunc) ([]claircore.Digest, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AffectedManifests", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "AffectedManifests", ctx, v, f) ret0, _ := ret[0].([]claircore.Digest) ret1, _ := ret[1].(error) return ret0, ret1 } // AffectedManifests indicates an expected call of AffectedManifests. -func (mr *MockStoreMockRecorder) AffectedManifests(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) AffectedManifests(ctx, v, f any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AffectedManifests", reflect.TypeOf((*MockStore)(nil).AffectedManifests), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AffectedManifests", reflect.TypeOf((*MockStore)(nil).AffectedManifests), ctx, v, f) } // Close mocks base method. @@ -91,95 +94,110 @@ func (mr *MockStoreMockRecorder) DeleteManifests(arg0 any, arg1 ...any) *gomock. } // DistributionsByLayer mocks base method. -func (m *MockStore) DistributionsByLayer(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanners) ([]*claircore.Distribution, error) { +func (m *MockStore) DistributionsByLayer(ctx context.Context, hash claircore.Digest, scnrs indexer.VersionedScanners) ([]*claircore.Distribution, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DistributionsByLayer", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "DistributionsByLayer", ctx, hash, scnrs) ret0, _ := ret[0].([]*claircore.Distribution) ret1, _ := ret[1].(error) return ret0, ret1 } // DistributionsByLayer indicates an expected call of DistributionsByLayer. -func (mr *MockStoreMockRecorder) DistributionsByLayer(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) DistributionsByLayer(ctx, hash, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributionsByLayer", reflect.TypeOf((*MockStore)(nil).DistributionsByLayer), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributionsByLayer", reflect.TypeOf((*MockStore)(nil).DistributionsByLayer), ctx, hash, scnrs) } // FilesByLayer mocks base method. -func (m *MockStore) FilesByLayer(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanners) ([]claircore.File, error) { +func (m *MockStore) FilesByLayer(ctx context.Context, hash claircore.Digest, scnrs indexer.VersionedScanners) ([]claircore.File, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FilesByLayer", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "FilesByLayer", ctx, hash, scnrs) ret0, _ := ret[0].([]claircore.File) ret1, _ := ret[1].(error) return ret0, ret1 } // FilesByLayer indicates an expected call of FilesByLayer. -func (mr *MockStoreMockRecorder) FilesByLayer(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) FilesByLayer(ctx, hash, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilesByLayer", reflect.TypeOf((*MockStore)(nil).FilesByLayer), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilesByLayer", reflect.TypeOf((*MockStore)(nil).FilesByLayer), ctx, hash, scnrs) +} + +// GetData mocks base method. +func (m *MockStore) GetData(ctx context.Context, namespace, key string, dec func(context.Context, io.Reader) (any, error)) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetData", ctx, namespace, key, dec) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetData indicates an expected call of GetData. +func (mr *MockStoreMockRecorder) GetData(ctx, namespace, key, dec any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetData", reflect.TypeOf((*MockStore)(nil).GetData), ctx, namespace, key, dec) } // IndexDistributions mocks base method. -func (m *MockStore) IndexDistributions(arg0 context.Context, arg1 []*claircore.Distribution, arg2 *claircore.Layer, arg3 indexer.VersionedScanner) error { +func (m *MockStore) IndexDistributions(ctx context.Context, dists []*claircore.Distribution, layer *claircore.Layer, scnr indexer.VersionedScanner) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexDistributions", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "IndexDistributions", ctx, dists, layer, scnr) ret0, _ := ret[0].(error) return ret0 } // IndexDistributions indicates an expected call of IndexDistributions. -func (mr *MockStoreMockRecorder) IndexDistributions(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexDistributions(ctx, dists, layer, scnr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexDistributions", reflect.TypeOf((*MockStore)(nil).IndexDistributions), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexDistributions", reflect.TypeOf((*MockStore)(nil).IndexDistributions), ctx, dists, layer, scnr) } // IndexFiles mocks base method. -func (m *MockStore) IndexFiles(arg0 context.Context, arg1 []claircore.File, arg2 *claircore.Layer, arg3 indexer.VersionedScanner) error { +func (m *MockStore) IndexFiles(ctx context.Context, files []claircore.File, layer *claircore.Layer, scnr indexer.VersionedScanner) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexFiles", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "IndexFiles", ctx, files, layer, scnr) ret0, _ := ret[0].(error) return ret0 } // IndexFiles indicates an expected call of IndexFiles. -func (mr *MockStoreMockRecorder) IndexFiles(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexFiles(ctx, files, layer, scnr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexFiles", reflect.TypeOf((*MockStore)(nil).IndexFiles), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexFiles", reflect.TypeOf((*MockStore)(nil).IndexFiles), ctx, files, layer, scnr) } // IndexManifest mocks base method. -func (m *MockStore) IndexManifest(arg0 context.Context, arg1 *claircore.IndexReport) error { +func (m *MockStore) IndexManifest(ctx context.Context, ir *claircore.IndexReport) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexManifest", arg0, arg1) + ret := m.ctrl.Call(m, "IndexManifest", ctx, ir) ret0, _ := ret[0].(error) return ret0 } // IndexManifest indicates an expected call of IndexManifest. -func (mr *MockStoreMockRecorder) IndexManifest(arg0, arg1 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexManifest(ctx, ir any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexManifest", reflect.TypeOf((*MockStore)(nil).IndexManifest), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexManifest", reflect.TypeOf((*MockStore)(nil).IndexManifest), ctx, ir) } // IndexPackages mocks base method. -func (m *MockStore) IndexPackages(arg0 context.Context, arg1 []*claircore.Package, arg2 *claircore.Layer, arg3 indexer.VersionedScanner) error { +func (m *MockStore) IndexPackages(ctx context.Context, pkgs []*claircore.Package, layer *claircore.Layer, scnr indexer.VersionedScanner) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexPackages", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "IndexPackages", ctx, pkgs, layer, scnr) ret0, _ := ret[0].(error) return ret0 } // IndexPackages indicates an expected call of IndexPackages. -func (mr *MockStoreMockRecorder) IndexPackages(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexPackages(ctx, pkgs, layer, scnr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexPackages", reflect.TypeOf((*MockStore)(nil).IndexPackages), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexPackages", reflect.TypeOf((*MockStore)(nil).IndexPackages), ctx, pkgs, layer, scnr) } // IndexReport mocks base method. -func (m *MockStore) IndexReport(arg0 context.Context, arg1 claircore.Digest) (*claircore.IndexReport, bool, error) { +func (m *MockStore) IndexReport(ctx context.Context, hash claircore.Digest) (*claircore.IndexReport, bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexReport", arg0, arg1) + ret := m.ctrl.Call(m, "IndexReport", ctx, hash) ret0, _ := ret[0].(*claircore.IndexReport) ret1, _ := ret[1].(bool) ret2, _ := ret[2].(error) @@ -187,125 +205,125 @@ func (m *MockStore) IndexReport(arg0 context.Context, arg1 claircore.Digest) (*c } // IndexReport indicates an expected call of IndexReport. -func (mr *MockStoreMockRecorder) IndexReport(arg0, arg1 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexReport(ctx, hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexReport", reflect.TypeOf((*MockStore)(nil).IndexReport), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexReport", reflect.TypeOf((*MockStore)(nil).IndexReport), ctx, hash) } // IndexRepositories mocks base method. -func (m *MockStore) IndexRepositories(arg0 context.Context, arg1 []*claircore.Repository, arg2 *claircore.Layer, arg3 indexer.VersionedScanner) error { +func (m *MockStore) IndexRepositories(ctx context.Context, repos []*claircore.Repository, layer *claircore.Layer, scnr indexer.VersionedScanner) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IndexRepositories", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "IndexRepositories", ctx, repos, layer, scnr) ret0, _ := ret[0].(error) return ret0 } // IndexRepositories indicates an expected call of IndexRepositories. -func (mr *MockStoreMockRecorder) IndexRepositories(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockStoreMockRecorder) IndexRepositories(ctx, repos, layer, scnr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexRepositories", reflect.TypeOf((*MockStore)(nil).IndexRepositories), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IndexRepositories", reflect.TypeOf((*MockStore)(nil).IndexRepositories), ctx, repos, layer, scnr) } // LayerScanned mocks base method. -func (m *MockStore) LayerScanned(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanner) (bool, error) { +func (m *MockStore) LayerScanned(ctx context.Context, hash claircore.Digest, scnr indexer.VersionedScanner) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LayerScanned", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "LayerScanned", ctx, hash, scnr) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // LayerScanned indicates an expected call of LayerScanned. -func (mr *MockStoreMockRecorder) LayerScanned(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) LayerScanned(ctx, hash, scnr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LayerScanned", reflect.TypeOf((*MockStore)(nil).LayerScanned), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LayerScanned", reflect.TypeOf((*MockStore)(nil).LayerScanned), ctx, hash, scnr) } // ManifestScanned mocks base method. -func (m *MockStore) ManifestScanned(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanners) (bool, error) { +func (m *MockStore) ManifestScanned(ctx context.Context, hash claircore.Digest, scnrs indexer.VersionedScanners) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ManifestScanned", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "ManifestScanned", ctx, hash, scnrs) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // ManifestScanned indicates an expected call of ManifestScanned. -func (mr *MockStoreMockRecorder) ManifestScanned(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) ManifestScanned(ctx, hash, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ManifestScanned", reflect.TypeOf((*MockStore)(nil).ManifestScanned), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ManifestScanned", reflect.TypeOf((*MockStore)(nil).ManifestScanned), ctx, hash, scnrs) } // PackagesByLayer mocks base method. -func (m *MockStore) PackagesByLayer(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanners) ([]*claircore.Package, error) { +func (m *MockStore) PackagesByLayer(ctx context.Context, hash claircore.Digest, scnrs indexer.VersionedScanners) ([]*claircore.Package, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PackagesByLayer", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "PackagesByLayer", ctx, hash, scnrs) ret0, _ := ret[0].([]*claircore.Package) ret1, _ := ret[1].(error) return ret0, ret1 } // PackagesByLayer indicates an expected call of PackagesByLayer. -func (mr *MockStoreMockRecorder) PackagesByLayer(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) PackagesByLayer(ctx, hash, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PackagesByLayer", reflect.TypeOf((*MockStore)(nil).PackagesByLayer), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PackagesByLayer", reflect.TypeOf((*MockStore)(nil).PackagesByLayer), ctx, hash, scnrs) } // PersistManifest mocks base method. -func (m *MockStore) PersistManifest(arg0 context.Context, arg1 claircore.Manifest) error { +func (m *MockStore) PersistManifest(ctx context.Context, manifest claircore.Manifest) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PersistManifest", arg0, arg1) + ret := m.ctrl.Call(m, "PersistManifest", ctx, manifest) ret0, _ := ret[0].(error) return ret0 } // PersistManifest indicates an expected call of PersistManifest. -func (mr *MockStoreMockRecorder) PersistManifest(arg0, arg1 any) *gomock.Call { +func (mr *MockStoreMockRecorder) PersistManifest(ctx, manifest any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersistManifest", reflect.TypeOf((*MockStore)(nil).PersistManifest), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersistManifest", reflect.TypeOf((*MockStore)(nil).PersistManifest), ctx, manifest) } // RegisterScanners mocks base method. -func (m *MockStore) RegisterScanners(arg0 context.Context, arg1 indexer.VersionedScanners) error { +func (m *MockStore) RegisterScanners(ctx context.Context, scnrs indexer.VersionedScanners) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RegisterScanners", arg0, arg1) + ret := m.ctrl.Call(m, "RegisterScanners", ctx, scnrs) ret0, _ := ret[0].(error) return ret0 } // RegisterScanners indicates an expected call of RegisterScanners. -func (mr *MockStoreMockRecorder) RegisterScanners(arg0, arg1 any) *gomock.Call { +func (mr *MockStoreMockRecorder) RegisterScanners(ctx, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterScanners", reflect.TypeOf((*MockStore)(nil).RegisterScanners), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterScanners", reflect.TypeOf((*MockStore)(nil).RegisterScanners), ctx, scnrs) } // RepositoriesByLayer mocks base method. -func (m *MockStore) RepositoriesByLayer(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanners) ([]*claircore.Repository, error) { +func (m *MockStore) RepositoriesByLayer(ctx context.Context, hash claircore.Digest, scnrs indexer.VersionedScanners) ([]*claircore.Repository, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RepositoriesByLayer", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "RepositoriesByLayer", ctx, hash, scnrs) ret0, _ := ret[0].([]*claircore.Repository) ret1, _ := ret[1].(error) return ret0, ret1 } // RepositoriesByLayer indicates an expected call of RepositoriesByLayer. -func (mr *MockStoreMockRecorder) RepositoriesByLayer(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) RepositoriesByLayer(ctx, hash, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RepositoriesByLayer", reflect.TypeOf((*MockStore)(nil).RepositoriesByLayer), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RepositoriesByLayer", reflect.TypeOf((*MockStore)(nil).RepositoriesByLayer), ctx, hash, scnrs) } // SetIndexFinished mocks base method. -func (m *MockStore) SetIndexFinished(arg0 context.Context, arg1 *claircore.IndexReport, arg2 indexer.VersionedScanners) error { +func (m *MockStore) SetIndexFinished(ctx context.Context, sr *claircore.IndexReport, scnrs indexer.VersionedScanners) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetIndexFinished", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "SetIndexFinished", ctx, sr, scnrs) ret0, _ := ret[0].(error) return ret0 } // SetIndexFinished indicates an expected call of SetIndexFinished. -func (mr *MockStoreMockRecorder) SetIndexFinished(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) SetIndexFinished(ctx, sr, scnrs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetIndexFinished", reflect.TypeOf((*MockStore)(nil).SetIndexFinished), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetIndexFinished", reflect.TypeOf((*MockStore)(nil).SetIndexFinished), ctx, sr, scnrs) } // SetIndexReport mocks base method. @@ -323,23 +341,38 @@ func (mr *MockStoreMockRecorder) SetIndexReport(arg0, arg1 any) *gomock.Call { } // SetLayerScanned mocks base method. -func (m *MockStore) SetLayerScanned(arg0 context.Context, arg1 claircore.Digest, arg2 indexer.VersionedScanner) error { +func (m *MockStore) SetLayerScanned(ctx context.Context, hash claircore.Digest, scnr indexer.VersionedScanner) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetLayerScanned", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "SetLayerScanned", ctx, hash, scnr) ret0, _ := ret[0].(error) return ret0 } // SetLayerScanned indicates an expected call of SetLayerScanned. -func (mr *MockStoreMockRecorder) SetLayerScanned(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStoreMockRecorder) SetLayerScanned(ctx, hash, scnr any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLayerScanned", reflect.TypeOf((*MockStore)(nil).SetLayerScanned), ctx, hash, scnr) +} + +// UpdateIndexerData mocks base method. +func (m *MockStore) UpdateIndexerData(ctx context.Context, fp driver.Fingerprint, d []driver.IndexerData) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateIndexerData", ctx, fp, d) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateIndexerData indicates an expected call of UpdateIndexerData. +func (mr *MockStoreMockRecorder) UpdateIndexerData(ctx, fp, d any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLayerScanned", reflect.TypeOf((*MockStore)(nil).SetLayerScanned), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateIndexerData", reflect.TypeOf((*MockStore)(nil).UpdateIndexerData), ctx, fp, d) } // MockPackageScanner is a mock of PackageScanner interface. type MockPackageScanner struct { ctrl *gomock.Controller recorder *MockPackageScannerMockRecorder + isgomock struct{} } // MockPackageScannerMockRecorder is the mock recorder for MockPackageScanner. @@ -420,6 +453,7 @@ func (mr *MockPackageScannerMockRecorder) Version() *gomock.Call { type MockVersionedScanner struct { ctrl *gomock.Controller recorder *MockVersionedScannerMockRecorder + isgomock struct{} } // MockVersionedScannerMockRecorder is the mock recorder for MockVersionedScanner. @@ -485,6 +519,7 @@ func (mr *MockVersionedScannerMockRecorder) Version() *gomock.Call { type MockDistributionScanner struct { ctrl *gomock.Controller recorder *MockDistributionScannerMockRecorder + isgomock struct{} } // MockDistributionScannerMockRecorder is the mock recorder for MockDistributionScanner. @@ -565,6 +600,7 @@ func (mr *MockDistributionScannerMockRecorder) Version() *gomock.Call { type MockRepositoryScanner struct { ctrl *gomock.Controller recorder *MockRepositoryScannerMockRecorder + isgomock struct{} } // MockRepositoryScannerMockRecorder is the mock recorder for MockRepositoryScanner. @@ -645,6 +681,7 @@ func (mr *MockRepositoryScannerMockRecorder) Version() *gomock.Call { type MockCoalescer struct { ctrl *gomock.Controller recorder *MockCoalescerMockRecorder + isgomock struct{} } // MockCoalescerMockRecorder is the mock recorder for MockCoalescer. @@ -665,24 +702,25 @@ func (m *MockCoalescer) EXPECT() *MockCoalescerMockRecorder { } // Coalesce mocks base method. -func (m *MockCoalescer) Coalesce(arg0 context.Context, arg1 []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { +func (m *MockCoalescer) Coalesce(ctx context.Context, artifacts []*indexer.LayerArtifacts) (*claircore.IndexReport, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Coalesce", arg0, arg1) + ret := m.ctrl.Call(m, "Coalesce", ctx, artifacts) ret0, _ := ret[0].(*claircore.IndexReport) ret1, _ := ret[1].(error) return ret0, ret1 } // Coalesce indicates an expected call of Coalesce. -func (mr *MockCoalescerMockRecorder) Coalesce(arg0, arg1 any) *gomock.Call { +func (mr *MockCoalescerMockRecorder) Coalesce(ctx, artifacts any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Coalesce", reflect.TypeOf((*MockCoalescer)(nil).Coalesce), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Coalesce", reflect.TypeOf((*MockCoalescer)(nil).Coalesce), ctx, artifacts) } // MockRealizer is a mock of Realizer interface. type MockRealizer struct { ctrl *gomock.Controller recorder *MockRealizerMockRecorder + isgomock struct{} } // MockRealizerMockRecorder is the mock recorder for MockRealizer. @@ -734,6 +772,7 @@ func (mr *MockRealizerMockRecorder) Realize(arg0, arg1 any) *gomock.Call { type MockFetchArena struct { ctrl *gomock.Controller recorder *MockFetchArenaMockRecorder + isgomock struct{} } // MockFetchArenaMockRecorder is the mock recorder for MockFetchArena. diff --git a/test/mock/updater/driver/v1/mocks.go b/test/mock/updater/driver/v1/mocks.go index 8ffa5d5ed..6bd86b418 100644 --- a/test/mock/updater/driver/v1/mocks.go +++ b/test/mock/updater/driver/v1/mocks.go @@ -24,6 +24,7 @@ import ( type MockUpdater struct { ctrl *gomock.Controller recorder *MockUpdaterMockRecorder + isgomock struct{} } // MockUpdaterMockRecorder is the mock recorder for MockUpdater. @@ -76,6 +77,7 @@ func (mr *MockUpdaterMockRecorder) Name() *gomock.Call { type MockUpdaterFactory struct { ctrl *gomock.Controller recorder *MockUpdaterFactoryMockRecorder + isgomock struct{} } // MockUpdaterFactoryMockRecorder is the mock recorder for MockUpdaterFactory. @@ -128,6 +130,7 @@ func (mr *MockUpdaterFactoryMockRecorder) Name() *gomock.Call { type MockVulnerabilityParser struct { ctrl *gomock.Controller recorder *MockVulnerabilityParserMockRecorder + isgomock struct{} } // MockVulnerabilityParserMockRecorder is the mock recorder for MockVulnerabilityParser. @@ -166,6 +169,7 @@ func (mr *MockVulnerabilityParserMockRecorder) ParseVulnerability(arg0, arg1 any type MockEnrichmentParser struct { ctrl *gomock.Controller recorder *MockEnrichmentParserMockRecorder + isgomock struct{} } // MockEnrichmentParserMockRecorder is the mock recorder for MockEnrichmentParser. diff --git a/test/mock/updater/mocks.go b/test/mock/updater/mocks.go index 592b8e8e5..ffd3f5d4d 100644 --- a/test/mock/updater/mocks.go +++ b/test/mock/updater/mocks.go @@ -22,6 +22,7 @@ import ( type MockStore struct { ctrl *gomock.Controller recorder *MockStoreMockRecorder + isgomock struct{} } // MockStoreMockRecorder is the mock recorder for MockStore. @@ -42,44 +43,44 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { } // GetLatestUpdateOperations mocks base method. -func (m *MockStore) GetLatestUpdateOperations(arg0 context.Context) ([]driver.UpdateOperation, error) { +func (m *MockStore) GetLatestUpdateOperations(ctx context.Context) ([]driver.UpdateOperation, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLatestUpdateOperations", arg0) + ret := m.ctrl.Call(m, "GetLatestUpdateOperations", ctx) ret0, _ := ret[0].([]driver.UpdateOperation) ret1, _ := ret[1].(error) return ret0, ret1 } // GetLatestUpdateOperations indicates an expected call of GetLatestUpdateOperations. -func (mr *MockStoreMockRecorder) GetLatestUpdateOperations(arg0 any) *gomock.Call { +func (mr *MockStoreMockRecorder) GetLatestUpdateOperations(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestUpdateOperations", reflect.TypeOf((*MockStore)(nil).GetLatestUpdateOperations), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestUpdateOperations", reflect.TypeOf((*MockStore)(nil).GetLatestUpdateOperations), ctx) } // UpdateEnrichments mocks base method. -func (m *MockStore) UpdateEnrichments(arg0 context.Context, arg1 uuid.UUID, arg2 string, arg3 driver.Fingerprint, arg4 []driver.EnrichmentRecord) error { +func (m *MockStore) UpdateEnrichments(ctx context.Context, ref uuid.UUID, kind string, fp driver.Fingerprint, es []driver.EnrichmentRecord) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateEnrichments", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "UpdateEnrichments", ctx, ref, kind, fp, es) ret0, _ := ret[0].(error) return ret0 } // UpdateEnrichments indicates an expected call of UpdateEnrichments. -func (mr *MockStoreMockRecorder) UpdateEnrichments(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockStoreMockRecorder) UpdateEnrichments(ctx, ref, kind, fp, es any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockStore)(nil).UpdateEnrichments), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnrichments", reflect.TypeOf((*MockStore)(nil).UpdateEnrichments), ctx, ref, kind, fp, es) } // UpdateVulnerabilities mocks base method. -func (m *MockStore) UpdateVulnerabilities(arg0 context.Context, arg1 uuid.UUID, arg2 string, arg3 driver.Fingerprint, arg4 *driver.ParsedVulnerabilities) error { +func (m *MockStore) UpdateVulnerabilities(ctx context.Context, ref uuid.UUID, updater string, fp driver.Fingerprint, vs *driver.ParsedVulnerabilities) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateVulnerabilities", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "UpdateVulnerabilities", ctx, ref, updater, fp, vs) ret0, _ := ret[0].(error) return ret0 } // UpdateVulnerabilities indicates an expected call of UpdateVulnerabilities. -func (mr *MockStoreMockRecorder) UpdateVulnerabilities(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockStoreMockRecorder) UpdateVulnerabilities(ctx, ref, updater, fp, vs any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockStore)(nil).UpdateVulnerabilities), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVulnerabilities", reflect.TypeOf((*MockStore)(nil).UpdateVulnerabilities), ctx, ref, updater, fp, vs) } diff --git a/updater/driver/v1/interfaces.go b/updater/driver/v1/interfaces.go index 2145eb0b0..db2659f53 100644 --- a/updater/driver/v1/interfaces.go +++ b/updater/driver/v1/interfaces.go @@ -67,3 +67,8 @@ type VulnerabilityParser interface { type EnrichmentParser interface { ParseEnrichment(context.Context, fs.FS) ([]EnrichmentRecord, error) } + +// TODO(crozzy): docs +type IndexerDataParser interface { + ParseIndexerData(context.Context, fs.FS) ([]IndexerData, error) +} diff --git a/updater/driver/v1/types.go b/updater/driver/v1/types.go index 16de17c12..768c5081b 100644 --- a/updater/driver/v1/types.go +++ b/updater/driver/v1/types.go @@ -86,3 +86,9 @@ type Repository struct { URI string CPE cpe.WFN } + +type IndexerData struct { + Namespace string + Key string + Value []byte +} diff --git a/updater/interfaces.go b/updater/interfaces.go index 19a09999e..ea6f2b9e3 100644 --- a/updater/interfaces.go +++ b/updater/interfaces.go @@ -25,6 +25,11 @@ type Store interface { GetLatestUpdateOperations(ctx context.Context) ([]driver.UpdateOperation, error) } +// TODO(crozzy): Docs +type IndexerStore interface { + UpdateIndexerData(ctx context.Context, fp driver.Fingerprint, id []driver.IndexerData) error +} + // Locker is the Context-based locking Updater expects. type Locker interface { // TryLock returns a canceled Context if it would need to wait to acquire diff --git a/updater/offline_v1.go b/updater/offline_v1.go index add39b9a4..4dd6cd2d8 100644 --- a/updater/offline_v1.go +++ b/updater/offline_v1.go @@ -124,7 +124,7 @@ func (u *Updater) importV1(ctx context.Context, sys fs.FS) error { } // Load into DB. - if len(res.Vulnerabilities.Vulnerability) != 0 { + if res.Vulnerabilities != nil && len(res.Vulnerabilities.Vulnerability) != 0 { if err := u.store.UpdateVulnerabilities(ctx, ref, name, fp, res.Vulnerabilities); err != nil { return err } @@ -136,6 +136,12 @@ func (u *Updater) importV1(ctx context.Context, sys fs.FS) error { } zlog.Info(ctx).Stringer("ref", ref).Msg("updated enrichments") } + if len(res.IndexerData) != 0 { + if err := u.indexerStore.UpdateIndexerData(ctx, fp, res.IndexerData); err != nil { + return err + } + zlog.Info(ctx).Stringer("ref", ref).Msg("updated indexer data") + } } return nil diff --git a/updater/updater.go b/updater/updater.go index cb49f55bd..d2332e11c 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -26,11 +26,12 @@ import ( // // Close must be called, or the program may panic. type Updater struct { - store Store - locker Locker - client *http.Client - configs driver.Configs - factories []driver.UpdaterFactory + store Store + indexerStore IndexerStore + locker Locker + client *http.Client + configs driver.Configs + factories []driver.UpdaterFactory } // New returns an Updater ready to use. @@ -38,7 +39,11 @@ type Updater struct { // None of the resources passed in the Options struct have any of their cleanup // methods called, and need to be safe for use by multiple goroutines. func New(ctx context.Context, opts *Options) (*Updater, error) { - if opts.Store == nil { + // TODO(crozzy): maybe change this logic, I'm not thrilled about having + // two seperate store interfaces but like needlessly fulfilling an interface + // where methods will be unused no-ops is also BS, maybe acceping something non-nil + // and casing later? + if opts.Store == nil && opts.IndexerStore == nil { return nil, errors.New("updater: no Store implementation provided") } if opts.Client == nil { @@ -46,11 +51,12 @@ func New(ctx context.Context, opts *Options) (*Updater, error) { } u := &Updater{ - store: opts.Store, - locker: opts.Locker, - client: opts.Client, - configs: opts.Configs, - factories: opts.Factories, + store: opts.Store, + locker: opts.Locker, + client: opts.Client, + configs: opts.Configs, + factories: opts.Factories, + indexerStore: opts.IndexerStore, } if opts.Locker == nil { @@ -103,7 +109,8 @@ type Options struct { Configs driver.Configs // Factories is a slice of UpdaterFactories that are used to construct // Updaters on demand. - Factories []driver.UpdaterFactory + Factories []driver.UpdaterFactory + IndexerStore IndexerStore } // All the internal machinery deals with this taggedUpdater type, so that we @@ -326,7 +333,24 @@ func (u *Updater) parseOne(ctx context.Context, tu taggedUpdater, in fs.FS) (*pa Int("ct", len(res.Enrichments)). Msg("found enrichments") } + if p, ok := upd.(driver.IndexerDataParser); ok { + zlog.Debug(ctx).Msg("implements IndexerDataParser") + any = true + res.IndexerData, err = p.ParseIndexerData(ctx, in) + if err != nil { + return + } + zlog.Debug(ctx). + Err(err). + Int("ct", len(res.IndexerData)). + Msg("found indexer data") + } + }) + + if err != nil { + return nil, fmt.Errorf("error parsing data: %w", err) + } if !any { return nil, errors.New("did nothing") } @@ -336,6 +360,7 @@ func (u *Updater) parseOne(ctx context.Context, tu taggedUpdater, in fs.FS) (*pa type parseResult struct { Vulnerabilities *driver.ParsedVulnerabilities Enrichments []driver.EnrichmentRecord + IndexerData []driver.IndexerData } func (u *Updater) fetchAndParse(ctx context.Context, spool *os.File, pfps map[string]driver.Fingerprint, tu taggedUpdater) error { @@ -386,6 +411,14 @@ func (u *Updater) fetchAndParse(ctx context.Context, spool *os.File, pfps map[st } zlog.Info(ctx).Stringer("ref", ref).Msg("updated enrichments") } + if len(res.IndexerData) != 0 { + err = u.indexerStore.UpdateIndexerData(ctx, fp, res.IndexerData) + if err != nil { + return + } + zlog.Info(ctx).Stringer("ref", ref).Msg("updated indexer data") + } + }) if err != nil { return err