Skip to content

Commit

Permalink
all: replace replace io.ReadCloser with io.Reader in updater Parse
Browse files Browse the repository at this point in the history
Signed-off-by: RTann <rtannenb@redhat.com>
  • Loading branch information
RTann committed Feb 24, 2025
1 parent e9c6e41 commit f89edfe
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 25 deletions.
3 changes: 1 addition & 2 deletions alpine/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion aws/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions datastore/postgres/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand All @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions debian/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libvuln/driver/enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions libvuln/driver/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion libvuln/updates/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions oracle/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions photon/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions rhel/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rhel/vex/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions suse/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ubuntu/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion updater/osv/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f89edfe

Please sign in to comment.