train-core 3.8.5 → 3.8.9

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
  SHA256:
3
- metadata.gz: 4f18f7c68501c5b726aa917009507d012e8c31022bedb829a2b4c90636137cb9
4
- data.tar.gz: 939cc8932cf9b94c88785e5d3efd0c3e8b3ef0b47948e2f80fe5c7baa434d40d
3
+ metadata.gz: edb9b675408e81e6b24133e0fa0a859d19f727091fda4a93a7b16691addb20cf
4
+ data.tar.gz: 628ff896313d2ad8113a01c018864840fc341f2239246c85e8d2c47a921354fb
5
5
  SHA512:
6
- metadata.gz: 00176b461c853b0d1167451fa43aea79159b696a3e0be0a0cd8a10934ee426d60b6fc463e0cd62643a7c53a6ead8100ec423ab8c1f18c3f48a3085601abf93fc
7
- data.tar.gz: ccacf527642f27d7a84782050f0c05f2f0e617ea82b3bac2f5be258a17a2572cdbc0b7212e1eafba48003204012cb616e29daf88649e9349d7b726f59576df41
6
+ metadata.gz: d37f24464d367c55bfa73f285804b2428203219452a04d58bab4623adff91bc834ea4e27a1a1eb67aa813b3ab99ea4a16cecbe805dd92125e5f8df3e4308862f
7
+ data.tar.gz: 853c5858f859944c9e5b0777191d370ed062441986af9ab86e86b532188145dd1df55a1fc0ffea4cd6113545420783f3f489eb0a8e6db50851a5a6d2ebc4765e
data/lib/train/errors.rb CHANGED
@@ -38,6 +38,9 @@ module Train
38
38
  # Exception for when no platform can be detected.
39
39
  class PlatformDetectionFailed < Error; end
40
40
 
41
+ # Exception for when no uuid for the platform can be detected.
42
+ class PlatformUuidDetectionFailed < Error; end
43
+
41
44
  # Exception for when a invalid cache type is passed.
42
45
  class UnknownCacheType < Error; end
43
46
 
@@ -122,7 +122,6 @@ module Train::Platforms::Detect::Helpers
122
122
  end
123
123
 
124
124
  def unix_uuid_from_machine_file
125
- # require 'pry';binding.pry
126
125
  %W{
127
126
  /etc/chef/chef_guid
128
127
  #{ENV["HOME"]}/.chef/chef_guid
@@ -20,12 +20,13 @@ module Train::Platforms::Detect
20
20
  elsif @platform.windows?
21
21
  windows_uuid
22
22
  else
23
- if @platform[:uuid_command]
23
+ # Checking "unknown" :uuid_command which is set for mock transport.
24
+ if @platform[:uuid_command] && !@platform[:uuid_command] == "unknown"
24
25
  result = @backend.run_command(@platform[:uuid_command])
25
26
  return uuid_from_string(result.stdout.chomp) if result.exit_status == 0 && !result.stdout.empty?
26
27
  end
27
28
 
28
- raise "Could not find platform uuid! Please set a uuid_command for your platform."
29
+ raise Train::PlatformUuidDetectionFailed.new("Could not find platform uuid! Please set a uuid_command for your platform.")
29
30
  end
30
31
  end
31
32
  end
@@ -43,7 +43,7 @@ module Train::Transports
43
43
 
44
44
  # common target configuration
45
45
  option :host, required: true
46
- option :ssh_config_file, default: false
46
+ option :ssh_config_file, default: true
47
47
  option :port, default: 22, coerce: proc { |v| read_options_from_ssh_config(v, :port) }, required: true
48
48
  option :user, default: "root", coerce: proc { |v| read_options_from_ssh_config(v, :user) }, required: true
49
49
  option :key_files, default: nil
@@ -87,29 +87,30 @@ module Train::Transports
87
87
  end
88
88
  end
89
89
 
90
+ # Returns the ssh config option like user, port from config files
91
+ # Params options [Hash], option_type [String]
92
+ # Return String
90
93
  def self.read_options_from_ssh_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
94
+ files = options[:ssh_config_file].nil? || options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
95
+ config_options = Net::SSH::Config.for(options[:host], files)
96
+ config_options[option_type]
96
97
  end
97
98
 
98
99
  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
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
+ # Precedence is given to the option set by the user manually.
108
+ # And only assigning value to the option from the ssh config file when it is not set by the user
109
+ # in the option. When the option has a default value for e.g. option "keepalive_interval" has the "60" as the default
110
+ # value, then the default value will be used even though the value for "user" is present in the ssh
111
+ # config file. That is because the precedence is to the options set manually, and currently we don't have
112
+ # any way to differentiate between the value set by the user or is it the default. This has a future of improvement.
113
+ options[key] = host_cfg[key]
113
114
  end
114
115
  end
115
116
  end
@@ -133,14 +134,18 @@ module Train::Transports
133
134
  key_files = Array(options[:key_files])
134
135
  options[:auth_methods] ||= ["none"]
135
136
 
136
- unless key_files.empty?
137
- options[:auth_methods].push("publickey")
137
+ # by default auth_methods has a default values [none publickey password keyboard-interactive]
138
+ # REF: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L48
139
+ if key_files.empty?
140
+ options[:auth_methods].delete("publickey")
141
+ else
138
142
  options[:keys_only] = true if options[:password].nil?
139
143
  options[:key_files] = key_files
140
144
  end
141
145
 
142
- unless options[:password].nil?
143
- options[:auth_methods].push("password", "keyboard-interactive")
146
+ if options[:password].nil?
147
+ options[:auth_methods].delete("password")
148
+ options[:auth_methods].delete("keyboard-interactive")
144
149
  end
145
150
 
146
151
  if options[:auth_methods] == ["none"]
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.8.5".freeze
5
+ VERSION = "3.8.9".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.8.5
4
+ version: 3.8.9
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-11-30 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable