Skip to content

Conversation

@BradLugo
Copy link
Contributor

@BradLugo BradLugo commented May 31, 2025

  • Changes current Load() to NewLoader()
  • Implements Load() as documented, i.e., will load provided io.Reader in a Store
  • Moves Loader types and methods to a separate file
  • Fixes a bug in Store.UpdateEnrichments() where s.Enrichments weren’t being set
  • Fixes a bug in Store.UpdateVulnerabilities() where s.Vuln wasn’t being set

@BradLugo BradLugo force-pushed the blugo/jsonblob-load branch from a8a9ad1 to 2002eaa Compare June 1, 2025 17:47
@BradLugo BradLugo marked this pull request as ready for review June 1, 2025 17:51
@BradLugo BradLugo requested a review from a team as a code owner June 1, 2025 17:51
@BradLugo BradLugo requested review from crozzy and removed request for a team June 1, 2025 17:51
@BradLugo BradLugo force-pushed the blugo/jsonblob-load branch from 2002eaa to aea8376 Compare June 1, 2025 17:52
@BradLugo BradLugo requested review from a team, RTann, crozzy, daynewlee and hdonnay and removed request for crozzy June 1, 2025 17:53
@BradLugo BradLugo force-pushed the blugo/jsonblob-load branch from aea8376 to b3c3d38 Compare June 1, 2025 18:11
Comment on lines 47 to +64
// Load reads in all the records serialized in the provided [io.Reader].
func Load(ctx context.Context, r io.Reader) (*Loader, error) {
l := Loader{
dec: json.NewDecoder(r),
cur: uuid.Nil,
func Load(ctx context.Context, r io.Reader) (*Store, error) {
s, err := New()
if err != nil {
return nil, err
}
return &l, nil
}

// Loader is an iterator that returns a series of [Entry].
//
// Users should call [*Loader.Next] until it reports false, then check for
// errors via [*Loader.Err].
type Loader struct {
err error
e *Entry

dec *json.Decoder
next *Entry
de diskEntry
cur uuid.UUID
}

// Next reports whether there's an [Entry] to be processed.
func (l *Loader) Next() bool {
if l.err != nil {
return false
l, err := NewLoader(r)
if err != nil {
return nil, err
}

for l.err = l.dec.Decode(&l.de); l.err == nil; l.err = l.dec.Decode(&l.de) {
id := l.de.Ref
// If we just hit a new Entry, promote the current one.
if id != l.cur {
l.e = l.next
l.next = &Entry{}
l.next.Updater = l.de.Updater
l.next.Fingerprint = l.de.Fingerprint
l.next.Date = l.de.Date
// TODO(DO NOT MERGE): ~~This implementation might be a bit naive. Currently,
// it basically copies [OfflineImport]. We could probably do some custom
// parsing such that it basically just decodes the json into the
// appropriate [Store] fields.~~
// Actually, this might be the way.
// [OfflineImport]: https://github.com/quay/claircore/blob/126f688bb11220fb34708719be91952dc32ff7b1/libvuln/updates.go#L17-L74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of other thoughts here - we could either:

  1. Change the documentation to be specific to Loader instead of Store
  2. Merge jsonblob: Support individual record iteration #1334, then use Unmarshal() instead of using a Loader to load the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant