node shell
()
| 54 | |
| 55 | // node shell |
| 56 | func (h *Handler) NodeTerminalSessionHandler() iris.Handler { |
| 57 | return func(ctx *context.Context) { |
| 58 | nodeName := ctx.URLParam("nodeName") |
| 59 | |
| 60 | sessionID, err := terminal.GenTerminalSessionId() |
| 61 | if err != nil { |
| 62 | ctx.StatusCode(iris.StatusInternalServerError) |
| 63 | ctx.Values().Set("message", err) |
| 64 | return |
| 65 | } |
| 66 | clusterName := ctx.Params().GetString("name") |
| 67 | u := ctx.Values().Get("profile") |
| 68 | profile := u.(session.UserProfile) |
| 69 | if !profile.IsAdministrator { |
| 70 | ctx.StatusCode(iris.StatusForbidden) |
| 71 | ctx.Values().Set("message", "only administrator can open node terminal") |
| 72 | return |
| 73 | } |
| 74 | client, conf, _, err := clusteraccess.ClientForUser(clusterName, clusteraccess.User{ |
| 75 | Name: profile.Name, |
| 76 | IsAdministrator: true, |
| 77 | }) |
| 78 | if err != nil { |
| 79 | ctx.StatusCode(iris.StatusInternalServerError) |
| 80 | ctx.Values().Set("message", err) |
| 81 | return |
| 82 | } |
| 83 | terminal.TerminalSessions.Set(sessionID, terminal.TerminalSession{ |
| 84 | Id: sessionID, |
| 85 | Bound: make(chan error), |
| 86 | SizeChan: make(chan remotecommand.TerminalSize), |
| 87 | }) |
| 88 | go terminal.WaitForNodeShellTerminal(client, conf, nodeName, sessionID) |
| 89 | resp := TerminalResponse{ID: sessionID} |
| 90 | ctx.Values().Set("data", resp) |
| 91 | } |
| 92 | } |
no test coverage detected