From f89edfea310b735bcd2077b7e00f3ae05b960f87 Mon Sep 17 00:00:00 2001 From: RTann Date: Mon, 24 Feb 2025 13:57:24 -0800 Subject: [PATCH] all: replace replace io.ReadCloser with io.Reader in updater Parse Signed-off-by: RTann --- alpine/parser.go | 3 +-- aws/updater.go | 2 +- datastore/postgres/gc_test.go | 6 +++--- debian/parser.go | 3 +-- libvuln/driver/enrichment.go | 2 +- libvuln/driver/updater.go | 6 +++--- libvuln/updates/manager_test.go | 2 +- oracle/parser.go | 3 +-- photon/parser.go | 3 +-- rhel/parser.go | 3 +-- rhel/vex/parser.go | 2 +- suse/parser.go | 3 +-- ubuntu/updater.go | 3 +-- updater/osv/osv.go | 2 +- 14 files changed, 18 insertions(+), 25 deletions(-) diff --git a/alpine/parser.go b/alpine/parser.go index 015faae33..71d3fd8f4 100644 --- a/alpine/parser.go +++ b/alpine/parser.go @@ -17,10 +17,9 @@ const ( var _ driver.Parser = (*updater)(nil) -func (u *updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "alpine/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() var db SecurityDB if err := json.NewDecoder(r).Decode(&db); err != nil { diff --git a/aws/updater.go b/aws/updater.go index 16a550ab1..aa25d2e97 100644 --- a/aws/updater.go +++ b/aws/updater.go @@ -74,7 +74,7 @@ func (u *Updater) Fetch(ctx context.Context, fingerprint driver.Fingerprint) (io return rc, driver.Fingerprint(updatesRepoMD.Checksum.Sum), nil } -func (u *Updater) Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) { var updates alas.Updates dec := xml.NewDecoder(contents) dec.CharsetReader = xmlutil.CharsetReader diff --git a/datastore/postgres/gc_test.go b/datastore/postgres/gc_test.go index 4142836ad..e32fc1016 100644 --- a/datastore/postgres/gc_test.go +++ b/datastore/postgres/gc_test.go @@ -22,7 +22,7 @@ import ( type updaterMock struct { _name func() string _fetch func(_ context.Context, _ driver.Fingerprint) (io.ReadCloser, driver.Fingerprint, error) - _parse func(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) + _parse func(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) } func (u *updaterMock) Name() string { @@ -33,7 +33,7 @@ func (u *updaterMock) Fetch(ctx context.Context, fp driver.Fingerprint) (io.Read return u._fetch(ctx, fp) } -func (u *updaterMock) Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *updaterMock) Parse(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) { return u._parse(ctx, contents) } @@ -49,7 +49,7 @@ func TestGC(t *testing.T) { _fetch: func(_ context.Context, _ driver.Fingerprint) (io.ReadCloser, driver.Fingerprint, error) { return nil, "", nil }, - _parse: func(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) { + _parse: func(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) { return []*claircore.Vulnerability{ { Name: randString(t), diff --git a/debian/parser.go b/debian/parser.go index e9f6f0952..8a49a1b96 100644 --- a/debian/parser.go +++ b/debian/parser.go @@ -33,10 +33,9 @@ type ReleaseData struct { } // Parse implements [driver.Parser]. -func (u *updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "debian/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() var vulnsJSON JSONData err := json.NewDecoder(r).Decode(&vulnsJSON) diff --git a/libvuln/driver/enrichment.go b/libvuln/driver/enrichment.go index adf287e3a..ff565999f 100644 --- a/libvuln/driver/enrichment.go +++ b/libvuln/driver/enrichment.go @@ -51,7 +51,7 @@ func (u NoopUpdater) Fetch(_ context.Context, _ Fingerprint) (io.ReadCloser, Fin } // Parse implements Updater. -func (u NoopUpdater) Parse(_ context.Context, _ io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u NoopUpdater) Parse(_ context.Context, _ io.Reader) ([]*claircore.Vulnerability, error) { return []*claircore.Vulnerability{}, nil } diff --git a/libvuln/driver/updater.go b/libvuln/driver/updater.go index 4a06bdabb..c85455b46 100644 --- a/libvuln/driver/updater.go +++ b/libvuln/driver/updater.go @@ -19,13 +19,13 @@ type Updater interface { // Parser is an interface which is embedded into the Updater interface. // -// Parse should be called with an io.ReadCloser struct where the contents of a security +// Parse should be called with an io.Reader struct where the contents of a security // advisory database can be read and parsed into an array of *claircore.Vulnerability type Parser interface { - // Parse should take an io.ReadCloser, read the contents, parse the contents + // Parse should take an io.Reader, read the contents, parse the contents // into a list of claircore.Vulnerability structs and then return // the list. Parse should assume contents are uncompressed and ready for parsing. - Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) + Parse(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) } // Fetcher is an interface which is embedded into the Updater interface. diff --git a/libvuln/updates/manager_test.go b/libvuln/updates/manager_test.go index c6371e8ec..6871401fe 100644 --- a/libvuln/updates/manager_test.go +++ b/libvuln/updates/manager_test.go @@ -98,7 +98,7 @@ func (tu *testUpdater) Fetch(context.Context, driver.Fingerprint) (io.ReadCloser return nil, "", nil } -func (tu *testUpdater) Parse(ctx context.Context, vulnUpdates io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (tu *testUpdater) Parse(ctx context.Context, vulnUpdates io.Reader) ([]*claircore.Vulnerability, error) { // NOOP return nil, nil } diff --git a/oracle/parser.go b/oracle/parser.go index 6828b296a..d5d19f8ab 100644 --- a/oracle/parser.go +++ b/oracle/parser.go @@ -34,10 +34,9 @@ var platformToDist = map[string]*claircore.Distribution{ var _ driver.Parser = (*Updater)(nil) -func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "oracle/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() root := oval.Root{} dec := xml.NewDecoder(r) dec.CharsetReader = xmlutil.CharsetReader diff --git a/photon/parser.go b/photon/parser.go index 7467b1462..cb66bd57d 100644 --- a/photon/parser.go +++ b/photon/parser.go @@ -17,10 +17,9 @@ import ( var _ driver.Parser = (*Updater)(nil) -func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "photon/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() root := oval.Root{} dec := xml.NewDecoder(r) dec.CharsetReader = xmlutil.CharsetReader diff --git a/rhel/parser.go b/rhel/parser.go index 27ca353e5..dce016827 100644 --- a/rhel/parser.go +++ b/rhel/parser.go @@ -22,10 +22,9 @@ import ( // flavored OVAL XML. The distribution associated with vulnerabilities // is configured via the Updater. The repository associated with // vulnerabilies is based on the affected CPE list. -func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "rhel/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() root := oval.Root{} dec := xml.NewDecoder(r) dec.CharsetReader = xmlutil.CharsetReader diff --git a/rhel/vex/parser.go b/rhel/vex/parser.go index 7bd3a674e..bd4e736ad 100644 --- a/rhel/vex/parser.go +++ b/rhel/vex/parser.go @@ -24,7 +24,7 @@ import ( ) // Parse implements [driver.Updater]. -func (u *Updater) Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, contents io.Reader) ([]*claircore.Vulnerability, error) { // NOOP return nil, errors.ErrUnsupported } diff --git a/suse/parser.go b/suse/parser.go index e53cde0e0..e05302dcd 100644 --- a/suse/parser.go +++ b/suse/parser.go @@ -17,11 +17,10 @@ import ( var _ driver.Parser = (*Updater)(nil) -func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *Updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "suse/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() root := oval.Root{} dec := xml.NewDecoder(r) dec.CharsetReader = xmlutil.CharsetReader diff --git a/ubuntu/updater.go b/ubuntu/updater.go index 8060ecf33..6df5c2f52 100644 --- a/ubuntu/updater.go +++ b/ubuntu/updater.go @@ -141,11 +141,10 @@ func (u *updater) Fetch(ctx context.Context, fingerprint driver.Fingerprint) (io } // Parse implements [driver.Updater]. -func (u *updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "ubuntu/Updater.Parse") zlog.Info(ctx).Msg("starting parse") - defer r.Close() root := oval.Root{} dec := xml.NewDecoder(r) dec.CharsetReader = xmlutil.CharsetReader diff --git a/updater/osv/osv.go b/updater/osv/osv.go index 596608902..ded38a840 100644 --- a/updater/osv/osv.go +++ b/updater/osv/osv.go @@ -328,7 +328,7 @@ func (u *updater) Fetch(ctx context.Context, fp driver.Fingerprint) (io.ReadClos } // Fetcher implements driver.Updater. -func (u *updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) { +func (u *updater) Parse(ctx context.Context, r io.Reader) ([]*claircore.Vulnerability, error) { ctx = zlog.ContextWithValues(ctx, "component", "updater/osv/updater.Parse") ra, ok := r.(io.ReaderAt) if !ok {