Skip to content

Commit

Permalink
Update manifest API endpoints
Browse files Browse the repository at this point in the history
* Add validation for manifest name
* Always return an array for manifests even if empty
* Add missing return in df handler when returning error. Caused an
  additional null to be written to client crashing python decoder.

When c/image is refactored to include manifests, manifest endpoints should
be revisited.

Signed-off-by: Jhon Honce <[email protected]>
  • Loading branch information
jwhonce committed Apr 9, 2021
1 parent 54dce00 commit d41c33e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/api/handlers/libpod/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"

"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
Expand Down Expand Up @@ -34,6 +35,16 @@ func ManifestCreate(w http.ResponseWriter, r *http.Request) {
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

// TODO: (jhonce) When c/image is refactored the roadmap calls for this check to be pushed into that library.
for _, n := range query.Name {
if _, err := reference.ParseNormalizedNamed(n); err != nil {
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
errors.Wrapf(err, "invalid image name %s", n))
return
}
}

rtc, err := runtime.GetConfig()
if err != nil {
utils.InternalServerError(w, err)
Expand Down Expand Up @@ -75,11 +86,16 @@ func ManifestInspect(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusNotFound, inspectError)
return
}

var list manifest.Schema2List
if err := json.Unmarshal(inspectReport, &list); err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Unmarshal()"))
return
}
if list.Manifests == nil {
list.Manifests = make([]manifest.Schema2ManifestDescriptor, 0)
}

utils.WriteResponse(w, http.StatusOK, &list)
}

Expand Down
5 changes: 4 additions & 1 deletion test/apiv2/rest_api/test_rest_v2_0_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,13 @@ def test_pod_start_conflict(self):
start = json.loads(r.text)
self.assertGreater(len(start["Errs"]), 0, r.text)

def test_manifest_409(self):
r = requests.post(_url("/manifests/create"), params={"name": "ThisIsAnInvalidImage"})
self.assertEqual(r.status_code, 400, r.text)

def test_df(self):
r = requests.get(_url("/system/df"))
self.assertEqual(r.status_code, 200, r.text)


if __name__ == "__main__":
unittest.main()

0 comments on commit d41c33e

Please sign in to comment.