github.com/skf/moby@v1.13.1/distribution/metadata/v1_id_service.go (about) 1 package metadata 2 3 import ( 4 "github.com/docker/docker/image/v1" 5 "github.com/docker/docker/layer" 6 "github.com/pkg/errors" 7 ) 8 9 // V1IDService maps v1 IDs to layers on disk. 10 type V1IDService struct { 11 store Store 12 } 13 14 // NewV1IDService creates a new V1 ID mapping service. 15 func NewV1IDService(store Store) *V1IDService { 16 return &V1IDService{ 17 store: store, 18 } 19 } 20 21 // namespace returns the namespace used by this service. 22 func (idserv *V1IDService) namespace() string { 23 return "v1id" 24 } 25 26 // Get finds a layer by its V1 ID. 27 func (idserv *V1IDService) Get(v1ID, registry string) (layer.DiffID, error) { 28 if idserv.store == nil { 29 return "", errors.New("no v1IDService storage") 30 } 31 if err := v1.ValidateID(v1ID); err != nil { 32 return layer.DiffID(""), err 33 } 34 35 idBytes, err := idserv.store.Get(idserv.namespace(), registry+","+v1ID) 36 if err != nil { 37 return layer.DiffID(""), err 38 } 39 return layer.DiffID(idBytes), nil 40 } 41 42 // Set associates an image with a V1 ID. 43 func (idserv *V1IDService) Set(v1ID, registry string, id layer.DiffID) error { 44 if idserv.store == nil { 45 return nil 46 } 47 if err := v1.ValidateID(v1ID); err != nil { 48 return err 49 } 50 return idserv.store.Set(idserv.namespace(), registry+","+v1ID, []byte(id)) 51 }