From 96230176e9d4b476ef106e6f40948a76f1dbb175 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 14 Dec 2022 18:29:00 +0000 Subject: [PATCH] ociindex: add utility method for getting a single manifest from the index Signed-off-by: Justin Chadwell --- client/ociindex/ociindex.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/ociindex/ociindex.go b/client/ociindex/ociindex.go index b4db093798a2..3731ff36bb23 100644 --- a/client/ociindex/ociindex.go +++ b/client/ociindex/ociindex.go @@ -119,6 +119,18 @@ func (s StoreIndex) Get(tag string) (*ocispecs.Descriptor, error) { return nil, nil } +func (s StoreIndex) GetSingle() (*ocispecs.Descriptor, error) { + idx, err := s.Read() + if err != nil { + return nil, err + } + + if len(idx.Manifests) == 1 { + return &idx.Manifests[0], nil + } + return nil, nil +} + // insertDesc puts desc to index with tag. // Existing manifests with the same tag will be removed from the index. func insertDesc(index *ocispecs.Index, desc ocispecs.Descriptor, tag string) error {