summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/generic/images.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-04 05:11:25 -0800
committerGitHub <noreply@github.com>2020-02-04 05:11:25 -0800
commit28eb296653f78f462c07e3fe6b156bc093ff44c6 (patch)
tree87652e6dab337f25b1b86d9bc94a2e369f860a27 /pkg/api/handlers/generic/images.go
parent05e04b4a6436478e78ff93d33e32db92932bba10 (diff)
parent84381df8105f94814e4f532542df9fda4152cbc4 (diff)
downloadpodman-28eb296653f78f462c07e3fe6b156bc093ff44c6.tar.gz
podman-28eb296653f78f462c07e3fe6b156bc093ff44c6.tar.bz2
podman-28eb296653f78f462c07e3fe6b156bc093ff44c6.zip
Merge pull request #5060 from vrothberg/v2-libpod-image-endpoints
[CI:DOCS] swagger: v2: libpod/images/{import,load,pull}
Diffstat (limited to 'pkg/api/handlers/generic/images.go')
-rw-r--r--pkg/api/handlers/generic/images.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/pkg/api/handlers/generic/images.go b/pkg/api/handlers/generic/images.go
index 20dd84456..c65db7575 100644
--- a/pkg/api/handlers/generic/images.go
+++ b/pkg/api/handlers/generic/images.go
@@ -3,6 +3,7 @@ package generic
import (
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
"net/http"
"os"
@@ -315,3 +316,47 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
}
utils.WriteResponse(w, http.StatusOK, summaries)
}
+
+func LoadImages(w http.ResponseWriter, r *http.Request) {
+ // TODO this is basically wrong
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+
+ query := struct {
+ Changes map[string]string `json:"changes"`
+ Message string `json:"message"`
+ Quiet bool `json:"quiet"`
+ }{
+ // 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
+ }
+
+ var (
+ err error
+ writer io.Writer
+ )
+ f, err := ioutil.TempFile("", "api_load.tar")
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to create tempfile"))
+ return
+ }
+ if err := handlers.SaveFromBody(f, r); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to write temporary file"))
+ return
+ }
+ id, err := runtime.LoadImage(r.Context(), "", f.Name(), writer, "")
+ //id, err := runtime.Import(r.Context())
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to load image"))
+ return
+ }
+ utils.WriteResponse(w, http.StatusOK, struct {
+ Stream string `json:"stream"`
+ }{
+ Stream: fmt.Sprintf("Loaded image: %s\n", id),
+ })
+}