MCPcopy
hub / github.com/1Panel-dev/KubePi / TerminalSessionHandler

Method TerminalSessionHandler

internal/api/v1/cluster/terminal.go:16–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14}
15
16func (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
56func (h *Handler) NodeTerminalSessionHandler() iris.Handler {

Callers 1

InstallFunction · 0.95

Calls 5

GenTerminalSessionIdFunction · 0.92
ClientForUserFunction · 0.92
WaitForTerminalFunction · 0.92
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected