Class: Bcome::Ssh::ConnectionWrangler
- Inherits:
-
Object
- Object
- Bcome::Ssh::ConnectionWrangler
- Defined in:
- lib/objects/ssh/connection_wrangler.rb
Instance Attribute Summary collapse
-
#proxy_details ⇒ Object
Returns the value of attribute proxy_details.
Instance Method Summary collapse
- #create_proxy ⇒ Object
-
#first_hop ⇒ Object
Accessors –.
- #get_local_port_forward_command(start_port, end_port) ⇒ Object
- #get_rsync_command(local_path, remote_path) ⇒ Object
- #get_ssh_command(config = {}, _proxy_only = false) ⇒ Object
- #has_hop? ⇒ Boolean
- #hops ⇒ Object
-
#initialize(ssh_driver) ⇒ ConnectionWrangler
constructor
A new instance of ConnectionWrangler.
- #proxy ⇒ Object
- #single_hop? ⇒ Boolean
Constructor Details
#initialize(ssh_driver) ⇒ ConnectionWrangler
Returns a new instance of ConnectionWrangler.
9 10 11 12 13 14 15 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 9 def initialize(ssh_driver) @ssh_driver = ssh_driver @config = ssh_driver.config[:proxy] @context_node = ssh_driver.context_node @user = ssh_driver.user set_proxy_details end |
Instance Attribute Details
#proxy_details ⇒ Object
Returns the value of attribute proxy_details.
7 8 9 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 7 def proxy_details @proxy_details end |
Instance Method Details
#create_proxy ⇒ Object
34 35 36 37 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 34 def create_proxy proxy = Net::SSH::Proxy::Jump.new(hops.reverse.collect(&:get_ssh_string).join(',')) proxy end |
#first_hop ⇒ Object
Accessors –
18 19 20 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 18 def first_hop hops.reverse.first end |
#get_local_port_forward_command(start_port, end_port) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 54 def get_local_port_forward_command(start_port, end_port) # TODO: - below check is not actually true... you might still want to proxy over SSH... raise ::Bcome::Exception::InvalidPortForwardRequest, 'Connections to this node are not via a proxy. Rather than port forward, try connecting directly.' unless has_hop? cmd = "ssh -N -L #{start_port}:localhost:#{end_port} -J" cmd += "\s" + hops.collect(&:get_ssh_string).join(',') if has_hop? cmd += "\s#{@ssh_driver.user}@#{target_machine_ingress_ip}" cmd end |
#get_rsync_command(local_path, remote_path) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 47 def get_rsync_command(local_path, remote_path) cmd = 'rsync -azv' cmd += "\s-e 'ssh\s-A -J\s" + hops.collect(&:get_ssh_string).join(',') + "'" if has_hop? cmd += "\s#{local_path}\s#{@ssh_driver.user}@#{target_machine_ingress_ip}:#{remote_path}" cmd end |
#get_ssh_command(config = {}, _proxy_only = false) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 39 def get_ssh_command(config = {}, _proxy_only = false) cmd = has_hop? ? 'ssh -J' : 'ssh' cmd += "\s" + hops.collect(&:get_ssh_string).join(',') if has_hop? cmd += "\s#{@ssh_driver.user}@#{target_machine_ingress_ip}" config[:as_pseudo_tty] ? "#{cmd} -t" : cmd end |
#has_hop? ⇒ Boolean
22 23 24 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 22 def has_hop? hops.any? end |
#hops ⇒ Object
65 66 67 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 65 def hops @hops ||= set_hops end |
#proxy ⇒ Object
30 31 32 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 30 def proxy @proxy ||= create_proxy end |
#single_hop? ⇒ Boolean
26 27 28 |
# File 'lib/objects/ssh/connection_wrangler.rb', line 26 def single_hop? has_hop? && hops.size == 1 end |