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 +4 -4
- data/lib/train/transports/ssh.rb +36 -9
- data/lib/train/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f18f7c68501c5b726aa917009507d012e8c31022bedb829a2b4c90636137cb9
|
4
|
+
data.tar.gz: 939cc8932cf9b94c88785e5d3efd0c3e8b3ef0b47948e2f80fe5c7baa434d40d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00176b461c853b0d1167451fa43aea79159b696a3e0be0a0cd8a10934ee426d60b6fc463e0cd62643a7c53a6ead8100ec423ab8c1f18c3f48a3085601abf93fc
|
7
|
+
data.tar.gz: ccacf527642f27d7a84782050f0c05f2f0e617ea82b3bac2f5be258a17a2572cdbc0b7212e1eafba48003204012cb616e29daf88649e9349d7b726f59576df41
|
data/lib/train/transports/ssh.rb
CHANGED
@@ -42,12 +42,12 @@ module Train::Transports
|
|
42
42
|
include_options Train::Extras::CommandWrapper
|
43
43
|
|
44
44
|
# common target configuration
|
45
|
-
option :host,
|
46
|
-
option :
|
47
|
-
option :
|
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
|
-
|
94
|
-
|
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
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.
|
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-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|