MCPcopy
hub / github.com/cloudfoundry/cli / InteractiveSession

Method InteractiveSession

util/clissh/ssh.go:108–208  ·  view source on GitHub ↗
(commands []string, terminalRequest TTYRequest)

Source from the content-addressed store, hash-verified

106}
107
108func (c *SecureShell) InteractiveSession(commands []string, terminalRequest TTYRequest) error {
109 session, err := c.secureClient.NewSession()
110 if err != nil {
111 return fmt.Errorf("SSH session allocation failed: %s", err.Error())
112 }
113 defer session.Close()
114
115 stdin, stdout, stderr := c.terminalHelper.StdStreams()
116
117 inPipe, err := session.StdinPipe()
118 if err != nil {
119 return err
120 }
121
122 outPipe, err := session.StdoutPipe()
123 if err != nil {
124 return err
125 }
126
127 errPipe, err := session.StderrPipe()
128 if err != nil {
129 return err
130 }
131
132 stdinFd, stdinIsTerminal := c.terminalHelper.GetFdInfo(stdin)
133 stdoutFd, stdoutIsTerminal := c.terminalHelper.GetFdInfo(stdout)
134
135 if c.shouldAllocateTerminal(commands, terminalRequest, stdinIsTerminal) {
136 modes := ssh.TerminalModes{
137 ssh.ECHO: 1,
138 ssh.TTY_OP_ISPEED: 115200,
139 ssh.TTY_OP_OSPEED: 115200,
140 }
141
142 width, height := c.getWindowDimensions(stdoutFd)
143
144 err = session.RequestPty(c.terminalType(), height, width, modes)
145 if err != nil {
146 return err
147 }
148
149 var state *term.State
150 state, err = c.terminalHelper.SetRawTerminal(stdinFd)
151 if err == nil {
152 defer func() {
153 err := c.terminalHelper.RestoreTerminal(stdinFd, state)
154 log.Errorln("restore terminal", err)
155 }()
156 }
157 }
158
159 if len(commands) > 0 {
160 cmd := strings.Join(commands, " ")
161 err = session.Start(cmd)
162 if err != nil {
163 return err
164 }
165 } else {

Callers

nothing calls this directly

Implementers 4

secureShellcf/ssh/ssh.go
FakeSecureShellcf/ssh/sshfakes/fake_secure_shell.go
FakeSecureShellClientactor/sharedaction/sharedactionfakes/f
SecureShellutil/clissh/ssh.go

Calls 15

getWindowDimensionsMethod · 0.95
terminalTypeMethod · 0.95
resizeMethod · 0.95
SIGWINCHFunction · 0.92
copyAndCloseFunction · 0.70
copyAndDoneFunction · 0.70
keepaliveFunction · 0.70
NewSessionMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
StdStreamsMethod · 0.65

Tested by

no test coverage detected