diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-01-15 20:39:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 20:39:16 +0100 |
commit | 3c9e41bb5393e0a857d8755bb50345544cc31b50 (patch) | |
tree | 9f2af691f56081271e7fff6971ddd7e5fe45271a /pkg/api/handlers/compat | |
parent | fff9e8755c298bfe2b3b0c33c4b96ffd43a1eab6 (diff) | |
parent | 14940a067d007af445560a0a7eb414f6547a7cd4 (diff) | |
download | podman-3c9e41bb5393e0a857d8755bb50345544cc31b50.tar.gz podman-3c9e41bb5393e0a857d8755bb50345544cc31b50.tar.bz2 podman-3c9e41bb5393e0a857d8755bb50345544cc31b50.zip |
Merge pull request #12572 from rhatdan/image
Remove two GetImages functions from API
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r-- | pkg/api/handlers/compat/images.go | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index c1cc99da4..f08a7ee41 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -11,6 +11,7 @@ import ( "github.com/containers/buildah" "github.com/containers/common/libimage" "github.com/containers/common/pkg/config" + "github.com/containers/common/pkg/filters" "github.com/containers/image/v5/manifest" "github.com/containers/image/v5/types" "github.com/containers/podman/v3/libpod" @@ -404,25 +405,52 @@ func GetImage(w http.ResponseWriter, r *http.Request) { } func GetImages(w http.ResponseWriter, r *http.Request) { - images, err := utils.GetImages(w, r) - if err != nil { - utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images")) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) + query := struct { + All bool + Digests bool + Filter string // Docker 1.24 compatibility + }{ + // This is where you can override the golang default value for one of fields + } + + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, + errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) + return + } + if _, found := r.URL.Query()["digests"]; found && query.Digests { + utils.UnSupportedParameter("digests") return } - summaries := make([]*entities.ImageSummary, 0, len(images)) - for _, img := range images { - // If the image is a manifest list, extract as much as we can. - if isML, _ := img.IsManifestList(r.Context()); isML { - continue + filterList, err := filters.FiltersFromRequest(r) + if err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) + return + } + if !utils.IsLibpodRequest(r) { + if len(query.Filter) > 0 { // Docker 1.24 compatibility + filterList = append(filterList, "reference="+query.Filter) } + filterList = append(filterList, "manifest=false") + } - is, err := handlers.ImageToImageSummary(img) - if err != nil { - utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed transform image summaries")) - return + imageEngine := abi.ImageEngine{Libpod: runtime} + + listOptions := entities.ImageListOptions{All: query.All, Filter: filterList} + summaries, err := imageEngine.List(r.Context(), listOptions) + if err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) + return + } + + if !utils.IsLibpodRequest(r) { + // docker adds sha256: in front of the ID + for _, s := range summaries { + s.ID = "sha256:" + s.ID } - summaries = append(summaries, is) } utils.WriteResponse(w, http.StatusOK, summaries) } |