Class: Freighter::SSH
- Inherits:
-
Object
- Object
- Freighter::SSH
- Defined in:
- lib/freighter/ssh.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(host, ssh_conf) ⇒ SSH
constructor
A new instance of SSH.
- #proxy ⇒ Object
- #tunneled_proxy(local_port, use_proxy = false, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
6 7 8 |
# File 'lib/freighter/ssh.rb', line 6 def thread @thread end |
Instance Method Details
#proxy ⇒ Object
15 16 17 18 |
# File 'lib/freighter/ssh.rb', line 15 def proxy docker_port = OPTIONS.config['connection']['docker']['port'] Net::SSH::Proxy::SOCKS5.new(@host, docker_port, {user: @user}.merge(@ssh_options)) end |
#tunneled_proxy(local_port, use_proxy = false, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/freighter/ssh.rb', line 20 def tunneled_proxy(local_port, use_proxy=false, &block) = use_proxy ? { proxy: proxy } : @ssh_options docker_port = OPTIONS.config['docker']['port'] LOGGER.debug "Connecting\n host: #{@host}, user: #{@user}, options: #{.inspect}" @thread = Thread.new do Thread.current.thread_variable_set(:ssh_tunnel_established, false) Net::SSH.start(@host, @user, ) do |session| session.forward.local(local_port, "0.0.0.0", docker_port) LOGGER.debug "Connected to #{@host} and port #{local_port} is forwarded to host's docker REST API port ##{docker_port}." Thread.current.thread_variable_set(:ssh_tunnel_established, true) int_pressed = false trap("INT") { int_pressed = true } session.loop(0.1) { !session.closed? && !int_pressed } end end while @thread.thread_variable_get(:ssh_tunnel_established) != true sleep 0.1 end yield end |