Skip to content

Commit 9623017

Browse files
committed
ociindex: add utility method for getting a single manifest from the index
Signed-off-by: Justin Chadwell <[email protected]>
1 parent 49c2275 commit 9623017

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

client/ociindex/ociindex.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ func (s StoreIndex) Get(tag string) (*ocispecs.Descriptor, error) {
119119
return nil, nil
120120
}
121121

122+
func (s StoreIndex) GetSingle() (*ocispecs.Descriptor, error) {
123+
idx, err := s.Read()
124+
if err != nil {
125+
return nil, err
126+
}
127+
128+
if len(idx.Manifests) == 1 {
129+
return &idx.Manifests[0], nil
130+
}
131+
return nil, nil
132+
}
133+
122134
// insertDesc puts desc to index with tag.
123135
// Existing manifests with the same tag will be removed from the index.
124136
func insertDesc(index *ocispecs.Index, desc ocispecs.Descriptor, tag string) error {

0 commit comments

Comments
 (0)