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.
- checksums.yaml +4 -4
- data/lib/factor/connector/ssh.rb +48 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 626d8267471771788e813eb9266923489db3d4e8
|
4
|
+
data.tar.gz: 98ed1bbf9142689203d38d9c93c07c268cc91849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf44969ec87c27d08add881431a20b29c7fa93bf6468441f3efd84477915e251cc3647d4c23d809017274bedcd0016efbe79577187cab7d243d4b06721971e03
|
7
|
+
data.tar.gz: 4791f30d29e654059e3cff063a78e48688347d16442403f94c5fedff7b8663dac02bbf9cc7356d619fc864aeeb08b33ad24a3599cafb3bc12437f49b596a046b
|
data/lib/factor/connector/ssh.rb
CHANGED
@@ -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
|
-
|
90
|
+
output = ssh.exec_sc!(command)
|
50
91
|
encode_settings = {
|
51
92
|
invalid: :replace,
|
52
93
|
undef: :replace,
|
53
94
|
replace: '?'
|
54
95
|
}
|
55
|
-
|
56
|
-
output
|
57
|
-
|
58
|
-
|
59
|
-
|
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.
|
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-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|