1package distribution 2 3import ( 4 "context" 5 6 "github.com/docker/distribution/reference" 7) 8 9// Scope defines the set of items that match a namespace. 10type Scope interface { 11 // Contains returns true if the name belongs to the namespace. 12 Contains(name string) bool 13} 14 15type fullScope struct{} 16 17func (f fullScope) Contains(string) bool { 18 return true 19} 20 21// GlobalScope represents the full namespace scope which contains 22// all other scopes. 23var GlobalScope = Scope(fullScope{}) 24 25// Namespace represents a collection of repositories, addressable by name. 26// Generally, a namespace is backed by a set of one or more services, 27// providing facilities such as registry access, trust, and indexing. 28type Namespace interface { 29 // Scope describes the names that can be used with this Namespace. The 30 // global namespace will have a scope that matches all names. The scope 31 // effectively provides an identity for the namespace. 32 Scope() Scope 33 34 // Repository should return a reference to the named repository. The 35 // registry may or may not have the repository but should always return a 36 // reference. 37 Repository(ctx context.Context, name reference.Named) (Repository, error) 38 39 // Repositories fills 'repos' with a lexicographically sorted catalog of repositories 40 // up to the size of 'repos' and returns the value 'n' for the number of entries 41 // which were filled. 'last' contains an offset in the catalog, and 'err' will be 42 // set to io.EOF if there are no more entries to obtain. 43 Repositories(ctx context.Context, repos []string, last string) (n int, err error) 44 45 // Blobs returns a blob enumerator to access all blobs 46 Blobs() BlobEnumerator 47 48 // BlobStatter returns a BlobStatter to control 49 BlobStatter() BlobStatter 50} 51 52// RepositoryEnumerator describes an operation to enumerate repositories 53type RepositoryEnumerator interface { 54 Enumerate(ctx context.Context, ingester func(string) error) error 55} 56 57// RepositoryRemover removes given repository 58type RepositoryRemover interface { 59 Remove(ctx context.Context, name reference.Named) error 60} 61 62// ManifestServiceOption is a function argument for Manifest Service methods 63type ManifestServiceOption interface { 64 Apply(ManifestService) error 65} 66 67// WithTag allows a tag to be passed into Put 68func WithTag(tag string) ManifestServiceOption { 69 return WithTagOption{tag} 70} 71 72// WithTagOption holds a tag 73type WithTagOption struct{ Tag string } 74 75// Apply conforms to the ManifestServiceOption interface 76func (o WithTagOption) Apply(m ManifestService) error { 77 // no implementation 78 return nil 79} 80 81// WithManifestMediaTypes lists the media types the client wishes 82// the server to provide. 83func WithManifestMediaTypes(mediaTypes []string) ManifestServiceOption { 84 return WithManifestMediaTypesOption{mediaTypes} 85} 86 87// WithManifestMediaTypesOption holds a list of accepted media types 88type WithManifestMediaTypesOption struct{ MediaTypes []string } 89 90// Apply conforms to the ManifestServiceOption interface 91func (o WithManifestMediaTypesOption) Apply(m ManifestService) error { 92 // no implementation 93 return nil 94} 95 96// Repository is a named collection of manifests and layers. 97type Repository interface { 98 // Named returns the name of the repository. 99 Named() reference.Named 100 101 // Manifests returns a reference to this repository's manifest service. 102 // with the supplied options applied. 103 Manifests(ctx context.Context, options ...ManifestServiceOption) (ManifestService, error) 104 105 // Blobs returns a reference to this repository's blob service. 106 Blobs(ctx context.Context) BlobStore 107 108 // TODO(stevvooe): The above BlobStore return can probably be relaxed to 109 // be a BlobService for use with clients. This will allow such 110 // implementations to avoid implementing ServeBlob. 111 112 // Tags returns a reference to this repositories tag service 113 Tags(ctx context.Context) TagService 114} 115 116// TODO(stevvooe): Must add close methods to all these. May want to change the 117// way instances are created to better reflect internal dependency 118// relationships. 119