diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-02-04 05:11:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-04 05:11:25 -0800 |
commit | 28eb296653f78f462c07e3fe6b156bc093ff44c6 (patch) | |
tree | 87652e6dab337f25b1b86d9bc94a2e369f860a27 | |
parent | 05e04b4a6436478e78ff93d33e32db92932bba10 (diff) | |
parent | 84381df8105f94814e4f532542df9fda4152cbc4 (diff) | |
download | podman-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}
-rw-r--r-- | pkg/api/handlers/generic/images.go | 45 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/images.go | 52 | ||||
-rw-r--r-- | pkg/api/handlers/swagger.go | 21 | ||||
-rw-r--r-- | pkg/api/handlers/types.go | 15 | ||||
-rw-r--r-- | pkg/api/server/register_images.go | 77 |
5 files changed, 159 insertions, 51 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), + }) +} diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 202ed5eaa..6c926c45b 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -2,7 +2,6 @@ package libpod import ( "fmt" - "io" "io/ioutil" "net/http" "os" @@ -176,46 +175,17 @@ func ExportImage(w http.ResponseWriter, r *http.Request) { utils.WriteResponse(w, http.StatusOK, rdr) } -func ImportImage(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 - } +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")) +} - 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 - } +func ImagesImport(w http.ResponseWriter, r *http.Request) { + //TODO ... + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.New("/libpod/images/import is not yet implemented")) +} - 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), - }) +func ImagesPull(w http.ResponseWriter, r *http.Request) { + //TODO ... + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.New("/libpod/images/pull is not yet implemented")) } diff --git a/pkg/api/handlers/swagger.go b/pkg/api/handlers/swagger.go index faae98798..bc75777aa 100644 --- a/pkg/api/handlers/swagger.go +++ b/pkg/api/handlers/swagger.go @@ -26,6 +26,27 @@ type swagImageInspect struct { } } +// Load response +// swagger:response DocsLibpodImagesLoadResponse +type swagLibpodImagesLoadResponse struct { + // in:body + Body []LibpodImagesLoadReport +} + +// Import response +// swagger:response DocsLibpodImagesImportResponse +type swagLibpodImagesImportResponse struct { + // in:body + Body LibpodImagesImportReport +} + +// Pull response +// swagger:response DocsLibpodImagesPullResponse +type swagLibpodImagesPullResponse struct { + // in:body + Body LibpodImagesPullReport +} + // Delete response // swagger:response DocsImageDeleteResponse type swagImageDeleteResponse struct { diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go index 34b428852..6169adb18 100644 --- a/pkg/api/handlers/types.go +++ b/pkg/api/handlers/types.go @@ -49,6 +49,21 @@ type LibpodContainersPruneReport struct { PruneError string `json:"error"` } +type LibpodImagesLoadReport struct { + ID string `json:"id"` + RepoTags []string `json:"repoTags"` +} + +type LibpodImagesImportReport struct { + ID string `json:"id"` + RepoTags []string `json:"repoTags"` +} + +type LibpodImagesPullReport struct { + ID string `json:"id"` + RepoTags []string `json:"repoTags"` +} + type Info struct { docker.Info BuildahVersion string diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go index 18a90dc3d..2959e604a 100644 --- a/pkg/api/server/register_images.go +++ b/pkg/api/server/register_images.go @@ -107,7 +107,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // description: no error // 500: // $ref: '#/responses/InternalError' - r.Handle(VersionedPath("/images/load"), APIHandler(s.Context, libpod.ImportImage)).Methods(http.MethodPost) + r.Handle(VersionedPath("/images/load"), APIHandler(s.Context, generic.LoadImages)).Methods(http.MethodPost) // swagger:operation POST /images/prune compat pruneImages // --- // tags: @@ -631,18 +631,14 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // 500: // $ref: '#/responses/InternalError' r.Handle(VersionedPath("/libpod/images/json"), APIHandler(s.Context, libpod.GetImages)).Methods(http.MethodGet) - // swagger:operation POST /libpod/images/load libpod libpodImportImage + // swagger:operation POST /libpod/images/load libpod libpodImagesLoad // --- // tags: // - images - // summary: Import image - // description: Load a set of images and tags into a repository. + // summary: Load image + // description: Load an image (oci-archive or docker-archive) stream. // parameters: // - in: query - // name: quiet - // type: boolean - // description: not supported - // - in: query // name: change // description: "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR. JSON encoded string" // type: string @@ -660,10 +656,71 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error { // - application/json // responses: // 200: - // description: no error + // $ref: "#/response/LibpodImagesLoadResponse" + // 500: + // $ref: '#/responses/InternalError' + r.Handle(VersionedPath("/libpod/images/load"), APIHandler(s.Context, libpod.ImagesLoad)).Methods(http.MethodPost) + // swagger:operation POST /libpod/images/import libpod libpodImagesImport + // --- + // tags: + // - images + // summary: Import image + // description: Import a previosly exported tarball as an image. + // parameters: + // - in: query + // name: change + // description: "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR. JSON encoded string" + // type: string + // - in: query + // name: message + // description: Set commit message for imported image + // type: string + // - in: query + // name: url + // description: Specify a URL instead of a tarball + // type: bool + // - in: body + // name: request + // description: Tarball of (or URL to) container image + // required: true + // schema: + // type: string + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/response/LibpodImagesImportResponse" + // 500: + // $ref: '#/responses/InternalError' + r.Handle(VersionedPath("/libpod/images/import"), APIHandler(s.Context, libpod.ImagesImport)).Methods(http.MethodPost) + // swagger:operation GET /libpod/images/pull libpod libpodImagesPull + // --- + // tags: + // - images + // summary: Import image + // description: Import a previosly exported image as a tarball. + // parameters: + // - in: query + // name: reference + // description: Mandatory reference to the image (e.g., quay.io/image/name:tag)/ + // type: string + // - in: query + // name: credentials + // description: username:password for the registry. + // type: string + // - in: query + // name: tls-verify + // description: Require TLS verification. + // type: bool + // default: true + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/response/LibpodImagesPullResponse" // 500: // $ref: '#/responses/InternalError' - r.Handle(VersionedPath("/libpod/images/load"), APIHandler(s.Context, libpod.ImportImage)).Methods(http.MethodPost) + r.Handle(VersionedPath("/libpod/images/pull"), APIHandler(s.Context, libpod.ImagesPull)).Methods(http.MethodPost) // swagger:operation POST /libpod/images/prune libpod libpodPruneImages // --- // tags: |