summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/resize.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-05-15 09:33:21 -0700
committerJhon Honce <jhonce@redhat.com>2020-05-18 11:21:06 -0700
commit6287a5585223e5934706d1c1c21d68bfac5b5803 (patch)
tree835ea460df979073ce36050149b105eed7a4a2ae /pkg/api/handlers/compat/resize.go
parentd4587c6074e4b4e3673cf495f0c4cd2811742791 (diff)
downloadpodman-6287a5585223e5934706d1c1c21d68bfac5b5803.tar.gz
podman-6287a5585223e5934706d1c1c21d68bfac5b5803.tar.bz2
podman-6287a5585223e5934706d1c1c21d68bfac5b5803.zip
V2 Implement terminal handling in bindings attach
* Add support for /exec/{id}/resize * Add support for ErrSessionNotFound * Resize container TTY as stdin changes size * Refactor all resize functions into one handler Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat/resize.go')
-rw-r--r--pkg/api/handlers/compat/resize.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/resize.go b/pkg/api/handlers/compat/resize.go
new file mode 100644
index 000000000..3ead733bc
--- /dev/null
+++ b/pkg/api/handlers/compat/resize.go
@@ -0,0 +1,68 @@
+package compat
+
+import (
+ "net/http"
+ "strings"
+
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/gorilla/schema"
+ "github.com/pkg/errors"
+ "k8s.io/client-go/tools/remotecommand"
+)
+
+func ResizeTTY(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+
+ // /containers/{id}/resize
+ query := struct {
+ height uint16 `schema:"h"`
+ width uint16 `schema:"w"`
+ }{
+ // 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
+ }
+
+ sz := remotecommand.TerminalSize{
+ Width: query.width,
+ Height: query.height,
+ }
+
+ var status int
+ name := utils.GetName(r)
+ switch {
+ case strings.Contains(r.URL.Path, "/containers/"):
+ ctnr, err := runtime.LookupContainer(name)
+ if err != nil {
+ utils.ContainerNotFound(w, name, err)
+ return
+ }
+ if err := ctnr.AttachResize(sz); err != nil {
+ utils.InternalServerError(w, errors.Wrapf(err, "cannot resize container"))
+ return
+ }
+ // This is not a 204, even though we write nothing, for compatibility
+ // reasons.
+ status = http.StatusOK
+ case strings.Contains(r.URL.Path, "/exec/"):
+ ctnr, err := runtime.GetExecSessionContainer(name)
+ if err != nil {
+ utils.SessionNotFound(w, name, err)
+ return
+ }
+ if err := ctnr.ExecResize(name, sz); err != nil {
+ utils.InternalServerError(w, errors.Wrapf(err, "cannot resize session"))
+ return
+ }
+ // This is not a 204, even though we write nothing, for compatibility
+ // reasons.
+ status = http.StatusCreated
+ }
+ utils.WriteResponse(w, status, "")
+}