(user, host string, jumphost config.SSHJumpHost)
| 352 | } |
| 353 | |
| 354 | func buildSSHArgsBase(user, host string, jumphost config.SSHJumpHost) []string { |
| 355 | var args []string |
| 356 | target := fmt.Sprintf("%s@%s", user, host) |
| 357 | |
| 358 | if jumphost.Addr != "" { |
| 359 | if jumphost.Keyfile != "" { |
| 360 | proxyCmd := "ssh -W %h:%p" |
| 361 | proxyCmd += fmt.Sprintf(" -i %s", shellQuote(jumphost.Keyfile)) |
| 362 | if jumphost.User != "" { |
| 363 | proxyCmd += fmt.Sprintf(" -l %s", shellQuote(jumphost.User)) |
| 364 | } |
| 365 | if jumphost.Port > 0 { |
| 366 | proxyCmd += fmt.Sprintf(" -p %d", jumphost.Port) |
| 367 | } |
| 368 | proxyCmd += fmt.Sprintf(" %s", shellQuote(jumphost.Addr)) |
| 369 | |
| 370 | args = append(args, "-o", fmt.Sprintf("ProxyCommand=%s", proxyCmd)) |
| 371 | } else { |
| 372 | jumpSpec := jumphost.Addr |
| 373 | if jumphost.User != "" { |
| 374 | jumpSpec = fmt.Sprintf("%s@%s", jumphost.User, jumphost.Addr) |
| 375 | } |
| 376 | if jumphost.Port > 0 { |
| 377 | jumpSpec = fmt.Sprintf("%s:%d", jumpSpec, jumphost.Port) |
| 378 | } |
| 379 | args = append(args, "-J", jumpSpec) |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | args = append(args, target) |
| 384 | return args |
| 385 | } |
| 386 | |
| 387 | func shellQuote(s string) string { |
| 388 | return "'" + strings.ReplaceAll(s, "'", "'\\''") + "'" |
no test coverage detected