()
| 14 | } |
| 15 | |
| 16 | func (h *Handler) TerminalSessionHandler() iris.Handler { |
| 17 | return func(ctx *context.Context) { |
| 18 | namespace := ctx.URLParam("namespace") |
| 19 | podName := ctx.URLParam("podName") |
| 20 | containerName := ctx.URLParam("containerName") |
| 21 | shell := ctx.URLParam("shell") |
| 22 | |
| 23 | sessionID, err := terminal.GenTerminalSessionId() |
| 24 | if err != nil { |
| 25 | ctx.StatusCode(iris.StatusInternalServerError) |
| 26 | ctx.Values().Set("message", err) |
| 27 | return |
| 28 | } |
| 29 | clusterName := ctx.Params().GetString("name") |
| 30 | u := ctx.Values().Get("profile") |
| 31 | profile := u.(session.UserProfile) |
| 32 | client, conf, _, err := clusteraccess.ClientForUser(clusterName, clusteraccess.User{ |
| 33 | Name: profile.Name, |
| 34 | IsAdministrator: profile.IsAdministrator, |
| 35 | }) |
| 36 | if err != nil { |
| 37 | ctx.StatusCode(iris.StatusInternalServerError) |
| 38 | ctx.Values().Set("message", err) |
| 39 | return |
| 40 | } |
| 41 | if shell == "" { |
| 42 | shell = "sh" |
| 43 | } |
| 44 | terminal.TerminalSessions.Set(sessionID, terminal.TerminalSession{ |
| 45 | Id: sessionID, |
| 46 | Bound: make(chan error), |
| 47 | SizeChan: make(chan remotecommand.TerminalSize), |
| 48 | }) |
| 49 | go terminal.WaitForTerminal(client, conf, namespace, podName, containerName, sessionID, shell) |
| 50 | resp := TerminalResponse{ID: sessionID} |
| 51 | ctx.Values().Set("data", resp) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // node shell |
| 56 | func (h *Handler) NodeTerminalSessionHandler() iris.Handler { |
no test coverage detected