Module: TrainPlugins::Juniper::WindowsProxy

Included in:
BastionProxy
Defined in:
lib/train-juniper/connection/windows_proxy.rb

Overview

Windows-specific proxy handling using plink.exe This pattern is used by various Ruby projects for Windows SSH support, including hglib.rb (Mercurial) and follows Net::SSH::Proxy::Command patterns

Instance Method Summary collapse

Instance Method Details

Build plink.exe proxy command for Windows bastion authentication

Parameters:

  • bastion_host (String)

    Bastion hostname

  • user (String)

    Username for bastion

  • port (Integer)

    Port for bastion

  • password (String)

    Password for bastion

Returns:

  • (String)

    Complete plink command string



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/train-juniper/connection/windows_proxy.rb', line 27

def build_plink_proxy_command(bastion_host, user, port, password)
  parts = []
  parts << 'plink.exe'
  parts << '-batch' # Non-interactive mode
  parts << '-ssh'   # Force SSH protocol (not telnet)
  parts << '-pw'
  parts << Shellwords.escape(password)

  if port && port != 22
    parts << '-P'
    parts << port.to_s
  end

  parts << "#{user}@#{bastion_host}"
  parts << '-nc'
  parts << '%h:%p' # Netcat mode for proxying

  parts.join(' ')
end

Check if plink.exe is available on Windows

Returns:

  • (Boolean)

    true if plink.exe is found in PATH



13
14
15
16
17
18
19
# File 'lib/train-juniper/connection/windows_proxy.rb', line 13

def plink_available?
  return false unless Gem.win_platform?

  ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
    File.exist?(File.join(path, 'plink.exe'))
  end
end