-
Notifications
You must be signed in to change notification settings - Fork 177
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
Enrich discover --verbose command tree output with additional data (Layers, data from Descriptor) #1501
base: main
Are you sure you want to change the base?
Conversation
…ayers, data from Descriptor)
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.
I'm not sure if this feature is wanted, but some general comments
fetchOpts := oras.DefaultFetchBytesOptions | ||
fetchOpts.TargetPlatform = platform.Platform | ||
_, content, err := oras.FetchBytes(ctx, target, digest.String(), fetchOpts) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to fetch the content of %q: %w", "", err) | ||
} | ||
|
||
var jsonMap map[string]any | ||
if err = json.Unmarshal(content, &jsonMap); err != nil { | ||
return false, err | ||
} | ||
|
||
if layers, ok := jsonMap["layers"].([]interface{}); ok { | ||
if len(layers) != 0 { |
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.
This whole thing seems to me like a method fetchLayers or something which returns layers or error
func addDescriptorInfo(referrer ocispec.Descriptor, referrerNode *tree.Node) { | ||
descriptorNode := referrerNode.AddPath("Descriptor") | ||
descriptorNode.AddPath(strings.TrimSpace("MediaType: " + referrer.MediaType)) | ||
descriptorNode.AddPath(strings.TrimSpace("Size: " + strconv.FormatInt(referrer.Size, 10))) | ||
} | ||
|
||
func addAnnotationsInfo(referrer ocispec.Descriptor, referrerNode *tree.Node) error { | ||
if len(referrer.Annotations) != 0 { | ||
annotationsNode := referrerNode.AddPath("Annotations") | ||
annotationsKeys := sortedKeys(referrer.Annotations) | ||
for _, k := range annotationsKeys { | ||
v := referrer.Annotations[k] |
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.
Seems like it would be easier to unit test this stuff if it was a wrapper for referrerNode and these were addDescriptor, addAnnotations, etc.
v := annotationsMap[k] | ||
bytes, err := yaml.Marshal(map[string]interface{}{k: v}) | ||
if err != nil { | ||
continue |
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.
This is too deep, something needs to be broken up here
results, err := registry.Referrers(ctx, repo, desc, artifactType) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, r := range results { | ||
if err := handler.OnDiscovered(r, desc); err != nil { | ||
if err := handler.OnDiscovered(r, desc, ctx, repo, platform); err != nil { |
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.
Not loving passing ctx in the middle here. I haven't looked everything over, but seems like this should be passing down a fetch method around here
WIP
Hi,
when I was investigating why Trivy does not see SBOMs attached to Harbor Images (it was because old Harbor v2.10.2 was malformes
ArtifactType
of attached SBOM JSON. It always override toapplication/vnd.oci.empty.v1+json
. In latest version of Harbor it is fixed), I found out that it is good to see (at that time only in debugger) some additional data about Images.What helped me, was to see
MediaType
fromDescriptor
, andMediaType
from Layers.What do you think about those additions to
--verbose
mode ofdiscover
command?Thank you
Ivos
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Please check the following list:
Output looks like this: