(r *api.SSHBastionResponse, user, host, port string)
| 264 | } |
| 265 | |
| 266 | func proxyBastion(r *api.SSHBastionResponse, user, host, port string) error { |
| 267 | sshPath, err := exec.LookPath("ssh") |
| 268 | if err != nil { |
| 269 | sshPath = sshDefaultPath |
| 270 | } |
| 271 | |
| 272 | args := []string{} |
| 273 | if r.Bastion.User != "" { |
| 274 | args = append(args, "-l", r.Bastion.User) |
| 275 | } |
| 276 | if r.Bastion.Port != "" { |
| 277 | args = append(args, "-p", r.Bastion.Port) |
| 278 | } |
| 279 | if r.Bastion.Flags != "" { |
| 280 | // BUG(mariano): This is a naive way of doing it as it doesn't |
| 281 | // support strings, but it should work for most of the cases in ssh. |
| 282 | // For more advance cases the package |
| 283 | // github.com/kballard/go-shellquote can be used. |
| 284 | fields := strings.Fields(r.Bastion.Flags) |
| 285 | args = append(args, fields...) |
| 286 | } |
| 287 | args = append(args, r.Bastion.Hostname) |
| 288 | if r.Bastion.Command != "" { |
| 289 | args = append(args, sshutil.ProxyCommand(r.Bastion.Command, user, host, port)) |
| 290 | } else { |
| 291 | args = append(args, "nc", host, port) |
| 292 | } |
| 293 | exec.Exec(sshPath, args...) |
| 294 | return nil |
| 295 | } |
no test coverage detected
searching dependent graphs…