diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-31 21:12:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 21:12:49 +0200 |
commit | 6e8f6cab602b43d05c97c167faa56b3f46f1f73a (patch) | |
tree | c4b4f2ab7e91e4f49d2fe5a9b9d89be455bdd219 /pkg/api/handlers/libpod/images.go | |
parent | 56ab9e4cc8a33bb8a791a799753a11c33809dedf (diff) | |
parent | 3bdad6fa2af41be7e783256f3c8a213dc42ca8f6 (diff) | |
download | podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.tar.gz podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.tar.bz2 podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.zip |
Merge pull request #5675 from vrothberg/v2-pull
podmanV2: implement pull
Diffstat (limited to 'pkg/api/handlers/libpod/images.go')
-rw-r--r-- | pkg/api/handlers/libpod/images.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 4b24d7d9f..bb54450da 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -303,6 +303,10 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) { utils.WriteResponse(w, http.StatusOK, handlers.LibpodImagesImportReport{ID: importedImage}) } +// ImagesPull is the v2 libpod endpoint for pulling images. Note that the +// mandatory `reference` must be a reference to a registry (i.e., of docker +// transport or be normalized to one). Other transports are rejected as they +// do not make sense in a remote context. func ImagesPull(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) decoder := r.Context().Value("decoder").(*schema.Decoder) @@ -328,10 +332,11 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) { return } // Enforce the docker transport. This is just a precaution as some callers - // might accustomed to using the "transport:reference" notation. Using + // might be accustomed to using the "transport:reference" notation. Using // another than the "docker://" transport does not really make sense for a // remote case. For loading tarballs, the load and import endpoints should // be used. + dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name()) imageRef, err := alltransports.ParseImageName(query.Reference) if err == nil && imageRef.Transport().Name() != docker.Transport.Name() { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, @@ -339,7 +344,7 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) { return } else if err != nil { origErr := err - imageRef, err = alltransports.ParseImageName(fmt.Sprintf("%s://%s", docker.Transport.Name(), query.Reference)) + imageRef, err = alltransports.ParseImageName(fmt.Sprintf("%s%s", dockerPrefix, query.Reference)) if err != nil { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, errors.Wrapf(origErr, "reference %q must be a docker reference", query.Reference)) @@ -347,16 +352,19 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) { } } + // Trim the docker-transport prefix. + rawImage := strings.TrimPrefix(query.Reference, dockerPrefix) + // all-tags doesn't work with a tagged reference, so let's check early - namedRef, err := reference.Parse(query.Reference) + namedRef, err := reference.Parse(rawImage) if err != nil { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, - errors.Wrapf(err, "error parsing reference %q", query.Reference)) + errors.Wrapf(err, "error parsing reference %q", rawImage)) return } if _, isTagged := namedRef.(reference.Tagged); isTagged && query.AllTags { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, - errors.Errorf("reference %q must not have a tag for all-tags", query.Reference)) + errors.Errorf("reference %q must not have a tag for all-tags", rawImage)) return } |