registry.go 3.9 KB

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