Class: Devproxy::Session

Inherits:
Struct
  • Object
show all
Defined in:
lib/devproxy/session.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

HEARTBEAT =
"HEARTBEAT"
CONNECT =
"CONNECT:"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sshObject

Returns the value of attribute ssh

Returns:

  • (Object)

    the current value of ssh



5
6
7
# File 'lib/devproxy/session.rb', line 5

def ssh
  @ssh
end

Class Method Details

.create(options, connection) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/devproxy/session.rb', line 24

def self.create(options,connection)
  ssh        = open_ssh(options)
  ssh.forward.remote(options.port,options.listen,0,'0.0.0.0')
  channel    = ssh.exec(options.proxy) do |ch,stream,data|
    if stream == :stdout
      if data.start_with?(HEARTBEAT)
        connection.on_heartbeat(data)
      elsif data.start_with?(CONNECT)
        connection.on_connected(data[(CONNECT.size)..-1].chomp)
      else
        connection.on_stdout(data)
      end
    else
      connection.on_stderr(data)
    end
  end
  channel.on_close do
    connection.on_close
  end
  new(ssh)
rescue Net::SSH::AuthenticationFailed
  raise Error::Authentication, "Authentication Failed: Invalid username or SSH key"
end

.open_ssh(options) ⇒ Object



47
48
49
50
51
52
# File 'lib/devproxy/session.rb', line 47

def self.open_ssh(options)
  Net::SSH.start(options.host, options.username,{
    :port => options.remote_port,
    :user_known_hosts_file => "/dev/null",
  })
end

Instance Method Details

#loop!Object



16
17
18
# File 'lib/devproxy/session.rb', line 16

def loop!
  ssh.loop { !@halt }
end

#shutdown!Object



12
13
14
# File 'lib/devproxy/session.rb', line 12

def shutdown!
  ssh.shutdown!
end

#stop!Object



20
21
22
# File 'lib/devproxy/session.rb', line 20

def stop!
  @halt = true
end