Skip to content

Commit b33f6a8

Browse files
alacukupoiana
authored andcommitted
feat(oci/puller): add Descriptor method to retrieve artifacts' descriptor
In some cases, the descriptor of an artifact is checked before pulling it. Signed-off-by: Aldo Lacuku <[email protected]>
1 parent 744ada5 commit b33f6a8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/oci/puller/puller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ func (p *Puller) Pull(ctx context.Context, ref, destDir, os, arch string) (*oci.
111111
}, nil
112112
}
113113

114+
// Descriptor retrieves the descriptor of an artifact from a remote repository.
115+
func (p *Puller) Descriptor(ctx context.Context, ref string) (*v1.Descriptor, error) {
116+
repo, err := remote.NewRepository(ref)
117+
if err != nil {
118+
return nil, fmt.Errorf("unable to create new repository with ref %s: %w", ref, err)
119+
}
120+
repo.Client = p.Client
121+
122+
desc, _, err := repo.FetchReference(ctx, ref)
123+
if err != nil {
124+
return nil, err
125+
}
126+
return &desc, nil
127+
}
128+
114129
func manifestFromDesc(ctx context.Context, target oras.Target, desc *v1.Descriptor) (*v1.Manifest, error) {
115130
var manifest v1.Manifest
116131

0 commit comments

Comments
 (0)