train 2.1.7 → 2.1.13
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 +20 -20
- data/lib/train/errors.rb +1 -1
- data/lib/train/extras.rb +2 -2
- data/lib/train/extras/command_wrapper.rb +24 -24
- data/lib/train/extras/stat.rb +27 -27
- data/lib/train/file.rb +30 -30
- data/lib/train/file/local.rb +8 -8
- data/lib/train/file/local/unix.rb +5 -5
- data/lib/train/file/local/windows.rb +1 -1
- data/lib/train/file/remote.rb +8 -8
- data/lib/train/file/remote/aix.rb +1 -1
- data/lib/train/file/remote/linux.rb +2 -2
- data/lib/train/file/remote/qnx.rb +8 -8
- data/lib/train/file/remote/unix.rb +10 -14
- data/lib/train/file/remote/windows.rb +5 -5
- data/lib/train/globals.rb +1 -1
- data/lib/train/options.rb +8 -8
- data/lib/train/platforms.rb +8 -8
- data/lib/train/platforms/common.rb +1 -1
- data/lib/train/platforms/detect/helpers/os_common.rb +36 -32
- data/lib/train/platforms/detect/helpers/os_linux.rb +12 -12
- data/lib/train/platforms/detect/helpers/os_windows.rb +27 -29
- data/lib/train/platforms/detect/scanner.rb +4 -4
- data/lib/train/platforms/detect/specifications/api.rb +8 -8
- data/lib/train/platforms/detect/specifications/os.rb +252 -252
- data/lib/train/platforms/detect/uuid.rb +5 -7
- data/lib/train/platforms/platform.rb +9 -5
- data/lib/train/plugin_test_helper.rb +12 -12
- data/lib/train/plugins.rb +5 -5
- data/lib/train/plugins/base_connection.rb +13 -13
- data/lib/train/plugins/transport.rb +7 -7
- data/lib/train/transports/azure.rb +23 -23
- data/lib/train/transports/cisco_ios_connection.rb +20 -20
- data/lib/train/transports/clients/azure/graph_rbac.rb +2 -2
- data/lib/train/transports/clients/azure/vault.rb +4 -4
- data/lib/train/transports/docker.rb +4 -10
- data/lib/train/transports/gcp.rb +23 -23
- data/lib/train/transports/helpers/azure/file_credentials.rb +8 -8
- data/lib/train/transports/helpers/azure/file_parser.rb +1 -1
- data/lib/train/transports/helpers/azure/subscription_number_file_parser.rb +1 -1
- data/lib/train/transports/local.rb +22 -22
- data/lib/train/transports/mock.rb +33 -35
- data/lib/train/transports/ssh.rb +47 -47
- data/lib/train/transports/ssh_connection.rb +28 -28
- data/lib/train/transports/vmware.rb +32 -34
- data/lib/train/transports/winrm.rb +37 -37
- data/lib/train/transports/winrm_connection.rb +12 -12
- data/lib/train/version.rb +1 -1
- metadata +2 -2
@@ -20,9 +20,9 @@
|
|
20
20
|
# See the License for the specific language governing permissions and
|
21
21
|
# limitations under the License.
|
22
22
|
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
23
|
+
require "rbconfig"
|
24
|
+
require "uri"
|
25
|
+
require "train/errors"
|
26
26
|
|
27
27
|
module Train::Transports
|
28
28
|
# Wrapped exception for any internally raised WinRM-related errors.
|
@@ -36,22 +36,22 @@ module Train::Transports
|
|
36
36
|
# @author Salim Afiune <salim@afiunemaya.com.mx>
|
37
37
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
38
38
|
class WinRM < Train.plugin(1) # rubocop:disable ClassLength
|
39
|
-
name
|
39
|
+
name "winrm"
|
40
40
|
|
41
|
-
require
|
41
|
+
require "train/transports/winrm_connection"
|
42
42
|
|
43
43
|
# ref: https://github.com/winrb/winrm#transports
|
44
|
-
SUPPORTED_WINRM_TRANSPORTS = %i
|
44
|
+
SUPPORTED_WINRM_TRANSPORTS = %i{negotiate ssl plaintext kerberos}.freeze
|
45
45
|
|
46
46
|
# common target configuration
|
47
47
|
option :host, required: true
|
48
48
|
option :port
|
49
|
-
option :user, default:
|
49
|
+
option :user, default: "administrator", required: true
|
50
50
|
option :password, nil
|
51
51
|
option :winrm_transport, default: :negotiate
|
52
52
|
option :winrm_disable_sspi, default: false
|
53
53
|
option :winrm_basic_auth_only, default: false
|
54
|
-
option :path, default:
|
54
|
+
option :path, default: "/wsman"
|
55
55
|
option :ssl, default: false
|
56
56
|
option :self_signed, default: false
|
57
57
|
|
@@ -93,21 +93,21 @@ module Train::Transports
|
|
93
93
|
super(opts)
|
94
94
|
|
95
95
|
# set scheme and port based on ssl activation
|
96
|
-
scheme = opts[:ssl] ?
|
96
|
+
scheme = opts[:ssl] ? "https" : "http"
|
97
97
|
port = opts[:port]
|
98
98
|
port = (opts[:ssl] ? 5986 : 5985) if port.nil?
|
99
99
|
winrm_transport = opts[:winrm_transport].to_sym
|
100
100
|
unless SUPPORTED_WINRM_TRANSPORTS.include?(winrm_transport)
|
101
|
-
|
101
|
+
raise Train::ClientError, "Unsupported transport type: #{winrm_transport.inspect}"
|
102
102
|
end
|
103
103
|
|
104
104
|
# remove leading '/'
|
105
|
-
path = (opts[:path] ||
|
105
|
+
path = (opts[:path] || "").sub(%r{^/+}, "")
|
106
106
|
|
107
107
|
opts[:endpoint] = "#{scheme}://#{opts[:host]}:#{port}/#{path}"
|
108
108
|
end
|
109
109
|
|
110
|
-
WINRM_FS_SPEC_VERSION =
|
110
|
+
WINRM_FS_SPEC_VERSION = "~> 1.0".freeze
|
111
111
|
|
112
112
|
# Builds the hash of options needed by the Connection object on
|
113
113
|
# construction.
|
@@ -117,23 +117,23 @@ module Train::Transports
|
|
117
117
|
# @api private
|
118
118
|
def connection_options(opts)
|
119
119
|
{
|
120
|
-
logger:
|
121
|
-
transport:
|
122
|
-
disable_sspi:
|
123
|
-
basic_auth_only:
|
124
|
-
hostname:
|
125
|
-
endpoint:
|
126
|
-
user:
|
127
|
-
password:
|
128
|
-
rdp_port:
|
129
|
-
connection_retries:
|
130
|
-
connection_retry_sleep:
|
131
|
-
max_wait_until_ready:
|
120
|
+
logger: logger,
|
121
|
+
transport: opts[:winrm_transport].to_sym,
|
122
|
+
disable_sspi: opts[:winrm_disable_sspi],
|
123
|
+
basic_auth_only: opts[:winrm_basic_auth_only],
|
124
|
+
hostname: opts[:host],
|
125
|
+
endpoint: opts[:endpoint],
|
126
|
+
user: opts[:user],
|
127
|
+
password: opts[:password],
|
128
|
+
rdp_port: opts[:rdp_port],
|
129
|
+
connection_retries: opts[:connection_retries],
|
130
|
+
connection_retry_sleep: opts[:connection_retry_sleep],
|
131
|
+
max_wait_until_ready: opts[:max_wait_until_ready],
|
132
132
|
no_ssl_peer_verification: opts[:self_signed],
|
133
|
-
realm:
|
134
|
-
service:
|
135
|
-
ca_trust_path:
|
136
|
-
ssl_peer_fingerprint:
|
133
|
+
realm: opts[:kerberos_realm],
|
134
|
+
service: opts[:kerberos_service],
|
135
|
+
ca_trust_path: opts[:ca_trust_path],
|
136
|
+
ssl_peer_fingerprint: opts[:ssl_peer_fingerprint],
|
137
137
|
}
|
138
138
|
end
|
139
139
|
|
@@ -156,24 +156,24 @@ module Train::Transports
|
|
156
156
|
# (see Base#load_needed_dependencies!)
|
157
157
|
def load_needed_dependencies!
|
158
158
|
spec_version = WINRM_FS_SPEC_VERSION.dup
|
159
|
-
logger.debug(
|
159
|
+
logger.debug("winrm-fs requested," \
|
160
160
|
" loading WinRM::FS gem (#{spec_version})")
|
161
|
-
gem
|
162
|
-
first_load = require
|
161
|
+
gem "winrm-fs", spec_version
|
162
|
+
first_load = require "winrm-fs"
|
163
163
|
load_winrm_transport!
|
164
164
|
|
165
165
|
if first_load
|
166
|
-
logger.debug(
|
166
|
+
logger.debug("WinRM::FS library loaded")
|
167
167
|
else
|
168
|
-
logger.debug(
|
168
|
+
logger.debug("WinRM::FS previously loaded")
|
169
169
|
end
|
170
170
|
rescue LoadError => e
|
171
171
|
logger.fatal(
|
172
172
|
"The `winrm-fs' gem is missing and must" \
|
173
|
-
|
173
|
+
" be installed or cannot be properly activated. Run" \
|
174
174
|
" `gem install winrm-fs --version '#{spec_version}'`" \
|
175
|
-
|
176
|
-
" `gem 'winrm-fs', '#{spec_version}'`."
|
175
|
+
" or add the following to your Gemfile if you are using Bundler:" \
|
176
|
+
" `gem 'winrm-fs', '#{spec_version}'`."
|
177
177
|
)
|
178
178
|
raise Train::UserError,
|
179
179
|
"Could not load or activate WinRM::FS (#{e.message})"
|
@@ -183,7 +183,7 @@ module Train::Transports
|
|
183
183
|
#
|
184
184
|
# @api private
|
185
185
|
def load_winrm_transport!
|
186
|
-
silence_warnings { require
|
186
|
+
silence_warnings { require "winrm-fs" }
|
187
187
|
end
|
188
188
|
|
189
189
|
# Return the last saved WinRM connection instance.
|
@@ -49,7 +49,7 @@ class Train::Transports::WinRM
|
|
49
49
|
|
50
50
|
# (see Base::Connection#login_command)
|
51
51
|
def login_command
|
52
|
-
case RbConfig::CONFIG[
|
52
|
+
case RbConfig::CONFIG["host_os"]
|
53
53
|
when /darwin/
|
54
54
|
login_command_for_mac
|
55
55
|
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
@@ -57,7 +57,7 @@ class Train::Transports::WinRM
|
|
57
57
|
when /linux/
|
58
58
|
login_command_for_linux
|
59
59
|
else
|
60
|
-
|
60
|
+
raise ActionFailed,
|
61
61
|
"Remote login not supported in #{self.class} " \
|
62
62
|
"from host OS '#{RbConfig::CONFIG['host_os']}'."
|
63
63
|
end
|
@@ -79,7 +79,7 @@ class Train::Transports::WinRM
|
|
79
79
|
delay = 3
|
80
80
|
session(
|
81
81
|
retry_limit: @max_wait_until_ready / delay,
|
82
|
-
retry_delay: delay
|
82
|
+
retry_delay: delay
|
83
83
|
)
|
84
84
|
run_command_via_connection(PING_COMMAND.dup)
|
85
85
|
end
|
@@ -99,7 +99,7 @@ class Train::Transports::WinRM
|
|
99
99
|
def run_command_via_connection(command, &data_handler)
|
100
100
|
return if command.nil?
|
101
101
|
logger.debug("[WinRM] #{self} (#{command})")
|
102
|
-
out =
|
102
|
+
out = ""
|
103
103
|
|
104
104
|
response = session.run(command) do |stdout, _|
|
105
105
|
yield(stdout) if data_handler && stdout
|
@@ -119,7 +119,7 @@ class Train::Transports::WinRM
|
|
119
119
|
host = URI.parse(options[:endpoint]).host
|
120
120
|
content = [
|
121
121
|
"full address:s:#{host}:#{@rdp_port}",
|
122
|
-
|
122
|
+
"prompt for credentials:i:1",
|
123
123
|
"username:s:#{options[:user]}",
|
124
124
|
].join("\n")
|
125
125
|
|
@@ -145,10 +145,10 @@ class Train::Transports::WinRM
|
|
145
145
|
# @return [LoginCommand] a login command
|
146
146
|
# @api private
|
147
147
|
def login_command_for_linux
|
148
|
-
args = %W
|
149
|
-
args += %W
|
150
|
-
args += %W
|
151
|
-
LoginCommand.new(
|
148
|
+
args = %W{ -u #{options[:user]} }
|
149
|
+
args += %W{ -p #{options[:pass]} } if options.key?(:pass)
|
150
|
+
args += %W{ #{URI.parse(options[:endpoint]).host}:#{@rdp_port} }
|
151
|
+
LoginCommand.new("rdesktop", args)
|
152
152
|
end
|
153
153
|
|
154
154
|
# Builds a `LoginCommand` for use by Mac-based platforms.
|
@@ -156,7 +156,7 @@ class Train::Transports::WinRM
|
|
156
156
|
# @return [LoginCommand] a login command
|
157
157
|
# @api private
|
158
158
|
def login_command_for_mac
|
159
|
-
LoginCommand.new(
|
159
|
+
LoginCommand.new("open", rdp_doc(mac: true))
|
160
160
|
end
|
161
161
|
|
162
162
|
# Builds a `LoginCommand` for use by Windows-based platforms.
|
@@ -164,7 +164,7 @@ class Train::Transports::WinRM
|
|
164
164
|
# @return [LoginCommand] a login command
|
165
165
|
# @api private
|
166
166
|
def login_command_for_windows
|
167
|
-
LoginCommand.new(
|
167
|
+
LoginCommand.new("mstsc", rdp_doc)
|
168
168
|
end
|
169
169
|
|
170
170
|
# Establishes a remote shell session, or establishes one when invoked
|
@@ -193,7 +193,7 @@ class Train::Transports::WinRM
|
|
193
193
|
# @api private
|
194
194
|
def to_s
|
195
195
|
options_to_print = @options.clone
|
196
|
-
options_to_print[:password] =
|
196
|
+
options_to_print[:password] = "<hidden>" if options_to_print.key?(:password)
|
197
197
|
"#{@username}@#{@hostname}<#{options_to_print.inspect}>"
|
198
198
|
end
|
199
199
|
end
|
data/lib/train/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|