summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-02 14:52:38 -0400
committerGitHub <noreply@github.com>2020-10-02 14:52:38 -0400
commitd4e97b35c2fa9e27b78c14e9ce7f3272d7db7cbf (patch)
treed7be7239f186a6c9f3c5f026f5c306166ce5ae11
parentf1cdead33d8f9c29348f9a66ba4a6aa5ed0aa7b2 (diff)
parent6a291942c253fcb13fc2ee0990f2137ca3584270 (diff)
downloadpodman-d4e97b35c2fa9e27b78c14e9ce7f3272d7db7cbf.tar.gz
podman-d4e97b35c2fa9e27b78c14e9ce7f3272d7db7cbf.tar.bz2
podman-d4e97b35c2fa9e27b78c14e9ce7f3272d7db7cbf.zip
Merge pull request #7901 from vrothberg/fix-compat-images-create
compat: images/create: fix tag parsing
-rw-r--r--pkg/api/handlers/compat/images.go21
-rw-r--r--test/apiv2/10-images.at6
2 files changed, 22 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index 940b57343..cc67ebcd1 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -20,9 +20,25 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/docker/docker/api/types"
"github.com/gorilla/schema"
+ "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
)
+// mergeNameAndTagOrDigest creates an image reference as string from the
+// provided image name and tagOrDigest which can be a tag, a digest or empty.
+func mergeNameAndTagOrDigest(name, tagOrDigest string) string {
+ if len(tagOrDigest) == 0 {
+ return name
+ }
+
+ separator := ":" // default to tag
+ if _, err := digest.Parse(tagOrDigest); err == nil {
+ // We have a digest, so let's change the separator.
+ separator = "@"
+ }
+ return fmt.Sprintf("%s%s%s", name, separator, tagOrDigest)
+}
+
func ExportImage(w http.ResponseWriter, r *http.Request) {
// 200 ok
// 500 server
@@ -252,10 +268,7 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
return
}
- fromImage := query.FromImage
- if len(query.Tag) >= 1 {
- fromImage = fmt.Sprintf("%s:%s", fromImage, query.Tag)
- }
+ fromImage := mergeNameAndTagOrDigest(query.FromImage, query.Tag)
authConf, authfile, key, err := auth.GetCredentials(r)
if err != nil {
diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at
index a204df65c..bdc298ae3 100644
--- a/test/apiv2/10-images.at
+++ b/test/apiv2/10-images.at
@@ -39,7 +39,11 @@ t GET images/$iid/json 200 \
.Id=sha256:$iid \
.RepoTags[0]=$IMAGE
-#t POST images/create fromImage=alpine 201 foo
+t POST "images/create?fromImage=alpine" '' 200
+
+t POST "images/create?fromImage=alpine&tag=latest" '' 200
+
+t POST "images/create?fromImage=docker.io/library/alpine&tag=sha256:acd3ca9941a85e8ed16515bfc5328e4e2f8c128caa72959a58a127b7801ee01f" '' 200
# Display the image history
t GET libpod/images/nonesuch/history 404