mirror of
https://github.com/moby/moby.git
synced 2026-08-04 15:11:00 +00:00
SearchRegistryForImages does not make sense as part of the image service interface. The implementation just wraps the search API of the registry service to filter the results client-side. It has nothing to do with local image storage, and the implementation of search does not need to change when changing which backend (graph driver vs. containerd snapshotter) is used for local image storage. Filtering of the search results is an implementation detail: the consumer of the results does not care which actor does the filtering so long as the results are filtered as requested. Move filtering into the exported API of the registry service to hide the implementation details. Only one thing---the registry service implementation---would need to change in order to support server-side filtering of search results if Docker Hub or other registry servers were to add support for it to their APIs. Use a fake registry server in the search unit tests to avoid having to mock out the registry API client. Signed-off-by: Cory Snider <csnider@mirantis.com>
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package image // import "github.com/docker/docker/api/server/router/image"
|
|
|
|
import (
|
|
"github.com/docker/docker/api/server/router"
|
|
"github.com/docker/docker/image"
|
|
"github.com/docker/docker/layer"
|
|
"github.com/docker/docker/reference"
|
|
)
|
|
|
|
// imageRouter is a router to talk with the image controller
|
|
type imageRouter struct {
|
|
backend Backend
|
|
searcher Searcher
|
|
referenceBackend reference.Store
|
|
imageStore image.Store
|
|
layerStore layer.Store
|
|
routes []router.Route
|
|
}
|
|
|
|
// NewRouter initializes a new image router
|
|
func NewRouter(backend Backend, searcher Searcher, referenceBackend reference.Store, imageStore image.Store, layerStore layer.Store) router.Router {
|
|
ir := &imageRouter{
|
|
backend: backend,
|
|
searcher: searcher,
|
|
referenceBackend: referenceBackend,
|
|
imageStore: imageStore,
|
|
layerStore: layerStore,
|
|
}
|
|
ir.initRoutes()
|
|
return ir
|
|
}
|
|
|
|
// Routes returns the available routes to the image controller
|
|
func (ir *imageRouter) Routes() []router.Route {
|
|
return ir.routes
|
|
}
|
|
|
|
// initRoutes initializes the routes in the image router
|
|
func (ir *imageRouter) initRoutes() {
|
|
ir.routes = []router.Route{
|
|
// GET
|
|
router.NewGetRoute("/images/json", ir.getImagesJSON),
|
|
router.NewGetRoute("/images/search", ir.getImagesSearch),
|
|
router.NewGetRoute("/images/get", ir.getImagesGet),
|
|
router.NewGetRoute("/images/{name:.*}/get", ir.getImagesGet),
|
|
router.NewGetRoute("/images/{name:.*}/history", ir.getImagesHistory),
|
|
router.NewGetRoute("/images/{name:.*}/json", ir.getImagesByName),
|
|
// POST
|
|
router.NewPostRoute("/images/load", ir.postImagesLoad),
|
|
router.NewPostRoute("/images/create", ir.postImagesCreate),
|
|
router.NewPostRoute("/images/{name:.*}/push", ir.postImagesPush),
|
|
router.NewPostRoute("/images/{name:.*}/tag", ir.postImagesTag),
|
|
router.NewPostRoute("/images/prune", ir.postImagesPrune),
|
|
// DELETE
|
|
router.NewDeleteRoute("/images/{name:.*}", ir.deleteImages),
|
|
}
|
|
}
|