Skip to content
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

feat: show annotations in oras discover tree format output #735

Merged
merged 7 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cmd/oras/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"strings"

"gopkg.in/yaml.v3"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras/cmd/oras/internal/errors"
Expand Down Expand Up @@ -101,7 +102,7 @@ func runDiscover(opts discoverOptions) error {

if opts.outputType == "tree" {
root := tree.New(repo.Reference.String())
err = fetchAllReferrers(ctx, repo, desc, opts.artifactType, root)
err = opts.fetchAllReferrers(ctx, repo, desc, opts.artifactType, root)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +142,7 @@ func fetchReferrers(ctx context.Context, repo *remote.Repository, desc ocispec.D
return results, nil
}

func fetchAllReferrers(ctx context.Context, repo *remote.Repository, desc ocispec.Descriptor, artifactType string, node *tree.Node) error {
func (opts *discoverOptions) fetchAllReferrers(ctx context.Context, repo *remote.Repository, desc ocispec.Descriptor, artifactType string, node *tree.Node) error {
qweeah marked this conversation as resolved.
Show resolved Hide resolved
results, err := fetchReferrers(ctx, repo, desc, artifactType)
if err != nil {
return err
Expand All @@ -150,7 +151,17 @@ func fetchAllReferrers(ctx context.Context, repo *remote.Repository, desc ocispe
for _, r := range results {
// Find all indirect referrers
referrerNode := node.AddPath(r.ArtifactType, r.Digest)
err := fetchAllReferrers(
if opts.Verbose {
bytes, err := yaml.Marshal(r.Annotations)
if err != nil {
return err
}
annotations := strings.Split(strings.TrimSpace(string(bytes)), "\n")
for _, a := range annotations {
referrerNode.AddPathString(a)
}
qweeah marked this conversation as resolved.
Show resolved Hide resolved
}
err := opts.fetchAllReferrers(
ctx, repo,
ocispec.Descriptor{
Digest: r.Digest,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.0.0-rc.6
)

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down