MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/application/ssh.go:106–174  ·  view source on GitHub ↗
(fc flags.FlagContext)

Source from the content-addressed store, hash-verified

104}
105
106func (cmd *SSH) Execute(fc flags.FlagContext) error {
107 if fc.IsSet("i") {
108 instanceIndex := fc.Int("i")
109 if instanceIndex < 0 {
110 return errors.New(T("The application instance index cannot be negative"))
111 }
112 if instanceIndex >= cmd.appReq.GetApplication().InstanceCount {
113 return errors.New(T("The specified application instance does not exist"))
114 }
115 }
116
117 app := cmd.appReq.GetApplication()
118 info, err := cmd.getSSHEndpointInfo()
119 if err != nil {
120 return errors.New(T("Error getting SSH info:") + err.Error())
121 }
122
123 sshAuthCode, err := cmd.sshCodeGetter.Get()
124 if err != nil {
125 return errors.New(T("Error getting one time auth code: ") + err.Error())
126 }
127
128 // init secureShell if it is not already set by SetDependency() with fakes
129 if cmd.secureShell == nil {
130 cmd.secureShell = sshCmd.NewSecureShell(
131 sshCmd.DefaultSecureDialer(),
132 sshTerminal.DefaultHelper(),
133 sshCmd.DefaultListenerFactory(),
134 30*time.Second,
135 app,
136 info.SSHEndpointFingerprint,
137 info.SSHEndpoint,
138 sshAuthCode,
139 )
140 }
141
142 err = cmd.secureShell.Connect(cmd.opts)
143 if err != nil {
144 return errors.New(T("Error opening SSH connection: ") + err.Error())
145 }
146 defer cmd.secureShell.Close()
147
148 err = cmd.secureShell.LocalPortForward()
149 if err != nil {
150 return errors.New(T("Error forwarding port: ") + err.Error())
151 }
152
153 if cmd.opts.SkipRemoteExecution {
154 err = cmd.secureShell.Wait()
155 } else {
156 err = cmd.secureShell.InteractiveSession()
157 }
158
159 if err != nil {
160 if exitError, ok := err.(*ssh.ExitError); ok {
161 exitStatus := exitError.ExitStatus()
162 if sig := exitError.Signal(); sig != "" {
163 cmd.ui.Say(T("Process terminated by signal: {{.Signal}}. Exited with {{.ExitCode}}", map[string]interface{}{

Callers

nothing calls this directly

Calls 13

getSSHEndpointInfoMethod · 0.95
IsSetMethod · 0.65
IntMethod · 0.65
GetApplicationMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.65
ConnectMethod · 0.65
CloseMethod · 0.65
LocalPortForwardMethod · 0.65
WaitMethod · 0.65
InteractiveSessionMethod · 0.65
SayMethod · 0.65

Tested by

no test coverage detected