-
Notifications
You must be signed in to change notification settings - Fork 89
jsonblob: implement Load as documented #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BradLugo
wants to merge
2
commits into
quay:main
Choose a base branch
from
BradLugo:blugo/jsonblob-load
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Brad Lugo <[email protected]>
a8a9ad1 to
2002eaa
Compare
2002eaa to
aea8376
Compare
Signed-off-by: Brad Lugo <[email protected]>
aea8376 to
b3c3d38
Compare
BradLugo
commented
Jun 3, 2025
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 |
Contributor
Author
There was a problem hiding this comment.
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:
- Change the documentation to be specific to
Loaderinstead ofStore - Merge jsonblob: Support individual record iteration #1334, then use
Unmarshal()instead of using aLoaderto load the data.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Load()toNewLoader()Load()as documented, i.e., will load providedio.Readerin aStoreLoadertypes and methods to a separate fileStore.UpdateEnrichments()wheres.Enrichmentsweren’t being setStore.UpdateVulnerabilities()wheres.Vulnwasn’t being set