summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorCory Snider <csnider@mirantis.com>2023-02-28 16:54:20 -0500
committerCory Snider <csnider@mirantis.com>2023-03-10 18:36:33 -0500
commit3991faf4640a46412a8af000ede78fc5cba76d0a (patch)
treece7a581e1bb15a2c75f668a4d29bb0bef737116c /api
parent2fa66cfce2523f6e38bcccc1161055b46c3c6a90 (diff)
downloaddocker-3991faf4640a46412a8af000ede78fc5cba76d0a.tar.gz
Move filtered registry search out of image service
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>
Diffstat (limited to 'api')
-rw-r--r--api/server/router/image/backend.go5
-rw-r--r--api/server/router/image/image.go4
-rw-r--r--api/server/router/image/image_routes.go4
3 files changed, 9 insertions, 4 deletions
diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go
index d4558fd0dd..6dcee6f100 100644
--- a/api/server/router/image/backend.go
+++ b/api/server/router/image/backend.go
@@ -39,5 +39,8 @@ type importExportBackend interface {
type registryBackend interface {
PullImage(ctx context.Context, image, tag string, platform *specs.Platform, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error
PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error
- SearchRegistryForImages(ctx context.Context, searchFilters filters.Args, term string, limit int, authConfig *registry.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error)
+}
+
+type Searcher interface {
+ Search(ctx context.Context, searchFilters filters.Args, term string, limit int, authConfig *registry.AuthConfig, metaHeaders map[string][]string) ([]registry.SearchResult, error)
}
diff --git a/api/server/router/image/image.go b/api/server/router/image/image.go
index 70750d09af..7dd1eabf44 100644
--- a/api/server/router/image/image.go
+++ b/api/server/router/image/image.go
@@ -10,6 +10,7 @@ import (
// 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
@@ -17,9 +18,10 @@ type imageRouter struct {
}
// NewRouter initializes a new image router
-func NewRouter(backend Backend, referenceBackend reference.Store, imageStore image.Store, layerStore layer.Store) router.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,
diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go
index 5e0cbac315..3140a663ab 100644
--- a/api/server/router/image/image_routes.go
+++ b/api/server/router/image/image_routes.go
@@ -415,11 +415,11 @@ func (ir *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWrite
// For a search it is not an error if no auth was given. Ignore invalid
// AuthConfig to increase compatibility with the existing API.
authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))
- query, err := ir.backend.SearchRegistryForImages(ctx, searchFilters, r.Form.Get("term"), limit, authConfig, headers)
+ res, err := ir.searcher.Search(ctx, searchFilters, r.Form.Get("term"), limit, authConfig, headers)
if err != nil {
return err
}
- return httputils.WriteJSON(w, http.StatusOK, query.Results)
+ return httputils.WriteJSON(w, http.StatusOK, res)
}
func (ir *imageRouter) postImagesPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {