diff options
author | baude <bbaude@redhat.com> | 2020-12-14 08:52:00 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-12-15 16:04:59 -0600 |
commit | 8d4e19634cf73f257ca7f5d2c9506183f6a5b183 (patch) | |
tree | b2687888a89a443a4c85b191d42cd4d1a8049c8c /pkg/api/handlers | |
parent | 0fd31e29948631c264df21a128b3de2700f7f007 (diff) | |
download | podman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.tar.gz podman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.tar.bz2 podman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.zip |
Podman image bindings for 3.0
Begin the migration of the image bindings for podman 3.0. this includes
the use of options for each binding. build was intentionally not
converted as I believe it needs more discussion before migration.
specifically, the build options themselves.
also noteworthly is that the remove image and remove images bindings
were merged into one. the remove images (or batch remove) has one
downside in that the errors return no longer adhere to http return
codes. this should be discussed and reimplemented in subsequent code.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r-- | pkg/api/handlers/libpod/images.go | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 505c96126..814d0fd69 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -265,8 +265,14 @@ func ExportImages(w http.ResponseWriter, r *http.Request) { // Format is mandatory! Currently, we only support multi-image docker // archives. + if len(query.References) > 1 && query.Format != define.V2s2Archive { + utils.Error(w, "unsupported format", http.StatusInternalServerError, errors.Errorf("multi-image archives must use format of %s", define.V2s2Archive)) + return + + } + switch query.Format { - case define.V2s2Archive: + case define.V2s2Archive, define.OCIArchive: tmpfile, err := ioutil.TempFile("", "api.tar") if err != nil { utils.Error(w, "unable to create tmpfile", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile")) @@ -277,6 +283,13 @@ func ExportImages(w http.ResponseWriter, r *http.Request) { utils.Error(w, "unable to close tmpfile", http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile")) return } + case define.OCIManifestDir, define.V2s2ManifestDir: + tmpdir, err := ioutil.TempDir("", "save") + if err != nil { + utils.Error(w, "unable to create tmpdir", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempdir")) + return + } + output = tmpdir default: utils.Error(w, "unsupported format", http.StatusInternalServerError, errors.Errorf("unsupported format %q", query.Format)) return @@ -287,7 +300,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) { opts := entities.ImageSaveOptions{ Compress: query.Compress, Format: query.Format, - MultiImageArchive: true, + MultiImageArchive: len(query.References) > 1, Output: output, RemoveSignatures: true, } @@ -414,7 +427,6 @@ func PushImage(w http.ResponseWriter, r *http.Request) { }{ // This is where you can override the golang default value for one of fields } - if err := decoder.Decode(&query, r.URL.Query()); err != nil { utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) return @@ -607,12 +619,12 @@ func UntagImage(w http.ResponseWriter, r *http.Request) { func SearchImages(w http.ResponseWriter, r *http.Request) { decoder := r.Context().Value("decoder").(*schema.Decoder) query := struct { - Term string `json:"term"` - Limit int `json:"limit"` - NoTrunc bool `json:"noTrunc"` - Filters []string `json:"filters"` - TLSVerify bool `json:"tlsVerify"` - ListTags bool `json:"listTags"` + Term string `json:"term"` + Limit int `json:"limit"` + NoTrunc bool `json:"noTrunc"` + Filters map[string][]string `json:"filters"` + TLSVerify bool `json:"tlsVerify"` + ListTags bool `json:"listTags"` }{ // This is where you can override the golang default value for one of fields } @@ -622,24 +634,44 @@ func SearchImages(w http.ResponseWriter, r *http.Request) { return } + filter := image.SearchFilter{} + if len(query.Filters) > 0 { + if len(query.Filters["stars"]) > 0 { + stars, err := strconv.Atoi(query.Filters["stars"][0]) + if err != nil { + utils.InternalServerError(w, err) + return + } + filter.Stars = stars + } + if len(query.Filters["is-official"]) > 0 { + isOfficial, err := strconv.ParseBool(query.Filters["is-official"][0]) + if err != nil { + utils.InternalServerError(w, err) + return + } + filter.IsOfficial = types.NewOptionalBool(isOfficial) + } + if len(query.Filters["is-automated"]) > 0 { + isAutomated, err := strconv.ParseBool(query.Filters["is-automated"][0]) + if err != nil { + utils.InternalServerError(w, err) + return + } + filter.IsAutomated = types.NewOptionalBool(isAutomated) + } + } options := image.SearchOptions{ Limit: query.Limit, NoTrunc: query.NoTrunc, ListTags: query.ListTags, + Filter: filter, } + if _, found := r.URL.Query()["tlsVerify"]; found { options.InsecureSkipTLSVerify = types.NewOptionalBool(!query.TLSVerify) } - if _, found := r.URL.Query()["filters"]; found { - filter, err := image.ParseSearchFilter(query.Filters) - if err != nil { - utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse filters parameter for %s", r.URL.String())) - return - } - options.Filter = *filter - } - _, 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())) @@ -678,10 +710,7 @@ func ImagesBatchRemove(w http.ResponseWriter, r *http.Request) { All bool `schema:"all"` Force bool `schema:"force"` Images []string `schema:"images"` - }{ - All: false, - Force: false, - } + }{} if err := decoder.Decode(&query, r.URL.Query()); err != nil { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, @@ -690,10 +719,8 @@ func ImagesBatchRemove(w http.ResponseWriter, r *http.Request) { } opts := entities.ImageRemoveOptions{All: query.All, Force: query.Force} - imageEngine := abi.ImageEngine{Libpod: runtime} rmReport, rmErrors := imageEngine.Remove(r.Context(), query.Images, opts) - strErrs := errorhandling.ErrorsToStrings(rmErrors) report := handlers.LibpodImagesRemoveReport{ImageRemoveReport: *rmReport, Errors: strErrs} utils.WriteResponse(w, http.StatusOK, report) |