em-ssh 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1155815fe2d0f34c5f6a9042c6affe16bb4a3d2
4
- data.tar.gz: 3f473143a7b7e43f00f6ca7a47e9122644869248
3
+ metadata.gz: 08f5d7822b2ff48dc4708c0dbab6f0de0842e567
4
+ data.tar.gz: 0a4ef8adb8b79ff280e4df14ba9159f730f67be1
5
5
  SHA512:
6
- metadata.gz: 2c64f15aeccde7c71cfd9c1b1e1ffca1b66a0ef44968239266a96db22ddc2748ee64b67799d35ef6b47dad42aede1f79bff91721387780c24b6586cfbc078171
7
- data.tar.gz: a47b97dece38734b165a41ad0f2d6f5e7c86672737bb74f178db6a3c03eae3d9bb130b2abe2e31d2c6f4a15cfc17d6d1ab307af1ca8c06eb1e28a65550772ad5
6
+ metadata.gz: 8d381dca0e9711543e13975aed8eb6e6a5f066a0baa1ad123bcd0fbddb075fc7013406b0220ed721353a56ed0f8b61b280542d46418ea74198f43e6044eb2baf
7
+ data.tar.gz: 58af8534fd673f0ce11d851d9e433ba5810f550ff0cdb121484a00ab0a1b823072a4045daca7a35f9cbdc65f8fb4325bab31ffedd084aca49b6c32c357991a13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ 0.8.0
2
+ - [b1f5774](https://github.com/simulacre/em-ssh/commit/b1f5774f10b2496063db5d52bab66b1871b2cd26) - net-ssh 3.2.0; em 1.2.0; docker for testing. Contributions from Kirill Timofeev
3
+
1
4
  0.7.0
2
5
  - [88323761c67c433bd46fedfd042ae9a97b726cb6](https://github.com/simulacre/em-ssh/commit/88323761c67c433bd46fedfd042ae9a97b726cb6) - Deal with ssh servers that send algo data and server version at the same time (Dropbear). Discovered by [@mandre](https://github.com/mandre)
3
6
 
@@ -26,10 +29,10 @@
26
29
  - [#20](https://github.com/simulacre/em-ssh/pull/20) - Fix Interactive timeout wasn't set if parameter not fed [@freakhill](https://github.com/freakhill)
27
30
 
28
31
  0.5.0
29
- - Shell an Connection instances can have their own Loggers
32
+ - Shell an Connection instances can have their own Loggers
30
33
  - [#18](https://github.com/simulacre/em-ssh/pull/18) - Target devices and options for specs can be configured through environment variables [@freakhill](https://github.com/freakhill)
31
34
  - [#19](https://github.com/simulacre/em-ssh/pull/19) - Decouple interactive behavior from Shell allowing for other channels to be extended with #expect, etc., [@freakhill](https://github.com/freakhill)
32
-
35
+
33
36
  0.4.2
34
37
  - Connection accepts :nego_timeout (seconds to wait for protocol and algorithm negotiation to finish)
35
38
  - If protocol, or algorithm negotiation fail #errback will be called
data/README.md CHANGED
@@ -3,7 +3,7 @@ Em-ssh is a net-ssh adapter for EventMachine. For the most part you can take any
3
3
 
4
4
  Em-ssh is not associated with the Jamis Buck's [net-ssh](http://net-ssh.github.com/) library. Please report any bugs with em-ssh to [https://github.com/simulacre/em-ssh/issues](https://github.com/simulacre/em-ssh/issues)
5
5
  ##Installation
6
- gem install em-ssh
6
+ gem install em-ssh
7
7
 
8
8
  ##Synopsis
9
9
 
@@ -18,38 +18,38 @@ EM.run do
18
18
  connection.callback do |ssh|
19
19
  # capture all stderr and stdout output from a remote process
20
20
  ssh.exec!('uname -a').tap {|r| puts "\nuname: #{r}"}
21
-
21
+
22
22
  # capture only stdout matching a particular pattern
23
23
  stdout = ""
24
24
  ssh.exec!("ls -l /home") do |channel, stream, data|
25
25
  stdout << data if stream == :stdout
26
26
  end
27
27
  puts "\n#{stdout}"
28
-
28
+
29
29
  # run multiple processes in parallel to completion
30
30
  ssh.exec('ping -c 1 www.google.com')
31
31
  ssh.exec('ping -c 1 www.yahoo.com')
32
32
  ssh.exec('ping -c 1 www.rakuten.co.jp')
33
-
33
+
34
34
  #open a new channel and configure a minimal set of callbacks, then wait for the channel to finishes (closees).
35
35
  channel = ssh.open_channel do |ch|
36
36
  ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
37
37
  raise "could not execute command" unless success
38
-
38
+
39
39
  # "on_data" is called when the process writes something to stdout
40
40
  ch.on_data do |c, data|
41
41
  $stdout.print data
42
42
  end
43
-
43
+
44
44
  # "on_extended_data" is called when the process writes something to stderr
45
45
  ch.on_extended_data do |c, type, data|
46
46
  $stderr.print data
47
47
  end
48
-
48
+
49
49
  ch.on_close { puts "done!" }
50
50
  end
51
51
  end
52
-
52
+
53
53
  channel.wait
54
54
 
55
55
  ssh.close
@@ -62,7 +62,7 @@ end
62
62
  See [http://net-ssh.github.com/ssh/v2/api/index.html](http://net-ssh.github.com/ssh/v2/api/index.html)
63
63
 
64
64
  ##Shell
65
-
65
+
66
66
  Em-ssh provides an expect-like shell abstraction layer on top of net-ssh in EM::Ssh::Shell
67
67
 
68
68
  ### Example
@@ -149,7 +149,7 @@ EM.run do
149
149
  commands.clone.each do |command|
150
150
  Fiber.new {
151
151
  # When given a block Shell#split will close the Shell after
152
- # the block returns. If a block is given it must be called
152
+ # the block returns. If a block is given it must be called
153
153
  # within a Fiber.
154
154
  sresult = shell.split do |mys|
155
155
  mys.on(:closed) do
@@ -184,6 +184,60 @@ See bin/em-ssh-shell for a more complex example usage of Shell.
184
184
 
185
185
  Em-ssh relies on Fibers. MRI 1.9.2-p290 on OSX Lion has been known to segfault when using Fibers.
186
186
 
187
+ ## Testing
188
+
189
+ The specs for em-ssh require two accessible ssh servers. The quickest
190
+ and most consistent way to get the servers up is to use Docker.
191
+
192
+ Containers run from ``krlmlr/debian-ssh:wheezy`` will be accessible with
193
+ users 'docker' and 'root'.
194
+
195
+ If you have ``docker-compose`` installed:
196
+ ```shell
197
+ SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" docker-compose up
198
+ ```
199
+
200
+ If you do not have ``docker-compose`` installed:
201
+ ```
202
+ docker run -d -p 2222:22 -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" krlmlr/debian-ssh:wheezy
203
+ docker run -d -p 2223:22 -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" krlmlr/debian-ssh:wheezy
204
+ ```
205
+
206
+ Once the two containers are running just run the specs.
207
+
208
+ ```shell
209
+ rspec spec
210
+ ```
211
+
212
+ If you want to use different ssh servers for testing you'll need to
213
+ update the variables in ``spec/constants.rb``
214
+
215
+ If you need to debug failing tests you can change the verbosity of
216
+ EM::Ssh:
217
+
218
+ ```shell
219
+ VERBOSITY=DEBUG rspec spec
220
+ ```
221
+
222
+ ### Manual Testing
223
+
224
+ You can also run manual tests using the executable in ``bin``.
225
+
226
+ ```shell
227
+ bin/em-ssh-shell docker@localhost:2223 '$ ' 'ls -al' 'hostname' 'uname -a'
228
+ ```
229
+
230
+ ```shell
231
+ be bin/em-ssh docker@localhost:2223
232
+ ```
233
+
234
+
235
+ ## Known Issues
236
+
237
+ - If the server's signature changes from the one recorded in your
238
+ ``known_hosts`` file ``EM::Ssh.start`` will hang
239
+ - ``bin/em-ssh`` and ``bin/em-ssh-shell`` will ask for passwords even
240
+ when one isn't required
187
241
 
188
242
  ##Copyright
189
243
  Copyright (c) 2011 Caleb Crane
data/lib/em-ssh.rb CHANGED
@@ -14,7 +14,7 @@ module EventMachine
14
14
  # end
15
15
  # end
16
16
  class Ssh
17
- DEFAULT_PORT = 22
17
+ DEFAULT_PORT = Net::SSH::Transport::Session::DEFAULT_PORT
18
18
 
19
19
  # Generic error tag
20
20
  module Error; end
@@ -93,6 +93,7 @@ module EventMachine
93
93
 
94
94
  class << self
95
95
  attr_writer :logger
96
+
96
97
  # Creates a logger when necessary
97
98
  # @return [Logger]
98
99
  def logger(level = Logger::WARN)
@@ -114,11 +115,17 @@ module EventMachine
114
115
  # channel.request_pty(options[:pty] || {}) do |pty,suc|
115
116
  def connect(host, user, opts = {}, &blk)
116
117
  opts[:logger] || logger.debug("#{self}.connect(#{host}, #{user}, #{opts})")
117
- options = { :host => host, :user => user, :port => DEFAULT_PORT }.merge(opts)
118
+
119
+ options = {
120
+ host: host,
121
+ user: user,
122
+ port: DEFAULT_PORT
123
+ }.merge(opts)
124
+
118
125
  EM.connect(options[:host], options[:port], Connection, options, &blk)
119
126
  end
120
127
  alias :start :connect
121
- end # << self
128
+ end
122
129
 
123
130
  # Pull in the constants from Net::SSH::[Transport, Connection and Authentication]
124
131
  # and define them locally.
@@ -127,11 +134,11 @@ module EventMachine
127
134
  .each do |mod|
128
135
  mod.constants.each do |name|
129
136
  const_set(name, mod.const_get(name))
130
- end # |name|
131
- end # |module|
137
+ end
138
+ end
132
139
 
133
- end # class::Ssh
134
- end # module::EventMachine
140
+ end
141
+ end
135
142
 
136
143
  EM::P::Ssh = EventMachine::Ssh
137
144
 
@@ -130,7 +130,6 @@ module EventMachine
130
130
 
131
131
  if failed_timeout
132
132
  fail(@disconnect ? EM::Ssh::Disconnect.from_packet(@disconnect) : NegotiationTimeout.new(@host))
133
-
134
133
  end
135
134
  end
136
135
 
@@ -141,8 +140,9 @@ module EventMachine
141
140
  end
142
141
 
143
142
  def connection_completed
144
- @contimeout.cancel
145
- @nocon.cancel
143
+ [@contimeout, @nocon].each(&:cancel)
144
+ @contimeout = nil
145
+ @nocon = nil
146
146
  end
147
147
 
148
148
  def initialize(options = {})
@@ -248,6 +248,14 @@ module EventMachine
248
248
  end # |string|
249
249
  end # host_as_string
250
250
 
251
+ # Taken from Net::SSH::Transport::Session
252
+ def host_keys
253
+ @host_keys ||= begin
254
+ known_hosts = options.fetch(:known_hosts, Net::SSH::KnownHosts)
255
+ known_hosts.search_for(options[:host_key_alias] || host_as_string, options)
256
+ end
257
+ end
258
+
251
259
  alias :logger :log
252
260
 
253
261
 
@@ -351,6 +359,6 @@ module EventMachine
351
359
  end # paranoid.respond_to?(:verify)
352
360
  end # paranoid
353
361
  end # select_host_key_verifier(paranoid)
354
- end # class::Connection < EventMachine::Connection
355
- end # module::Ssh
356
- end # module::EventMachine
362
+ end
363
+ end
364
+ end
@@ -42,14 +42,20 @@ module EventMachine
42
42
  # channel localy and the connection will just spin.
43
43
  if transport.closed?
44
44
  channels.each do |id, c|
45
+ # remove the connection reference to facilitate Garbage Collection
45
46
  c.instance_variable_set(:@connection, nil)
46
47
  end
47
48
  channels.clear
48
49
  else
49
- channels.each { |id, channel| channel.close }
50
+ channels.each do |id, channel|
51
+ channel.close
52
+ # force one last pass through the channel's send loop, so that
53
+ # net-ssh will properly set the values for local_closed
54
+ channel.process
55
+ end
50
56
  loop { channels.any? && !transport.closed? }
51
57
  end
52
- # remove the reference to the connection to facilitate Garbage Collection
58
+ # remove the reference to the transport to facilitate Garbage Collection
53
59
  transport, @transport = @transport, nil
54
60
  @listeners.clear
55
61
  transport.close
@@ -72,11 +78,14 @@ module EventMachine
72
78
  # at some point we should override Channel#enqueue_pending_output, etc.,.
73
79
  channels.each { |id, channel| channel.process unless channel.closing? }
74
80
  end
75
- end # register_callbacks
81
+ end
76
82
 
77
83
  def channel_close(packet)
78
84
  channel = channels[packet[:local_id]]
79
85
  super(packet).tap do
86
+ # force one last pass through the channel's send loop, so that
87
+ # net-ssh will properly set the values for local_closed
88
+ channel.process
80
89
  # remove the connection reference to facilitate Garbage Collection
81
90
  channel.instance_variable_set(:@connection, nil)
82
91
  end
@@ -89,7 +98,6 @@ module EventMachine
89
98
  channel.instance_variable_set(:@connection, nil)
90
99
  end
91
100
  end
92
-
93
- end # class::Session
94
- end # class::Ssh
95
- end # module::EventMachine
101
+ end
102
+ end
103
+ end
data/lib/em-ssh/shell.rb CHANGED
@@ -78,7 +78,12 @@ module EventMachine
78
78
  @pass = pass
79
79
  @options = opts
80
80
  @logger = opts[:logger] if opts[:logger]
81
- @connect_opts = {:password => pass, :port => 22, :auth_methods => ['publickey', 'password'], :logger => log}.merge(opts[:net_ssh] || {})
81
+ @connect_opts = {
82
+ password: pass,
83
+ port: opts[:port] || 22,
84
+ auth_methods: ['publickey', 'password'],
85
+ logger: log
86
+ }.merge(opts[:net_ssh] || {})
82
87
  @session = opts[:session]
83
88
  @parent = opts[:parent]
84
89
  @children = []
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  class Ssh
3
- VERSION='0.7.0'
3
+ VERSION='0.8.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Crane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-22 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ssh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-termios
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: highline
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.6'
69
69
  description: ''
70
70
  email:
71
71
  - em-ssh@simulacre.org
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: 1.3.6
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.2.2
117
+ rubygems_version: 2.5.2
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: An EventMachine compatible net-ssh