train-core 3.8.1 → 3.8.5

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: acaccd8e644f55898c93991140f7e5b2d80bc097f35a0abd0daffcae9c183d22
4
- data.tar.gz: bc1fe10109c88984eaeecb33a8674bac49ccef138c198ffd0fad48f3cf82d3f1
3
+ metadata.gz: 4f18f7c68501c5b726aa917009507d012e8c31022bedb829a2b4c90636137cb9
4
+ data.tar.gz: 939cc8932cf9b94c88785e5d3efd0c3e8b3ef0b47948e2f80fe5c7baa434d40d
5
5
  SHA512:
6
- metadata.gz: 1b4531fa4c4422fa17bafd72591d1215a116c7ba2e0884d5f55f1064f436f1e7c28044983614e7d03a8ef034c7c986357300de77b9303dd50589aefd1ce84588
7
- data.tar.gz: f5ef700b4ab4aa297e62cf3f104e9f29fab45d75582d670ae8a9d18bccef602e0aba502b9c2e7f6dc004e13ff240bbc88a0b7f34ae96390c07ef74713e590d6e
6
+ metadata.gz: 00176b461c853b0d1167451fa43aea79159b696a3e0be0a0cd8a10934ee426d60b6fc463e0cd62643a7c53a6ead8100ec423ab8c1f18c3f48a3085601abf93fc
7
+ data.tar.gz: ccacf527642f27d7a84782050f0c05f2f0e617ea82b3bac2f5be258a17a2572cdbc0b7212e1eafba48003204012cb616e29daf88649e9349d7b726f59576df41
@@ -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.8.1".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.8.1
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-07-27 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