MCPcopy
hub / github.com/smallstep/cli / proxyBastion

Function proxyBastion

command/ssh/proxycommand.go:266–295  ·  view source on GitHub ↗
(r *api.SSHBastionResponse, user, host, port string)

Source from the content-addressed store, hash-verified

264}
265
266func 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}

Callers 1

proxycommandActionFunction · 0.85

Calls 3

LookPathFunction · 0.92
ProxyCommandFunction · 0.92
ExecFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…