Class: Devproxy::Connection
- Inherits:
-
Object
- Object
- Devproxy::Connection
- Defined in:
- lib/devproxy/connection.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MAX_DOTS =
60
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#ssh ⇒ Object
readonly
Returns the value of attribute ssh.
Class Method Summary collapse
Instance Method Summary collapse
- #halt? ⇒ Boolean
-
#initialize(options, ssh) ⇒ Connection
constructor
A new instance of Connection.
- #loop! ⇒ Object
- #on_close ⇒ Object
- #on_stderr(data) ⇒ Object
- #on_stdout(data) ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(options, ssh) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 |
# File 'lib/devproxy/connection.rb', line 13 def initialize , ssh , @ssh, @halt = , ssh, false reset_dots! end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/devproxy/connection.rb', line 9 def end |
#ssh ⇒ Object (readonly)
Returns the value of attribute ssh.
9 10 11 |
# File 'lib/devproxy/connection.rb', line 9 def ssh @ssh end |
Class Method Details
.create(options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/devproxy/connection.rb', line 56 def self.create() ssh = open_ssh() connection = new(,ssh) ssh.forward.remote(.port,"localhost",0,'0.0.0.0') channel = ssh.exec(.proxy) do |ch,stream,data| if stream == :stdout connection.on_stdout(data) else connection.on_stderr(data) end end channel.on_close do connection.on_close end connection rescue Net::SSH::AuthenticationFailed raise Error::Authentication, "Authentication Failed: Invalid username or SSH key" end |
.loop!(options) ⇒ Object
52 53 54 |
# File 'lib/devproxy/connection.rb', line 52 def self.loop!() create().loop! end |
.open_ssh(options) ⇒ Object
74 75 76 77 78 |
# File 'lib/devproxy/connection.rb', line 74 def self.open_ssh() Net::SSH.start(.host, .username,{ :port => .remote_port, }) end |
Instance Method Details
#halt? ⇒ Boolean
27 28 29 |
# File 'lib/devproxy/connection.rb', line 27 def halt? @halt end |
#loop! ⇒ Object
18 19 20 21 22 23 |
# File 'lib/devproxy/connection.rb', line 18 def loop! @ssh.loop { !halt? } rescue Errno::ECONNREFUSED on_stderr "CONNECTION REFUSED. Is there anything listening on port #{options.port}?" retry end |
#on_close ⇒ Object
43 44 45 |
# File 'lib/devproxy/connection.rb', line 43 def on_close stop! end |
#on_stderr(data) ⇒ Object
38 39 40 41 |
# File 'lib/devproxy/connection.rb', line 38 def on_stderr data $stderr.puts "\nError: #{data}" reset_dots! end |
#on_stdout(data) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/devproxy/connection.rb', line 31 def on_stdout data $stdout.write data if (@dotno += 1) % MAX_DOTS == 0 $stdout.write "\n" end end |
#stop! ⇒ Object
24 25 26 |
# File 'lib/devproxy/connection.rb', line 24 def stop! @halt = true end |