MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / buildSSHArgsBase

Function buildSSHArgsBase

internal/ssh/client.go:354–385  ·  view source on GitHub ↗
(user, host string, jumphost config.SSHJumpHost)

Source from the content-addressed store, hash-verified

352}
353
354func 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
387func shellQuote(s string) string {
388 return "'" + strings.ReplaceAll(s, "'", "'\\''") + "'"

Callers 3

ExecuteLXCShellWithFunction · 0.85
buildSSHArgsFunction · 0.85
BuildSSHArgsFunction · 0.85

Calls 1

shellQuoteFunction · 0.85

Tested by

no test coverage detected