Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Filter query parameter to list images api #6878

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/api/handlers/utils/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) {
All bool
Filters map[string][]string `schema:"filters"`
Digests bool
Filter string // Docker 1.24 compatibility
}{
// This is where you can override the golang default value for one of fields
}
Expand All @@ -76,8 +77,16 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) {
err error
)

if len(query.Filters) > 0 {
for k, v := range query.Filters {
queryFilters := query.Filters
if !IsLibpodRequest(r) && len(query.Filter) > 0 { // Docker 1.24 compatibility
if queryFilters == nil {
queryFilters = make(map[string][]string)
}
queryFilters["reference"] = append(queryFilters["reference"], query.Filter)
}

if len(queryFilters) > 0 {
for k, v := range queryFilters {
filters = append(filters, fmt.Sprintf("%s=%s", k, strings.Join(v, "=")))
}
images, err = runtime.ImageRuntime().GetImagesWithFilters(filters)
Expand Down
8 changes: 8 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ t GET libpod/images/${iid:0:12}/json 200 \
.Id=$iid \
.RepoTags[0]=$IMAGE

# Docker API V1.24 filter parameter compatibility
t GET images/json?filter=$IMAGE 200 \
length=1 \
.[0].Names[0]=$IMAGE

# Negative test case
t GET images/json?filter=nonesuch 200 length=0

# FIXME: docker API incompatibility: libpod returns 'id', docker 'sha256:id'
t GET images/$iid/json 200 \
.Id=sha256:$iid \
Expand Down