Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add none support to ProxyJump #893

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/net/ssh/config.rb
Expand Up @@ -154,7 +154,10 @@ def load(path, host, settings = {}, base_dir = nil)
# ProxyCommand and ProxyJump override each other so they need to be tracked togeather
%w[proxyjump proxycommand].each do |proxy_key|
if (proxy_value = settings.delete(proxy_key))
settings['proxy'] ||= [proxy_key, proxy_value]
# When ProxyJump is set to none explicity disable the jumphost
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we clear settings['proxy'] if proxy jump is none. I mean if one config has a proxy configured but a more specific sets it none then we should clear it, shouldn't we?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I totally missed this! Let me fix that up

unless proxy_key == 'proxyjump' and proxy_value == 'none'
settings['proxy'] ||= [proxy_key, proxy_value]
end
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/net/ssh/proxy/jump.rb
Expand Up @@ -43,9 +43,11 @@ def build_proxy_command_equivalent(connection_options = nil)
template << " -p #{uri.port}" if uri.port
template << " -J #{extra_jumps}" if extra_jumps
template << " -F #{config}" if config != true && config
template << " -W %h:%p "
template << uri.host

# When ProxyJump is set to none explicity disable the jumphost
unless uri.host == 'none'
template << " -W %h:%p "
template << uri.host
end
@command_line_template = template
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_proxy_jump.rb
Expand Up @@ -7,6 +7,12 @@ def test_is_a_proxy_command
assert proxy.is_a?(Net::SSH::Proxy::Command)
end

def test_proxy_none
proxy = Net::SSH::Proxy::Jump.new("none")
proxy.build_proxy_command_equivalent
assert_equal "ssh", proxy.command_line_template
end

def test_host
proxy = Net::SSH::Proxy::Jump.new("jumphost")
proxy.build_proxy_command_equivalent
Expand Down