train-core 3.7.0 → 3.8.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e0529be878892640599f401af47c6c012a8d060fea3113895872b0af7e24127
4
- data.tar.gz: 4b387bc5129fbf652b37713a63d74173d8d04f3ea5dbdf9993cadf0d276f3add
3
+ metadata.gz: 4f18f7c68501c5b726aa917009507d012e8c31022bedb829a2b4c90636137cb9
4
+ data.tar.gz: 939cc8932cf9b94c88785e5d3efd0c3e8b3ef0b47948e2f80fe5c7baa434d40d
5
5
  SHA512:
6
- metadata.gz: 7fdf259b32a3dc0f033681b2f98e164f2ef76c8b4e7f51fb5bc1fe2412a1501039cdddfc06ef409f7b235dbcefef693f97c7fff21c02d7011618fdfc5ad09a9d
7
- data.tar.gz: 2f90638d94542daf5e70488f6fd5e592986d3a76ac6b10f188414a109b53fffc8000202ce0a853f68bc1a8c1dfee9178107da5fee2b51728a01b1863b3976baf
6
+ metadata.gz: 00176b461c853b0d1167451fa43aea79159b696a3e0be0a0cd8a10934ee426d60b6fc463e0cd62643a7c53a6ead8100ec423ab8c1f18c3f48a3085601abf93fc
7
+ data.tar.gz: ccacf527642f27d7a84782050f0c05f2f0e617ea82b3bac2f5be258a17a2572cdbc0b7212e1eafba48003204012cb616e29daf88649e9349d7b726f59576df41
@@ -81,6 +81,9 @@ module Train::Extras
81
81
  when /sudo: sorry, you must have a tty to run sudo/
82
82
  ["Sudo requires a TTY. Please see the README on how to configure "\
83
83
  "sudo to allow for non-interactive usage.", :sudo_no_tty]
84
+ when /sudo: a terminal is required to read the password; either use/
85
+ ["Sudo cannot prompt for password because there is no terminal. "\
86
+ "Please provide the sudo password directly", :sudo_missing_terminal]
84
87
  else
85
88
  [rawerr, nil]
86
89
  end
@@ -34,7 +34,7 @@ module Train::Extras
34
34
 
35
35
  def self.linux_stat(shell_escaped_path, backend, follow_symlink)
36
36
  lstat = follow_symlink ? " -L" : ""
37
- format = (backend.os.esx? || backend.os[:name] == "alpine" || backend.os[:name] == "yocto") ? "-c" : "--printf"
37
+ format = (backend.os.esx? || %w{alpine yocto ubios}.include?(backend.os[:name])) ? "-c" : "--printf"
38
38
  res = backend.run_command("stat#{lstat} #{shell_escaped_path} 2>/dev/null #{format} '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'")
39
39
  # ignore the exit_code: it is != 0 if selinux labels are not supported
40
40
  # on the system.
@@ -12,7 +12,7 @@ module Train
12
12
  @spath = path.gsub(/[<>"|?*]/, "")
13
13
  end
14
14
 
15
- def basename(suffix = nil, sep = '\\')
15
+ def basename(suffix = nil, sep = "\\")
16
16
  super(suffix, sep)
17
17
  end
18
18
 
@@ -74,6 +74,14 @@ module Train::Platforms::Detect::Specifications
74
74
  end
75
75
  end
76
76
 
77
+ declare_instance("ubios", "Ubiquiti UbiOS", "ubios") do
78
+ l_o_r = linux_os_release
79
+ if l_o_r && l_o_r["ID"] == "ubios"
80
+ @platform[:release] = l_o_r["VERSION_ID"]
81
+ true
82
+ end
83
+ end
84
+
77
85
  declare_instance("debian", "Debian Linux", "debian") do
78
86
  # if we get this far we have to be some type of debian
79
87
  @platform[:release] = unix_file_contents("/etc/debian_version").chomp
@@ -190,8 +190,23 @@ module Train::Transports
190
190
  script = "$ProgressPreference='SilentlyContinue';" + cmd
191
191
  encoded_script = Base64.strict_encode64(script)
192
192
  # TODO: no way to safely implement timeouts here.
193
- @pipe.puts(encoded_script)
194
- @pipe.flush
193
+ begin
194
+ @pipe.puts(encoded_script)
195
+ @pipe.flush
196
+ rescue Errno::EPIPE
197
+ # Retry once if the pipe went away
198
+ begin
199
+ # Maybe the pipe went away, but the server didn't? Reset it, to get a clean start.
200
+ close
201
+ rescue Errno::EIO
202
+ # Ignore - server already went away
203
+ end
204
+ @pipe = acquire_pipe
205
+ raise PipeError if @pipe.nil?
206
+
207
+ @pipe.puts(encoded_script)
208
+ @pipe.flush
209
+ end
195
210
  res = OpenStruct.new(JSON.parse(Base64.decode64(@pipe.readline)))
196
211
  Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
197
212
  end
@@ -216,12 +231,10 @@ module Train::Transports
216
231
 
217
232
  # PowerShell needs time to create pipe.
218
233
  100.times do
219
- begin
220
- pipe = open("//./pipe/#{pipe_name}", "r+")
221
- break
222
- rescue
223
- sleep 0.1
224
- end
234
+ pipe = open("//./pipe/#{pipe_name}", "r+")
235
+ break
236
+ rescue
237
+ sleep 0.1
225
238
  end
226
239
 
227
240
  pipe
@@ -42,12 +42,12 @@ module Train::Transports
42
42
  include_options Train::Extras::CommandWrapper
43
43
 
44
44
  # common target configuration
45
- option :host, required: true
46
- option :port, default: 22, coerce: proc { |u| read_options_from_ssh_config(u, :port) }, required: true
47
- option :user, default: "root", coerce: proc { |u| read_options_from_ssh_config(u, :user) }, required: true
45
+ option :host, required: true
46
+ option :ssh_config_file, default: false
47
+ option :port, default: 22, coerce: proc { |v| read_options_from_ssh_config(v, :port) }, required: true
48
+ option :user, default: "root", coerce: proc { |v| read_options_from_ssh_config(v, :user) }, required: true
48
49
  option :key_files, default: nil
49
50
  option :password, default: nil
50
-
51
51
  # additional ssh options
52
52
  option :keepalive, default: true
53
53
  option :keepalive_interval, default: 60
@@ -75,6 +75,7 @@ module Train::Transports
75
75
 
76
76
  # (see Base#connection)
77
77
  def connection(state = {}, &block)
78
+ apply_ssh_config_file(options[:host])
78
79
  opts = merge_options(options, state || {})
79
80
  validate_options(opts)
80
81
  conn_opts = connection_options(opts)
@@ -86,16 +87,39 @@ module Train::Transports
86
87
  end
87
88
  end
88
89
 
89
- # Returns the ssh config option like user, port from config files
90
- # Params options [Hash], option_type [String]
91
- # Return String
92
90
  def self.read_options_from_ssh_config(options, option_type)
93
- config_options = Net::SSH.configuration_for(options[:host], true)
94
- config_options[option_type]
91
+ if options[:ssh_config_file] != false && !options[:ssh_config_file].nil?
92
+ files = options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
93
+ config_options = Net::SSH::Config.for(options[:host], files)
94
+ config_options[option_type]
95
+ end
96
+ end
97
+
98
+ def apply_ssh_config_file(host)
99
+ if options[:ssh_config_file] != false && !options[:ssh_config_file].nil?
100
+ files = options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
101
+ host_cfg = ssh_config_file_for_host(host, files)
102
+ host_cfg.each do |key, value|
103
+ # setting the key_files option to the private keys set in ssh config file
104
+ if key == :keys && options[:key_files].nil? && !host_cfg[:keys].nil? && options[:password].nil?
105
+ options[:key_files] = host_cfg[key]
106
+ elsif options[key].nil?
107
+ # Give precedence to config file when ssh_config_file options is set to true or to the path of the config file.
108
+ # This is required as there are default values set for some of the opitons and we unable to
109
+ # identify whether the values are set from the cli option or those are default so either we should give
110
+ # precedence to config file or otherwise we need to check each options default values and then set the value for that option.
111
+ options[key] = host_cfg[key]
112
+ end
113
+ end
114
+ end
95
115
  end
96
116
 
97
117
  private
98
118
 
119
+ def ssh_config_file_for_host(host, files)
120
+ Net::SSH::Config.for(host, files)
121
+ end
122
+
99
123
  def reusable_connection?(conn_opts)
100
124
  return false unless @connection_options
101
125
 
@@ -131,6 +155,8 @@ module Train::Transports
131
155
  end
132
156
  end
133
157
 
158
+ options[:auth_methods] = options[:auth_methods].uniq
159
+
134
160
  if options[:pty]
135
161
  logger.warn("[SSH] PTY requested: stderr will be merged into stdout")
136
162
  end
@@ -186,6 +212,7 @@ module Train::Transports
186
212
  bastion_port: opts[:bastion_port],
187
213
  non_interactive: opts[:non_interactive],
188
214
  append_all_supported_algorithms: opts[:append_all_supported_algorithms],
215
+ config: options[:ssh_config_file],
189
216
  transport_options: opts,
190
217
  }
191
218
  # disable host key verification. The hash key and value to use
data/lib/train/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
3
3
 
4
4
  module Train
5
- VERSION = "3.7.0".freeze
5
+ VERSION = "3.8.5".freeze
6
6
  end
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.7.0
4
+ version: 3.8.5
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: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
181
  requirements:
182
182
  - - ">="
183
183
  - !ruby/object:Gem::Version
184
- version: '2.4'
184
+ version: '2.5'
185
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - ">="