summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2020-04-15 16:46:58 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-05-14 16:56:01 -0400
commitcf1f13af986b1e81bc17f58aae428610c14afc4f (patch)
tree1c8469ae883c24355813808fe5a85c71778bf501 /pkg/api/handlers/compat
parent4d410b7cb7191c2fdc4ff975136390b0a172a371 (diff)
downloadpodman-cf1f13af986b1e81bc17f58aae428610c14afc4f.tar.gz
podman-cf1f13af986b1e81bc17f58aae428610c14afc4f.tar.bz2
podman-cf1f13af986b1e81bc17f58aae428610c14afc4f.zip
Add APIv2 handler for resizing exec sessions
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/exec.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/exec.go b/pkg/api/handlers/compat/exec.go
index 897f4e6bd..df4950947 100644
--- a/pkg/api/handlers/compat/exec.go
+++ b/pkg/api/handlers/compat/exec.go
@@ -14,6 +14,7 @@ import (
"github.com/gorilla/schema"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
+ "k8s.io/client-go/tools/remotecommand"
)
// ExecCreateHandler creates an exec session for a given container.
@@ -107,6 +108,45 @@ func ExecInspectHandler(w http.ResponseWriter, r *http.Request) {
utils.WriteResponse(w, http.StatusOK, inspectOut)
}
+// ExecResizeHandler resizes a given exec session's TTY.
+func ExecResizeHandler(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+
+ sessionID := mux.Vars(r)["id"]
+
+ 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
+ }
+
+ sessionCtr, err := runtime.GetExecSessionContainer(sessionID)
+ if err != nil {
+ utils.Error(w, fmt.Sprintf("No such exec session: %s", sessionID), http.StatusNotFound, err)
+ return
+ }
+
+ newSize := remotecommand.TerminalSize{
+ Width: query.Width,
+ Height: query.Height,
+ }
+
+ if err := sessionCtr.ExecResize(sessionID, newSize); err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
+
+ // This is a 201 some reason, not a 204.
+ utils.WriteResponse(w, http.StatusCreated, "")
+}
+
// ExecStartHandler runs a given exec session.
func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)