factor-connector-ssh 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/factor/connector/ssh.rb +48 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03df7c841e47c23e72420dcc09f91295f03b8754
4
- data.tar.gz: 28425cd7c2e60cb7a36fbc51421a9dba8d633211
3
+ metadata.gz: 626d8267471771788e813eb9266923489db3d4e8
4
+ data.tar.gz: 98ed1bbf9142689203d38d9c93c07c268cc91849
5
5
  SHA512:
6
- metadata.gz: d176236d1004d233055e50f62c76f0987feaa1202ed103ab1062dab6db061cfea3a7b3b4375e1a3de90c153a49b3002930cf3e1200fbb793a5286d8580e0455b
7
- data.tar.gz: 6bd5c88e3d6f62b2ac42042d7b5233317f1b5e1b21c4d21ee38aa45a1c26e5b6731fd627d89f30bb043758bec6f787e565a03c77469043bb0ac219bb1088308f
6
+ metadata.gz: cf44969ec87c27d08add881431a20b29c7fa93bf6468441f3efd84477915e251cc3647d4c23d809017274bedcd0016efbe79577187cab7d243d4b06721971e03
7
+ data.tar.gz: 4791f30d29e654059e3cff063a78e48688347d16442403f94c5fedff7b8663dac02bbf9cc7356d619fc864aeeb08b33ad24a3599cafb3bc12437f49b596a046b
@@ -5,6 +5,46 @@ require 'tempfile'
5
5
  require 'securerandom'
6
6
  require 'uri'
7
7
 
8
+ class Net::SSH::Connection::Session
9
+ class CommandExecutionFailed < StandardError
10
+ end
11
+
12
+ def exec_sc!(command)
13
+ stdout_data,stderr_data = "",""
14
+ exit_code,exit_signal = nil,nil
15
+ self.open_channel do |channel|
16
+ channel.exec(command) do |_, success|
17
+ raise CommandExecutionFailed, "Command \"#{command}\" was unable to execute" unless success
18
+
19
+ channel.on_data do |_,data|
20
+ stdout_data += data
21
+ end
22
+
23
+ channel.on_extended_data do |_,_,data|
24
+ stderr_data += data
25
+ end
26
+
27
+ channel.on_request("exit-status") do |_,data|
28
+ exit_code = data.read_long
29
+ end
30
+
31
+ channel.on_request("exit-signal") do |_, data|
32
+ exit_signal = data.read_long
33
+ end
34
+ end
35
+ end
36
+ self.loop
37
+
38
+ {
39
+ stdout:stdout_data,
40
+ stderr:stderr_data,
41
+ exit_code:exit_code,
42
+ exit_signal:exit_signal
43
+ }
44
+ end
45
+ end
46
+
47
+
8
48
  Factor::Connector.service 'ssh' do
9
49
  action 'execute' do |params|
10
50
  host_param = params['host']
@@ -43,21 +83,22 @@ Factor::Connector.service 'ssh' do
43
83
  fail 'Host variable must specific host address' unless host
44
84
 
45
85
  begin
86
+ return_info = []
46
87
  Net::SSH.start(host, user, ssh_settings) do |ssh|
47
88
  commands.each do |command|
48
89
  info "Executing '#{command}'"
49
- output_lines = ssh.exec!(command)
90
+ output = ssh.exec_sc!(command)
50
91
  encode_settings = {
51
92
  invalid: :replace,
52
93
  undef: :replace,
53
94
  replace: '?'
54
95
  }
55
- output_lines = output_lines.to_s.encode('UTF-8', encode_settings)
56
- output << output_lines
57
- command_lines << {
58
- lines: output_lines.split("\n"),
59
- all: output_lines
60
- }
96
+
97
+ output[:stdout] = output[:stdout].to_s.encode('UTF-8', encode_settings).split("\n")
98
+ output[:stderr] = output[:stderr].to_s.encode('UTF-8', encode_settings).split("\n")
99
+ output[:command] = command
100
+ return_info << output
101
+
61
102
  end
62
103
  end
63
104
  rescue Net::SSH::AuthenticationFailed
@@ -72,11 +113,6 @@ Factor::Connector.service 'ssh' do
72
113
  rescue
73
114
  warn 'Failed to clean up, but no worries, work will go on.'
74
115
  end
75
- return_info = {
76
- line: output.split("\n"),
77
- all: output,
78
- command: command_lines
79
- }
80
116
  action_callback return_info
81
117
  end
82
118
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor-connector-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh