varlink: Rename SearchImage to SearchImages

Also rename image result struct to `ImageSearchResult` and make `limit`
parameter optional.

Signed-off-by: Lars Karlitski <lars@karlitski.net>
This commit is contained in:
Lars Karlitski
2019-02-04 20:39:23 +01:00
parent 5a32518170
commit 2448129e4d
2 changed files with 16 additions and 13 deletions

View File

@ -46,9 +46,8 @@ type ImageHistory (
comment: string comment: string
) )
# ImageSearch is the returned structure for SearchImage. It is returned # Represents a single search result from SearchImages
# in array form. type ImageSearchResult (
type ImageSearch (
description: string, description: string,
is_official: bool, is_official: bool,
is_automated: bool, is_automated: bool,
@ -644,10 +643,10 @@ method TagImage(name: string, tagged: string) -> (image: string)
# ~~~ # ~~~
method RemoveImage(name: string, force: bool) -> (image: string) method RemoveImage(name: string, force: bool) -> (image: string)
# SearchImage takes the string of an image name and a limit of searches from each registries to be returned. SearchImage # SearchImages searches available registries for images that contain the
# will then use a glob-like match to find the image you are searching for. The images are returned in an array of # contents of "query" in their name. If "limit" is given, limits the amount of
# ImageSearch structures which contain information about the image as well as its fully-qualified name. # search results per registry.
method SearchImage(name: string, limit: int) -> (images: []ImageSearch) method SearchImages(query: string, limit: ?int) -> (results: []ImageSearchResult)
# DeleteUnusedImages deletes any images not associated with a container. The IDs of the deleted images are returned # DeleteUnusedImages deletes any images not associated with a container. The IDs of the deleted images are returned
# in a string array. # in a string array.

View File

@ -399,17 +399,21 @@ func (i *LibpodAPI) RemoveImage(call iopodman.VarlinkCall, name string, force bo
return call.ReplyRemoveImage(newImage.ID()) return call.ReplyRemoveImage(newImage.ID())
} }
// SearchImage searches all registries configured in /etc/containers/registries.conf for an image // SearchImages searches all registries configured in /etc/containers/registries.conf for an image
// Requires an image name and a search limit as int // Requires an image name and a search limit as int
func (i *LibpodAPI) SearchImage(call iopodman.VarlinkCall, name string, limit int64) error { func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit *int64) error {
sc := image.GetSystemContext("", "", false) sc := image.GetSystemContext("", "", false)
registries, err := sysreg.GetRegistries() registries, err := sysreg.GetRegistries()
if err != nil { if err != nil {
return call.ReplyErrorOccurred(fmt.Sprintf("unable to get system registries: %q", err)) return call.ReplyErrorOccurred(fmt.Sprintf("unable to get system registries: %q", err))
} }
var imageResults []iopodman.ImageSearch var imageResults []iopodman.ImageSearchResult
for _, reg := range registries { for _, reg := range registries {
results, err := docker.SearchRegistry(getContext(), sc, reg, name, int(limit)) var lim = 1000
if limit != nil {
lim = int(*limit)
}
results, err := docker.SearchRegistry(getContext(), sc, reg, query, lim)
if err != nil { if err != nil {
// If we are searching multiple registries, don't make something like an // If we are searching multiple registries, don't make something like an
// auth error fatal. Unfortunately we cannot differentiate between auth // auth error fatal. Unfortunately we cannot differentiate between auth
@ -420,7 +424,7 @@ func (i *LibpodAPI) SearchImage(call iopodman.VarlinkCall, name string, limit in
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }
for _, result := range results { for _, result := range results {
i := iopodman.ImageSearch{ i := iopodman.ImageSearchResult{
Description: result.Description, Description: result.Description,
Is_official: result.IsOfficial, Is_official: result.IsOfficial,
Is_automated: result.IsAutomated, Is_automated: result.IsAutomated,
@ -430,7 +434,7 @@ func (i *LibpodAPI) SearchImage(call iopodman.VarlinkCall, name string, limit in
imageResults = append(imageResults, i) imageResults = append(imageResults, i)
} }
} }
return call.ReplySearchImage(imageResults) return call.ReplySearchImages(imageResults)
} }
// DeleteUnusedImages deletes any images that do not have containers associated with it. // DeleteUnusedImages deletes any images that do not have containers associated with it.