| 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 |
|
| 16 |
// Package registry provides high-level operations to manage registries. |
| 17 |
package registry |
| 18 |
|
| 19 |
import "context" |
| 20 |
|
| 21 |
// Registry represents a collection of repositories. |
| 22 |
type Registry interface { |
| 23 |
// Repositories lists the name of repositories available in the registry. |
| 24 |
// Since the returned repositories may be paginated by the underlying |
| 25 |
// implementation, a function should be passed in to process the paginated |
| 26 |
// repository list. |
| 27 |
// `last` argument is the `last` parameter when invoking the catalog API. |
| 28 |
// If `last` is NOT empty, the entries in the response start after the |
| 29 |
// repo specified by `last`. Otherwise, the response starts from the top |
| 30 |
// of the Repositories list. |
| 31 |
// Note: When implemented by a remote registry, the catalog API is called. |
| 32 |
// However, not all registries supports pagination or conforms the |
| 33 |
// specification. |
| 34 |
// Reference: https://distribution.github.io/distribution/spec/api/#catalog |
| 35 |
// See also `Repositories()` in this package. |
| 36 |
Repositories(ctx context.Context, last string, fn func(repos []string) error) error |
| 37 |
|
| 38 |
// Repository returns a repository reference by the given name. |
| 39 |
Repository(ctx context.Context, name string) (Repository, error) |
| 40 |
} |
| 41 |
|
| 42 |
// Repositories lists the name of repositories available in the registry. |
| 43 |
func Repositories(ctx context.Context, reg Registry) ([]string, error) { |
| 44 |
var res []string |
| 45 |
if err := reg.Repositories(ctx, "", func(repos []string) error { |
| 46 |
res = append(res, repos...) |
| 47 |
return nil |
| 48 |
}); err != nil { |
| 49 |
return nil, err |
| 50 |
} |
| 51 |
return res, nil |
| 52 |
} |