SSHOpts adds the following options to CommonOptions: User, ControlMaster, ControlPath, ControlPersist.
(ctx context.Context, sshExe SSHExe, instDir, username string, useDotSSH, forwardAgent, forwardX11, forwardX11Trusted bool)
| 334 | |
| 335 | // SSHOpts adds the following options to CommonOptions: User, ControlMaster, ControlPath, ControlPersist. |
| 336 | func SSHOpts(ctx context.Context, sshExe SSHExe, instDir, username string, useDotSSH, forwardAgent, forwardX11, forwardX11Trusted bool) ([]string, error) { |
| 337 | controlSock := filepath.Join(instDir, filenames.SSHSock) |
| 338 | if len(controlSock) >= osutil.UnixPathMax { |
| 339 | return nil, fmt.Errorf("socket path %q is too long: >= UNIX_PATH_MAX=%d", controlSock, osutil.UnixPathMax) |
| 340 | } |
| 341 | opts, err := CommonOpts(ctx, sshExe, useDotSSH) |
| 342 | if err != nil { |
| 343 | return nil, err |
| 344 | } |
| 345 | controlPath := fmt.Sprintf(`ControlPath="%s"`, controlSock) |
| 346 | if runtime.GOOS == "windows" { |
| 347 | controlSock, err = ioutilx.WindowsSubsystemPath(ctx, controlSock) |
| 348 | if err != nil { |
| 349 | return nil, err |
| 350 | } |
| 351 | controlPath = fmt.Sprintf(`ControlPath='%s'`, controlSock) |
| 352 | } |
| 353 | opts = append(opts, |
| 354 | fmt.Sprintf("User=%s", username), // guest and host have the same username, but we should specify the username explicitly (#85) |
| 355 | "ControlMaster=auto", |
| 356 | controlPath, |
| 357 | "ControlPersist=yes", |
| 358 | ) |
| 359 | if forwardAgent { |
| 360 | opts = append(opts, "ForwardAgent=yes") |
| 361 | } |
| 362 | if forwardX11 { |
| 363 | opts = append(opts, "ForwardX11=yes") |
| 364 | } |
| 365 | if forwardX11Trusted { |
| 366 | opts = append(opts, "ForwardX11Trusted=yes") |
| 367 | } |
| 368 | return opts, nil |
| 369 | } |
| 370 | |
| 371 | // SSHArgsFromOpts returns ssh args from opts. |
| 372 | // The result always contains {"-F", "/dev/null} in addition to {"-o", "KEY=VALUE", ...}. |
no test coverage detected