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 <rothberg@redhat.com>
This commit is contained in:
parent
8a49b59ed4
commit
6ae4401bd1
13
API.md
13
API.md
|
|
@ -107,7 +107,7 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
|
||||||
|
|
||||||
[func RestartPod(name: string) string](#RestartPod)
|
[func RestartPod(name: string) string](#RestartPod)
|
||||||
|
|
||||||
[func SearchImages(query: string, limit: int, tlsVerify: ?bool, filter: []string) ImageSearchResult](#SearchImages)
|
[func SearchImages(query: string, limit: int, tlsVerify: ?bool, filter: ImageSearchFilter) ImageSearchResult](#SearchImages)
|
||||||
|
|
||||||
[func SendFile(type: string, length: int) string](#SendFile)
|
[func SendFile(type: string, length: int) string](#SendFile)
|
||||||
|
|
||||||
|
|
@ -163,6 +163,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
|
||||||
|
|
||||||
[type ImageHistory](#ImageHistory)
|
[type ImageHistory](#ImageHistory)
|
||||||
|
|
||||||
|
[type ImageSearchFilter](#ImageSearchFilter)
|
||||||
|
|
||||||
[type ImageSearchResult](#ImageSearchResult)
|
[type ImageSearchResult](#ImageSearchResult)
|
||||||
|
|
||||||
[type InfoDistribution](#InfoDistribution)
|
[type InfoDistribution](#InfoDistribution)
|
||||||
|
|
@ -1408,6 +1410,15 @@ tags [[]string](#[]string)
|
||||||
size [int](https://godoc.org/builtin#int)
|
size [int](https://godoc.org/builtin#int)
|
||||||
|
|
||||||
comment [string](https://godoc.org/builtin#string)
|
comment [string](https://godoc.org/builtin#string)
|
||||||
|
### <a name="ImageSearchFilter"></a>type ImageSearchFilter
|
||||||
|
|
||||||
|
Represents a filter for SearchImages
|
||||||
|
|
||||||
|
is_official [bool](https://godoc.org/builtin#bool)
|
||||||
|
|
||||||
|
is_automated [bool](https://godoc.org/builtin#bool)
|
||||||
|
|
||||||
|
star_count [int](https://godoc.org/builtin#int)
|
||||||
### <a name="ImageSearchResult"></a>type ImageSearchResult
|
### <a name="ImageSearchResult"></a>type ImageSearchResult
|
||||||
|
|
||||||
Represents a single search result from SearchImages
|
Represents a single search result from SearchImages
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,12 @@ type ImageSearchResult (
|
||||||
star_count: int
|
star_count: int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ImageSearchFilter (
|
||||||
|
is_official: ?bool,
|
||||||
|
is_automated: ?bool,
|
||||||
|
star_count: int
|
||||||
|
)
|
||||||
|
|
||||||
type Container (
|
type Container (
|
||||||
id: string,
|
id: string,
|
||||||
image: string,
|
image: string,
|
||||||
|
|
@ -681,7 +687,7 @@ method RemoveImage(name: string, force: bool) -> (image: string)
|
||||||
# SearchImages searches available registries for images that contain the
|
# SearchImages searches available registries for images that contain the
|
||||||
# contents of "query" in their name. If "limit" is given, limits the amount of
|
# contents of "query" in their name. If "limit" is given, limits the amount of
|
||||||
# search results per registry.
|
# search results per registry.
|
||||||
method SearchImages(query: string, limit: ?int, tlsVerify: ?bool, filter: []string) -> (results: []ImageSearchResult)
|
method SearchImages(query: string, limit: ?int, tlsVerify: ?bool, filter: ImageSearchFilter) -> (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.
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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) SearchImages(call iopodman.VarlinkCall, query string, limit *int64, tlsVerify *bool, filter []string) error {
|
func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit *int64, tlsVerify *bool, filter iopodman.ImageSearchFilter) error {
|
||||||
sFilter, err := image.ParseSearchFilter(filter)
|
// Transform all arguments to proper types first
|
||||||
if err != nil {
|
argLimit := 0
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
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{
|
searchOptions := image.SearchOptions{
|
||||||
Limit: 1000,
|
Limit: argLimit,
|
||||||
Filter: *sFilter,
|
Filter: sFilter,
|
||||||
InsecureSkipTLSVerify: types.NewOptionalBool(!*tlsVerify),
|
InsecureSkipTLSVerify: argTLSVerify,
|
||||||
}
|
}
|
||||||
results, err := image.SearchImages(query, searchOptions)
|
results, err := image.SearchImages(query, searchOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue