train 2.0.12 → 2.1.0

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: b864f7e732e0a08d245b288c18f5df9a10696c6e2979473d54909ca84a79ce67
4
- data.tar.gz: 00a31194954f447b75e01b77df706f8839fca54eed741a2a3937b8919cdafd22
3
+ metadata.gz: 90606b9da5cf017c956f327cb396f116ff8ad54ef0de4784468c72f9506f0b00
4
+ data.tar.gz: 2e81ee280b43149f6de7961bb1526e15755b28579701a0f5375e1a6c4d579d23
5
5
  SHA512:
6
- metadata.gz: 50d8ba9889bd642223c7cde279aff18646fd6130066c57318ed9e1c127ce1b91192b616fe366d6623fb21dc1690e3ed141da1d798cbcb2afade8a4eb451dfa5a
7
- data.tar.gz: 7b527da5c001a7363f13154f5c6c1be0398e2abe4b57a0e6989e2b554194f5c8f20b7ba4932212544accbb5655ba62716f013044a2abea9bd14ce972e04fc5d5
6
+ metadata.gz: 10d9080f2d815d036875196894b81696e2db49dd3104f9942a95d1864b8721b226ae78f82934a41f80c032aae599f6a73ecaaeefc52decc6d66403ec459a7eae
7
+ data.tar.gz: f38b76b0c269fe39ca22b3d2a4324b3f7026eb0e5121c5ff7e8270cab47571c41bc6a741f78fd15eef1c9a257f75f055e80ce9264f47bda0a185336c5bac35b8
@@ -121,8 +121,45 @@ module Train::Extras
121
121
  end
122
122
  end
123
123
 
124
+ # Wrap windows commands.
125
+ class WindowsCommand < CommandWrapperBase
126
+ Train::Options.attach(self)
127
+
128
+ option :shell_command, default: nil
129
+
130
+ def initialize(backend, options)
131
+ @backend = backend
132
+ validate_options(options)
133
+
134
+ @shell_command = options[:shell_command] # e.g. 'powershell'
135
+ end
136
+
137
+ # (see CommandWrapperBase::run)
138
+ def run(command)
139
+ powershell_wrap(command)
140
+ end
141
+
142
+ private
143
+
144
+ # Wrap the cmd in an encoded command to allow pipes and quotes
145
+ def powershell_wrap(cmd)
146
+ shell = @shell_command || 'powershell'
147
+
148
+ # Prevent progress stream from leaking into stderr
149
+ script = "$ProgressPreference='SilentlyContinue';" + cmd
150
+
151
+ # Encode script so PowerShell can use it
152
+ script = script.encode('UTF-16LE', 'UTF-8')
153
+ base64_script = Base64.strict_encode64(script)
154
+
155
+ cmd = "#{shell} -NoProfile -EncodedCommand #{base64_script}"
156
+ cmd
157
+ end
158
+ end
159
+
124
160
  class CommandWrapper
125
161
  include_options LinuxCommand
162
+ include_options WindowsCommand
126
163
 
127
164
  def self.load(transport, options)
128
165
  if transport.os.unix?
@@ -134,6 +171,9 @@ module Train::Extras
134
171
  raise Train::UserError.new("Sudo failed: #{msg}", reason)
135
172
  end
136
173
  res
174
+ elsif transport.os.windows?
175
+ res = WindowsCommand.new(transport, options)
176
+ res
137
177
  end
138
178
  end
139
179
  end
@@ -3,7 +3,8 @@
3
3
  module Train::Platforms::Detect::Helpers
4
4
  module Windows
5
5
  def detect_windows
6
- res = @backend.run_command('cmd /c ver')
6
+ # try to detect windows, use cmd.exe to also support Microsoft OpenSSH
7
+ res = @backend.run_command('cmd.exe /c ver')
7
8
  return false if res.exit_status != 0 or res.stdout.empty?
8
9
 
9
10
  # if the ver contains `Windows`, we know its a Windows system
@@ -25,6 +25,11 @@ module Train::Platforms::Detect::Specifications
25
25
  is_windows = true if ruby_host_os(/mswin|mingw32|windows/)
26
26
  end
27
27
 
28
+ # Try to detect windows even for ssh transport
29
+ if !is_windows && detect_windows == true
30
+ is_windows = true
31
+ end
32
+
28
33
  is_windows
29
34
  }
30
35
  # windows platform
@@ -46,7 +46,8 @@ class Train::Transports::SSH
46
46
  # This verifies we are not in privileged exec mode before running the
47
47
  # enable command. Otherwise, the password will be in history.
48
48
  if run_command_via_connection('show privilege').stdout.split[-1] != '15'
49
- run_command_via_connection("enable\r\n#{@enable_password}")
49
+ # Extra newlines to get back to prompt if incorrect password is used
50
+ run_command_via_connection("enable\n#{@enable_password}\n\n\n")
50
51
  end
51
52
  end
52
53
 
@@ -65,7 +66,9 @@ class Train::Transports::SSH
65
66
 
66
67
  logger.debug('[SSH] waiting for prompt')
67
68
  until @buf =~ @prompt
68
- raise BadEnablePassword if @buf =~ /Bad secrets/
69
+ if @buf =~ /Bad (secrets|password)|Access denied/
70
+ raise BadEnablePassword
71
+ end
69
72
  session.connection.process(0)
70
73
  end
71
74
 
@@ -202,6 +202,8 @@ class Train::Transports::SSH
202
202
  Train::File::Remote::Unix.new(self, path)
203
203
  elsif os[:name] == 'qnx'
204
204
  Train::File::Remote::Qnx.new(self, path)
205
+ elsif os.windows?
206
+ Train::File::Remote::Windows.new(self, path)
205
207
  else
206
208
  Train::File::Remote::Linux.new(self, path)
207
209
  end
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '2.0.12'.freeze
6
+ VERSION = '2.1.0'.freeze
7
7
  end
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.0.12
4
+ version: 2.1.0
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-04-23 00:00:00.000000000 Z
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json