mirror of
https://github.com/containers/podman.git
synced 2025-05-29 22:46:25 +08:00
Update manifest API endpoints
* 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 <jhonce@redhat.com>
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/containers/image/v5/docker/reference"
|
||||||
"github.com/containers/image/v5/manifest"
|
"github.com/containers/image/v5/manifest"
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v3/libpod"
|
"github.com/containers/podman/v3/libpod"
|
||||||
@ -34,6 +35,16 @@ func ManifestCreate(w http.ResponseWriter, r *http.Request) {
|
|||||||
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||||
return
|
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()
|
rtc, err := runtime.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
@ -75,11 +86,16 @@ func ManifestInspect(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.Error(w, "Something went wrong.", http.StatusNotFound, inspectError)
|
utils.Error(w, "Something went wrong.", http.StatusNotFound, inspectError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var list manifest.Schema2List
|
var list manifest.Schema2List
|
||||||
if err := json.Unmarshal(inspectReport, &list); err != nil {
|
if err := json.Unmarshal(inspectReport, &list); err != nil {
|
||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Unmarshal()"))
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Unmarshal()"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if list.Manifests == nil {
|
||||||
|
list.Manifests = make([]manifest.Schema2ManifestDescriptor, 0)
|
||||||
|
}
|
||||||
|
|
||||||
utils.WriteResponse(w, http.StatusOK, &list)
|
utils.WriteResponse(w, http.StatusOK, &list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,10 +727,13 @@ class TestApi(unittest.TestCase):
|
|||||||
start = json.loads(r.text)
|
start = json.loads(r.text)
|
||||||
self.assertGreater(len(start["Errs"]), 0, 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):
|
def test_df(self):
|
||||||
r = requests.get(_url("/system/df"))
|
r = requests.get(_url("/system/df"))
|
||||||
self.assertEqual(r.status_code, 200, r.text)
|
self.assertEqual(r.status_code, 200, r.text)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user