Skip to content

Commit

Permalink
Merge pull request #7921 from vrothberg/v2.1-bz-1884668
Browse files Browse the repository at this point in the history
[v2.1] compat: images/create: fix tag parsing
  • Loading branch information
openshift-merge-robot authored Oct 5, 2020
2 parents 3873f30 + ba0e0a5 commit 9b0f5dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ import (
"github.com/containers/podman/v2/pkg/util"
"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
Expand Down Expand Up @@ -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, err := auth.GetCredentials(r)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b0f5dd

Please sign in to comment.