1 /* 2 Copyright The ORAS Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 package registry 16 17 import ( 18 "context" 19 ) 20 21 // Repository is an ORAS target and an union of the blob and the manifest CASs. 22 // As specified by https://docs.docker.com/registry/spec/api/, it is natural to 23 // assume that content.Resolver interface only works for manifests. Tagging a 24 // blob may be resulted in an `ErrUnsupported` error. However, this interface 25 // does not restrict tagging blobs. 26 // Since a repository is an union of the blob and the manifest CASs, all 27 // operations defined in the `BlobStore` are executed depending on the media 28 // type of the given descriptor accordingly. 29 // Furthurmore, this interface also provides the ability to enforce the 30 // separation of the blob and the manifests CASs. 31 type Repository interface { 32 33 // Tags lists the tags available in the repository. 34 // Since the returned tag list may be paginated by the underlying 35 // implementation, a function should be passed in to process the paginated 36 // tag list. 37 // Note: When implemented by a remote registry, the tags API is called. 38 // However, not all registries supports pagination or conforms the 39 // specification. 40 // References: 41 // - https://github.com/opencontainers/distribution-spec/blob/main/spec.md#content-discovery 42 // - https://docs.docker.com/registry/spec/api/#tags 43 // See also `Tags()` in this package. 44 Tags(ctx context.Context, fn func(tags []string) error) error 45 } 46 47 // Tags lists the tags available in the repository. 48 func Tags(ctx context.Context, repo Repository) ([]string, error) { 49 var res []string 50 if err := repo.Tags(ctx, func(tags []string) error { 51 res = append(res, tags...) 52 return nil 53 }); err != nil { 54 return nil, err 55 } 56 return res, nil 57 } 58