Created
December 7, 2017 14:25
-
-
Save NAshwini/bdf45c37b93bf4cfa926286bb881066f to your computer and use it in GitHub Desktop.
Gist for http_proxy of card [MSYS-721]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/kitchen/transport/ssh.rb b/lib/kitchen/transport/ssh.rb | |
index bc836e1..b315b61 100644 | |
--- a/lib/kitchen/transport/ssh.rb | |
+++ b/lib/kitchen/transport/ssh.rb | |
@@ -21,6 +21,7 @@ require "kitchen" | |
require "fileutils" | |
require "net/ssh" | |
require "net/ssh/gateway" | |
+require "net/ssh/proxy/http" | |
require "net/scp" | |
require "timeout" | |
require "benchmark" | |
@@ -55,6 +56,11 @@ module Kitchen | |
default_config :ssh_gateway, nil | |
default_config :ssh_gateway_username, nil | |
+ default_config :kitchen_ssh_proxy, nil | |
+ default_config :http_proxy_port, nil | |
+ default_config :http_proxy_user, nil | |
+ default_config :http_proxy_password, nil | |
+ | |
default_config :ssh_key, nil | |
expand_path_for :ssh_key | |
@@ -154,6 +160,14 @@ module Kitchen | |
# Should support other ports than 22 for ssh gateways | |
args += %W{ -o ProxyCommand=#{gateway_command} -p 22 } | |
end | |
+ if kitchen_ssh_proxy | |
+ if http_proxy_user && http_proxy_password | |
+ http_proxy_command = "ncat --proxy #{kitchen_ssh_proxy} --proxy-type http --proxy-auth #{http_proxy_user}:#{http_proxy_password} %h %p" | |
+ else | |
+ http_proxy_command = "ncat --proxy #{kitchen_ssh_proxy} --proxy-type http %h %p" | |
+ end | |
+ args += %W{ -o ProxyCommand=#{http_proxy_command} } | |
+ end | |
Array(options[:keys]).each { |ssh_key| args += %W{ -i #{ssh_key} } } | |
args += %W{ -p #{port} } | |
args += %W{ #{username}@#{hostname} } | |
@@ -271,6 +285,26 @@ module Kitchen | |
# @api private | |
attr_reader :ssh_gateway_username | |
+ # @return [String] The kitchen ssh proxy to use when connecting to the | |
+ # remote SSH host via http proxy | |
+ # @api private | |
+ attr_reader :kitchen_ssh_proxy | |
+ | |
+ # @return [String] The port to use when using an kitchen ssh proxy | |
+ # remote SSH host via http proxy | |
+ # @api private | |
+ attr_reader :http_proxy_port | |
+ | |
+ # @return [String] The username to use when using an kitchen ssh proxy | |
+ # remote SSH host via http proxy | |
+ # @api private | |
+ attr_reader :http_proxy_user | |
+ | |
+ # @return [String] The password to use when using an kitchen ssh proxy | |
+ # remote SSH host via http proxy | |
+ # @api private | |
+ attr_reader :http_proxy_password | |
+ | |
# Establish an SSH session on the remote host using a gateway host. | |
# | |
# @param opts [Hash] retry options | |
@@ -380,6 +414,10 @@ module Kitchen | |
@max_wait_until_ready = @options.delete(:max_wait_until_ready) | |
@ssh_gateway = @options.delete(:ssh_gateway) | |
@ssh_gateway_username = @options.delete(:ssh_gateway_username) | |
+ @kitchen_ssh_proxy = @options.delete(:kitchen_ssh_proxy) | |
+ @http_proxy_user = @options.delete(:http_proxy_user) | |
+ @http_proxy_password = @options.delete(:http_proxy_password) | |
+ @http_proxy_port = @options.delete(:http_proxy_port) | |
end | |
# Returns a connection session, or establishes one when invoked the | |
@@ -446,6 +484,13 @@ module Kitchen | |
opts[:auth_methods] = ["publickey"] | |
end | |
+ if data[:kitchen_ssh_proxy] | |
+ options_http_proxy = {} | |
+ options_http_proxy[:user] = data[:http_proxy_user] | |
+ options_http_proxy[:password] = data[:http_proxy_password] | |
+ opts[:proxy] = Net::SSH::Proxy::HTTP.new("#{data[:kitchen_ssh_proxy]}", data[:http_proxy_port], options_http_proxy) | |
+ end | |
+ | |
if data[:ssh_key_only] | |
opts[:auth_methods] = ["publickey"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment