From 6ae4401bd1c7988b84c6e1f715ca85ad74ee4048 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 19 Feb 2019 16:29:14 +0100 Subject: iopodman.SearchImages: add ImageSearchFilter to Varlink API Also add some argument checks to the Varlink function to avoid referencing nil pointers, and complement the API.md descriptions. The varlink endpoint can be tested via varlink CLI: $ varlink call -m unix:/run/podman/io.podman/io.podman.SearchImages \ '{"query": "ruby", "limit": 0, "tlsVerify": false, "filter": {}}' Signed-off-by: Valentin Rothberg --- pkg/varlinkapi/images.go | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'pkg') diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index 032160b1b..d12ab97ab 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -434,16 +434,36 @@ func (i *LibpodAPI) RemoveImage(call iopodman.VarlinkCall, name string, force bo // SearchImages searches all registries configured in /etc/containers/registries.conf for an image // Requires an image name and a search limit as int -func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit *int64, tlsVerify *bool, filter []string) error { - sFilter, err := image.ParseSearchFilter(filter) - if err != nil { - return call.ReplyErrorOccurred(err.Error()) +func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit *int64, tlsVerify *bool, filter iopodman.ImageSearchFilter) error { + // Transform all arguments to proper types first + argLimit := 0 + argTLSVerify := types.OptionalBoolUndefined + argIsOfficial := types.OptionalBoolUndefined + argIsAutomated := types.OptionalBoolUndefined + if limit != nil { + argLimit = int(*limit) + } + if tlsVerify != nil { + argTLSVerify = types.NewOptionalBool(!*tlsVerify) + } + if filter.Is_official != nil { + argIsOfficial = types.NewOptionalBool(*filter.Is_official) + } + if filter.Is_automated != nil { + argIsAutomated = types.NewOptionalBool(*filter.Is_automated) + } + + // Transform a SearchFilter the backend can deal with + sFilter := image.SearchFilter{ + IsOfficial: argIsOfficial, + IsAutomated: argIsAutomated, + Stars: int(filter.Star_count), } searchOptions := image.SearchOptions{ - Limit: 1000, - Filter: *sFilter, - InsecureSkipTLSVerify: types.NewOptionalBool(!*tlsVerify), + Limit: argLimit, + Filter: sFilter, + InsecureSkipTLSVerify: argTLSVerify, } results, err := image.SearchImages(query, searchOptions) if err != nil { -- cgit v1.2.3-54-g00ecf