github.com/mika/distribution@v2.2.2-0.20160108133430-a75790e3d8e0+incompatible/manifests.go (about) 1 package distribution 2 3 import ( 4 "fmt" 5 6 "github.com/docker/distribution/context" 7 "github.com/docker/distribution/digest" 8 ) 9 10 // Manifest represents a registry object specifying a set of 11 // references and an optional target 12 type Manifest interface { 13 // References returns a list of objects which make up this manifest. 14 // The references are strictly ordered from base to head. A reference 15 // is anything which can be represented by a distribution.Descriptor 16 References() []Descriptor 17 18 // Payload provides the serialized format of the manifest, in addition to 19 // the mediatype. 20 Payload() (mediatype string, payload []byte, err error) 21 } 22 23 // ManifestBuilder creates a manifest allowing one to include dependencies. 24 // Instances can be obtained from a version-specific manifest package. Manifest 25 // specific data is passed into the function which creates the builder. 26 type ManifestBuilder interface { 27 // Build creates the manifest from his builder. 28 Build(ctx context.Context) (Manifest, error) 29 30 // References returns a list of objects which have been added to this 31 // builder. The dependencies are returned in the order they were added, 32 // which should be from base to head. 33 References() []Descriptor 34 35 // AppendReference includes the given object in the manifest after any 36 // existing dependencies. If the add fails, such as when adding an 37 // unsupported dependency, an error may be returned. 38 AppendReference(dependency Describable) error 39 } 40 41 // ManifestService describes operations on image manifests. 42 type ManifestService interface { 43 // Exists returns true if the manifest exists. 44 Exists(ctx context.Context, dgst digest.Digest) (bool, error) 45 46 // Get retrieves the manifest specified by the given digest 47 Get(ctx context.Context, dgst digest.Digest, options ...ManifestServiceOption) (Manifest, error) 48 49 // Put creates or updates the given manifest returning the manifest digest 50 Put(ctx context.Context, manifest Manifest, options ...ManifestServiceOption) (digest.Digest, error) 51 52 // Delete removes the manifest specified by the given digest. Deleting 53 // a manifest that doesn't exist will return ErrManifestNotFound 54 Delete(ctx context.Context, dgst digest.Digest) error 55 56 // Enumerate fills 'manifests' with the manifests in this service up 57 // to the size of 'manifests' and returns 'n' for the number of entries 58 // which were filled. 'last' contains an offset in the manifest set 59 // and can be used to resume iteration. 60 //Enumerate(ctx context.Context, manifests []Manifest, last Manifest) (n int, err error) 61 } 62 63 // Describable is an interface for descriptors 64 type Describable interface { 65 Descriptor() Descriptor 66 } 67 68 // ManifestMediaTypes returns the supported media types for manifests. 69 func ManifestMediaTypes() (mediaTypes []string) { 70 for t := range mappings { 71 mediaTypes = append(mediaTypes, t) 72 } 73 return 74 } 75 76 // UnmarshalFunc implements manifest unmarshalling a given MediaType 77 type UnmarshalFunc func([]byte) (Manifest, Descriptor, error) 78 79 var mappings = make(map[string]UnmarshalFunc, 0) 80 81 // UnmarshalManifest looks up manifest unmarshall functions based on 82 // MediaType 83 func UnmarshalManifest(mediatype string, p []byte) (Manifest, Descriptor, error) { 84 unmarshalFunc, ok := mappings[mediatype] 85 if !ok { 86 return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype: %s", mediatype) 87 } 88 89 return unmarshalFunc(p) 90 } 91 92 // RegisterManifestSchema registers an UnmarshalFunc for a given schema type. This 93 // should be called from specific 94 func RegisterManifestSchema(mediatype string, u UnmarshalFunc) error { 95 if _, ok := mappings[mediatype]; ok { 96 return fmt.Errorf("manifest mediatype registration would overwrite existing: %s", mediatype) 97 } 98 mappings[mediatype] = u 99 return nil 100 }