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 subject digest in oras discover #798

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 1 addition & 9 deletions cmd/oras/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/file"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down Expand Up @@ -164,14 +163,7 @@ func runAttach(opts attachOptions) error {

digest := subject.Digest.String()
if !strings.HasSuffix(opts.RawReference, digest) {
// Reassemble a reference with subject digest
if repo, ok := dst.(*remote.Repository); ok {
ref := repo.Reference
ref.Reference = subject.Digest.String()
opts.RawReference = ref.String()
} else if opts.Type == option.TargetTypeOCILayout {
opts.RawReference = fmt.Sprintf("%s@%s", opts.Path, subject.Digest)
}
opts.RawReference = fmt.Sprintf("%s@%s", opts.Path, subject.Digest)
}
fmt.Println("Attached to", opts.AnnotatedReference())
fmt.Println("Digest:", root.Digest)
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func runDiscover(opts discoverOptions) error {
}

if opts.outputType == "tree" {
root := tree.New(opts.Reference)
root := tree.New(fmt.Sprintf("%s@%s", opts.Path, desc.Digest))
err = fetchAllReferrers(ctx, repo, desc, opts.artifactType, root, &opts)
if err != nil {
return err
Expand Down
11 changes: 10 additions & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ type Target struct {
RawReference string
Type string
Reference string //contains tag or digest
Path string
// Path contains
// - path to the OCI image layout target, or
// - registry and repository for the remote target
Path string

isOCILayout bool
}
Expand Down Expand Up @@ -118,6 +121,9 @@ func (opts *Target) NewTarget(common Common) (oras.GraphTarget, error) {
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
}
Expand Down Expand Up @@ -153,6 +159,9 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common) (ReadO
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
}
Expand Down