train-core 3.3.24 → 3.4.8
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/train.rb +3 -0
- data/lib/train/platforms/detect/helpers/os_windows.rb +15 -10
- data/lib/train/transports/ssh.rb +1 -0
- data/lib/train/transports/ssh_connection.rb +24 -9
- data/lib/train/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54dee42a0ad37ef8b4308a184f5bd63f869565db241c1c1fa910626d6c9a323f
|
4
|
+
data.tar.gz: afbeb697f1d0613f9d86af612e5ce6745b27b4ac597221b5e07db0e11b9d90d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2029c737655fc5f2eea92e290d73bbd0b6b7eac73ecc7e2e5526870e5318f6beceba8bc64c555ac451007cd1083870bba35985fa8353560a6040a5c6b997186
|
7
|
+
data.tar.gz: c57536c1bdddbde99d4955276d5fe14c20dbe84b7f109059bb8d8ee56a02f49f484811784aacf8384b1d6e5229f92f46f03fe005008677531eaef2abea55fe62
|
data/lib/train.rb
CHANGED
@@ -113,6 +113,9 @@ module Train
|
|
113
113
|
# TODO: rewrite next line using compact! once we drop support for ruby 2.3
|
114
114
|
creds = creds.delete_if { |_, value| value.nil? }
|
115
115
|
|
116
|
+
# merge train options in from the URI query string
|
117
|
+
creds.merge!(uri.query_values.map { |k, v| [k.to_sym, v] }.to_h) unless uri.query_values.nil?
|
118
|
+
|
116
119
|
# return the updated config
|
117
120
|
creds
|
118
121
|
end
|
@@ -33,15 +33,20 @@ module Train::Platforms::Detect::Helpers
|
|
33
33
|
command = @backend.run_command(
|
34
34
|
"Get-WmiObject Win32_OperatingSystem | Select Caption,Version | ConvertTo-Json"
|
35
35
|
)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
# some targets (e.g. Cisco) may return 0 and print an error to stdout
|
37
|
+
return false if (command.exit_status != 0) || command.stdout.downcase !~ /window/
|
38
|
+
|
39
|
+
begin
|
40
|
+
payload = JSON.parse(command.stdout)
|
41
|
+
@platform[:family] = "windows"
|
42
|
+
@platform[:release] = payload["Version"]
|
43
|
+
@platform[:name] = payload["Caption"]
|
44
|
+
|
45
|
+
read_wmic
|
46
|
+
true
|
47
|
+
rescue
|
48
|
+
false
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
def local_windows?
|
@@ -126,7 +131,7 @@ module Train::Platforms::Detect::Helpers
|
|
126
131
|
return if !file.exist? || file.size == 0
|
127
132
|
|
128
133
|
json = JSON.parse(file.content)
|
129
|
-
json["node_uuid"]
|
134
|
+
json["node_uuid"]
|
130
135
|
end
|
131
136
|
|
132
137
|
def windows_uuid_from_wmic
|
data/lib/train/transports/ssh.rb
CHANGED
@@ -63,6 +63,7 @@ module Train::Transports
|
|
63
63
|
option :bastion_port, default: 22
|
64
64
|
option :non_interactive, default: false
|
65
65
|
option :verify_host_key, default: false
|
66
|
+
option :forward_agent, default: false
|
66
67
|
|
67
68
|
# Allow connecting with older algorithms
|
68
69
|
option :append_all_supported_algorithms, default: true
|
@@ -29,8 +29,8 @@ class Train::Transports::SSH
|
|
29
29
|
#
|
30
30
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
31
31
|
class Connection < BaseConnection # rubocop:disable Metrics/ClassLength
|
32
|
-
attr_reader
|
33
|
-
|
32
|
+
attr_reader :hostname
|
33
|
+
attr_accessor :transport_options
|
34
34
|
|
35
35
|
def initialize(options)
|
36
36
|
# Track IOS command retries to prevent infinite loop on IOError. This must
|
@@ -72,13 +72,18 @@ class Train::Transports::SSH
|
|
72
72
|
|
73
73
|
args = %w{ -o UserKnownHostsFile=/dev/null }
|
74
74
|
args += %w{ -o StrictHostKeyChecking=no }
|
75
|
-
args += %w{ -o
|
76
|
-
args += %w{ -o BatchMode=yes } if options[:non_interactive]
|
75
|
+
args += %w{ -o BatchMode=yes } if options[:non_interactive]
|
77
76
|
args += %W{ -o LogLevel=#{level} }
|
78
77
|
args += %W{ -o ForwardAgent=#{fwd_agent} } if options.key?(:forward_agent)
|
79
|
-
|
80
|
-
|
78
|
+
|
79
|
+
keys = Array(options[:keys])
|
80
|
+
unless keys.empty?
|
81
|
+
args += %w{ -o IdentitiesOnly=yes }
|
82
|
+
keys.each do |ssh_key|
|
83
|
+
args += %W{ -i #{ssh_key} }
|
84
|
+
end
|
81
85
|
end
|
86
|
+
|
82
87
|
args
|
83
88
|
end
|
84
89
|
|
@@ -242,6 +247,16 @@ class Train::Transports::SSH
|
|
242
247
|
|
243
248
|
exit_status, stdout, stderr = execute_on_channel(cmd, opts, &data_handler)
|
244
249
|
|
250
|
+
# An interactive console might contain the STDERR in STDOUT
|
251
|
+
# concat both outputs for non-zero exit status.
|
252
|
+
output = "#{stdout} #{stderr}".strip if exit_status != 0
|
253
|
+
|
254
|
+
# Abstract the su - USER authentication failure
|
255
|
+
# raise the Train::UserError and passes message & reason
|
256
|
+
if output && output.match?("su: Authentication failure")
|
257
|
+
raise Train::UserError.new(output, :bad_su_user_password)
|
258
|
+
end
|
259
|
+
|
245
260
|
# Since `@session.loop` succeeded, reset the IOS command retry counter
|
246
261
|
@ios_cmd_retries = 0
|
247
262
|
|
@@ -317,12 +332,12 @@ class Train::Transports::SSH
|
|
317
332
|
channel.exec(cmd) do |_, success|
|
318
333
|
abort "Couldn't execute command on SSH." unless success
|
319
334
|
channel.on_data do |_, data|
|
320
|
-
yield(data) if block_given?
|
335
|
+
yield(data, channel) if block_given?
|
321
336
|
stdout += data
|
322
337
|
end
|
323
338
|
|
324
339
|
channel.on_extended_data do |_, _type, data|
|
325
|
-
yield(data) if block_given?
|
340
|
+
yield(data, channel) if block_given?
|
326
341
|
stderr += data
|
327
342
|
end
|
328
343
|
|
@@ -341,7 +356,7 @@ class Train::Transports::SSH
|
|
341
356
|
if timeout
|
342
357
|
res = thr.join(timeout)
|
343
358
|
unless res
|
344
|
-
logger.
|
359
|
+
logger.debug("train ssh command '#{cmd}' reached requested timeout (#{timeout}s)")
|
345
360
|
session.channels.each_value { |c| c.eof!; c.close }
|
346
361
|
raise Train::CommandTimeoutReached.new "ssh command reached timeout (#{timeout}s)"
|
347
362
|
end
|
data/lib/train/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef InSpec Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
191
|
+
rubygems_version: 3.1.4
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Transport interface to talk to a selected set of backends.
|