aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2020-01-09 14:18:09 -0600
committerbaude <bbaude@redhat.com>2020-01-10 09:41:54 -0600
commit25b34972f4c58ede6528e3ae25c54c29eb9034e1 (patch)
tree6d33eaa070aac89f55da6ef9decf44825d9054b5 /pkg/api/handlers
parentd924494f561bb878a2b3a7ce438d87ecb934b5fb (diff)
downloadpodman-25b34972f4c58ede6528e3ae25c54c29eb9034e1.tar.gz
podman-25b34972f4c58ede6528e3ae25c54c29eb9034e1.tar.bz2
podman-25b34972f4c58ede6528e3ae25c54c29eb9034e1.zip
[CI:DOCS]update apiv2 documentation with swagger goods
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/libpod/pods.go31
-rw-r--r--pkg/api/handlers/libpod/volumes.go32
-rw-r--r--pkg/api/handlers/swagger.go126
-rw-r--r--pkg/api/handlers/utils/errors.go4
4 files changed, 133 insertions, 60 deletions
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index cde1fcd48..daaf9d018 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -137,9 +137,6 @@ func Pods(w http.ResponseWriter, r *http.Request) {
}
func PodInspect(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := mux.Vars(r)["name"]
pod, err := runtime.LookupPod(name)
@@ -222,10 +219,6 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
}
func PodStart(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 304 no modified
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
allContainersRunning := true
name := mux.Vars(r)["name"]
@@ -267,9 +260,6 @@ func PodStart(w http.ResponseWriter, r *http.Request) {
}
func PodDelete(w http.ResponseWriter, r *http.Request) {
- // 200
- // 404 no such
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
decoder = r.Context().Value("decoder").(*schema.Decoder)
@@ -295,13 +285,10 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
return
}
- utils.WriteResponse(w, http.StatusOK, "")
+ utils.WriteResponse(w, http.StatusNoContent, "")
}
func PodRestart(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := mux.Vars(r)["name"]
pod, err := runtime.LookupPod(name)
@@ -318,8 +305,6 @@ func PodRestart(w http.ResponseWriter, r *http.Request) {
}
func PodPrune(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 500 internal
var (
err error
pods []*libpod.Pod
@@ -357,13 +342,10 @@ func PodPrune(w http.ResponseWriter, r *http.Request) {
return
}
}
- utils.WriteResponse(w, http.StatusOK, "")
+ utils.WriteResponse(w, http.StatusNoContent, "")
}
func PodPause(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := mux.Vars(r)["name"]
pod, err := runtime.LookupPod(name)
@@ -376,7 +358,7 @@ func PodPause(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
return
}
- utils.WriteResponse(w, http.StatusOK, "")
+ utils.WriteResponse(w, http.StatusNoContent, "")
}
func PodUnpause(w http.ResponseWriter, r *http.Request) {
@@ -399,10 +381,6 @@ func PodUnpause(w http.ResponseWriter, r *http.Request) {
}
func PodKill(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 409 has conflict
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
decoder = r.Context().Value("decoder").(*schema.Decoder)
@@ -451,9 +429,6 @@ func PodKill(w http.ResponseWriter, r *http.Request) {
}
func PodExists(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal (needs work)
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := mux.Vars(r)["name"]
_, err := runtime.LookupPod(name)
diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go
index ece59a4b6..3e0e597c6 100644
--- a/pkg/api/handlers/libpod/volumes.go
+++ b/pkg/api/handlers/libpod/volumes.go
@@ -63,23 +63,9 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
}
func InspectVolume(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
- decoder = r.Context().Value("decoder").(*schema.Decoder)
)
- query := struct {
- }{
- // override any golang type defaults
- }
-
- 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
- }
name := mux.Vars(r)["name"]
vol, err := runtime.GetVolume(name)
if err != nil {
@@ -115,22 +101,9 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
}
func PruneVolumes(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
- decoder = r.Context().Value("decoder").(*schema.Decoder)
)
- query := struct {
- }{
- // override any golang type defaults
- }
-
- 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
- }
pruned, errs := runtime.PruneVolumes(r.Context())
if errs != nil {
if len(errs) > 1 {
@@ -144,9 +117,6 @@ func PruneVolumes(w http.ResponseWriter, r *http.Request) {
}
func RemoveVolume(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
decoder = r.Context().Value("decoder").(*schema.Decoder)
@@ -170,5 +140,5 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
if err := runtime.RemoveVolume(r.Context(), vol, query.Force); err != nil {
utils.InternalServerError(w, err)
}
- utils.WriteResponse(w, http.StatusOK, "")
+ utils.WriteResponse(w, http.StatusNoContent, "")
}
diff --git a/pkg/api/handlers/swagger.go b/pkg/api/handlers/swagger.go
new file mode 100644
index 000000000..b677a5a0b
--- /dev/null
+++ b/pkg/api/handlers/swagger.go
@@ -0,0 +1,126 @@
+package handlers
+
+import (
+ "github.com/containers/libpod/cmd/podman/shared"
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/pkg/inspect"
+ "github.com/docker/docker/api/types"
+)
+
+// History response
+// swagger:response DocsHistory
+type swagHistory struct {
+ // in:body
+ Body struct {
+ HistoryResponse
+ }
+}
+
+// Inspect response
+// swagger:response DocsImageInspect
+type swagImageInspect struct {
+ // in:body
+ Body struct {
+ ImageInspect
+ }
+}
+
+// Delete response
+// swagger:response DocsImageDeleteResponse
+type swagImageDeleteResponse struct {
+ // in:body
+ Body struct {
+ image.ImageDeleteResponse
+ }
+}
+
+// Search results
+// swagger:response DocsSearchResponse
+type swagSearchResponse struct {
+ // in:body
+ Body struct {
+ image.SearchResult
+ }
+}
+
+// Inspect image
+// swagger:response DocsLibpodInspectImageResponse
+type swagLibpodInspectImageResponse struct {
+ // in:body
+ Body struct {
+ inspect.ImageData
+ }
+}
+
+// Prune containers
+// swagger:response DocsContainerPruneReport
+type swagContainerPruneReport struct {
+ // in: body
+ Body struct {
+ ContainersPruneReport
+ }
+}
+
+// Inspect container
+// swagger:response DocsContainerInspectResponse
+type swagContainerInspectResponse struct {
+ // in:body
+ Body struct {
+ types.ContainerJSON
+ }
+}
+
+// List processes in container
+// swagger:response DockerTopResponse
+type swagDockerTopResponse struct {
+ // in:body
+ Body struct {
+ ContainerTopOKBody
+ }
+}
+
+// List containers
+// swagger:response LibpodListContainersResponse
+type swagLibpodListContainersResponse struct {
+ // in:body
+ Body struct {
+ shared.PsContainerOutput
+ }
+}
+
+// Inspect container
+// swagger:response LibpodInspectContainerResponse
+type swagLibpodInspectContainerResponse struct {
+ // in:body
+ Body struct {
+ libpod.InspectContainerData
+ }
+}
+
+// List pods
+// swagger:response ListPodsResponse
+type swagListPodsResponse struct {
+ // in:body
+ Body struct {
+ libpod.PodInspect
+ }
+}
+
+// Inspect pod
+// swagger:response InspectPodResponse
+type swagInspectPodResponse struct {
+ // in:body
+ Body struct {
+ libpod.PodInspect
+ }
+}
+
+// Inspect volume
+// swagger:response InspectVolumeResponse
+type swagInspectVolumeResponse struct {
+ // in:body
+ Body struct {
+ libpod.InspectVolumeData
+ }
+}
diff --git a/pkg/api/handlers/utils/errors.go b/pkg/api/handlers/utils/errors.go
index 69d4e40f8..3ec0742bd 100644
--- a/pkg/api/handlers/utils/errors.go
+++ b/pkg/api/handlers/utils/errors.go
@@ -2,9 +2,9 @@ package utils
import (
"fmt"
- "github.com/containers/libpod/libpod/define"
"net/http"
+ "github.com/containers/libpod/libpod/define"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
@@ -73,7 +73,9 @@ func BadRequest(w http.ResponseWriter, key string, value string, err error) {
}
type ErrorModel struct {
+ // root cause
Because string `json:"cause"`
+ // error message
Message string `json:"message"`
}