Skip to content

Commit

Permalink
Merge pull request containers#10508 from matejvasek/fix-from-img
Browse files Browse the repository at this point in the history
Better error handing for images/create compat api
  • Loading branch information
openshift-merge-robot committed Jun 1, 2021
2 parents 19cd46c + 3330f98 commit 7a52440
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/common/libimage"
"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/pkg/shortnames"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/api/handlers"
Expand Down Expand Up @@ -234,6 +235,14 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {

fromImage := mergeNameAndTagOrDigest(query.FromImage, query.Tag)

// without this early check this function would return 200 but reported error via body stream soon after
// it's better to let caller know early via HTTP status code that request cannot be processed
_, err := shortnames.Resolve(runtime.SystemContext(), fromImage)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrap(err, "failed to resolve image name"))
return
}

authConf, authfile, key, err := auth.GetCredentials(r)
if err != nil {
utils.Error(w, "failed to retrieve repository credentials", http.StatusBadRequest, errors.Wrapf(err, "failed to parse %q header for %s", key, r.URL.String()))
Expand Down

0 comments on commit 7a52440

Please sign in to comment.