summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-02-05 14:30:25 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-02-10 13:18:48 +0100
commit926c9f8fbbff6332be4ba97d96ba95a9f09b7f65 (patch)
treee0b53150d01e06d19f880854e63411e256d996e5 /pkg/api/handlers
parent76e2a0c5d3365205cb104280d41015d6ab25cd9a (diff)
downloadpodman-926c9f8fbbff6332be4ba97d96ba95a9f09b7f65.tar.gz
podman-926c9f8fbbff6332be4ba97d96ba95a9f09b7f65.tar.bz2
podman-926c9f8fbbff6332be4ba97d96ba95a9f09b7f65.zip
v2 api: /libpod/images/load
Implement the /libpod/images/load endpoint. Tested manually with curl: curl -X POST --data-binary "@image.tar" --header "Content-Type: application/x-tar" Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/libpod/images.go38
-rw-r--r--pkg/api/handlers/types.go3
2 files changed, 37 insertions, 4 deletions
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index fffcad8ed..668daa377 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -3,6 +3,7 @@ package libpod
import (
"context"
"fmt"
+ "io"
"io/ioutil"
"net/http"
"os"
@@ -183,8 +184,41 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
}
func ImagesLoad(w http.ResponseWriter, r *http.Request) {
- //TODO ...
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.New("/libpod/images/load is not yet implemented"))
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ Reference string `schema:"reference"`
+ }{
+ // Add defaults here once needed.
+ }
+
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
+ errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+
+ tmpfile, err := ioutil.TempFile("", "libpod-images-load.tar")
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ return
+ }
+ defer os.Remove(tmpfile.Name())
+ defer tmpfile.Close()
+
+ if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to write archive to temporary file"))
+ return
+ }
+
+ tmpfile.Close()
+ loadedImage, err := runtime.LoadImage(context.Background(), query.Reference, tmpfile.Name(), os.Stderr, "")
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to load image"))
+ return
+ }
+
+ utils.WriteResponse(w, http.StatusOK, []handlers.LibpodImagesLoadReport{{ID: loadedImage}})
}
func ImagesImport(w http.ResponseWriter, r *http.Request) {
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index c19397e60..0a06e080f 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -34,8 +34,7 @@ type ContainerConfig struct {
}
type LibpodImagesLoadReport struct {
- ID string `json:"id"`
- RepoTags []string `json:"repoTags"`
+ ID string `json:"id"`
}
type LibpodImagesImportReport struct {