Class: Devproxy::Session
- Inherits:
-
Struct
- Object
- Struct
- Devproxy::Session
- Defined in:
- lib/devproxy/session.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- HEARTBEAT =
"HEARTBEAT"
Instance Attribute Summary collapse
-
#ssh ⇒ Object
Returns the value of attribute ssh.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#ssh ⇒ Object
Returns the value of attribute ssh
5 6 7 |
# File 'lib/devproxy/session.rb', line 5 def ssh @ssh end |
Class Method Details
.create(options, connection) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/devproxy/session.rb', line 23 def self.create(,connection) ssh = open_ssh() ssh.forward.remote(.port,.listen,0,'0.0.0.0') channel = ssh.exec(.proxy) do |ch,stream,data| if stream == :stdout if data.start_with?(HEARTBEAT) connection.on_heartbeat(data) else connection.on_stdout(data) end else connection.on_stderr(data) end end channel.on_close do connection.on_close end connection.on_connected new(ssh) rescue Net::SSH::AuthenticationFailed raise Error::Authentication, "Authentication Failed: Invalid username or SSH key" end |
.open_ssh(options) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/devproxy/session.rb', line 45 def self.open_ssh() Net::SSH.start(.host, .username,{ :port => .remote_port, :user_known_hosts_file => "/dev/null", }) end |
Instance Method Details
#loop! ⇒ Object
15 16 17 |
# File 'lib/devproxy/session.rb', line 15 def loop! ssh.loop { !@halt } end |
#shutdown! ⇒ Object
11 12 13 |
# File 'lib/devproxy/session.rb', line 11 def shutdown! ssh.shutdown! end |
#stop! ⇒ Object
19 20 21 |
# File 'lib/devproxy/session.rb', line 19 def stop! @halt = true end |