diff options
author | Matej Marusak <mmarusak@redhat.com> | 2020-02-17 18:43:37 +0100 |
---|---|---|
committer | Matej Marusak <mmarusak@redhat.com> | 2020-02-17 18:44:46 +0100 |
commit | d08e0c728f8c2bf2185265b35d8e7b6acfd221f0 (patch) | |
tree | 9a2192427c7a43e43a5e97a1a6ae0afe5f6ef298 | |
parent | ff0f8388138f7b66c4312db0e984f0bedcac2558 (diff) | |
download | podman-d08e0c728f8c2bf2185265b35d8e7b6acfd221f0.tar.gz podman-d08e0c728f8c2bf2185265b35d8e7b6acfd221f0.tar.bz2 podman-d08e0c728f8c2bf2185265b35d8e7b6acfd221f0.zip |
apiv2: Enable filtering images by ID
It is more practical for API usage and also it is more in sync how
filtering of containers works.
Signed-off-by: Matej Marusak <mmarusak@redhat.com>
-rw-r--r-- | libpod/image/filters.go | 9 | ||||
-rw-r--r-- | pkg/api/server/register_images.go | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libpod/image/filters.go b/libpod/image/filters.go index d545f1bfc..de10f9443 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -102,6 +102,13 @@ func ReferenceFilter(ctx context.Context, referenceFilter string) ResultFilter { } } +// IdFilter allows you to filter by image Id +func IdFilter(idFilter string) ResultFilter { + return func(i *Image) bool { + return i.ID() == idFilter + } +} + // OutputImageFilter allows you to filter by an a specific image name func OutputImageFilter(userImage *Image) ResultFilter { return func(i *Image) bool { @@ -165,6 +172,8 @@ func (ir *Runtime) createFilterFuncs(filters []string, img *Image) ([]ResultFilt case "reference": referenceFilter := strings.Join(splitFilter[1:], "=") filterFuncs = append(filterFuncs, ReferenceFilter(ctx, referenceFilter)) + case "id": + filterFuncs = append(filterFuncs, IdFilter(splitFilter[1])) default: return nil, errors.Errorf("invalid filter %s ", splitFilter[0]) } diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go index f082c5fec..cc5be8086 100644 --- a/pkg/api/server/register_images.go +++ b/pkg/api/server/register_images.go @@ -621,6 +621,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // - `dangling=true` // - `label=key` or `label="key=value"` of an image label // - `reference`=(`<image-name>[:<tag>]`) + // - `id`=(`<image-id>`) // - `since`=(`<image-name>[:<tag>]`, `<image id>` or `<image@digest>`) // type: string // produces: |