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

Method NodeTerminalSessionHandler

internal/api/v1/cluster/terminal.go:56–92  ·  view source on GitHub ↗

node shell

()

Source from the content-addressed store, hash-verified

54
55// node shell
56func (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}

Callers 1

InstallFunction · 0.95

Calls 5

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

Tested by

no test coverage detected