train-core 2.0.12 → 2.1.0

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: 6428f10f1fcb461fff9d6a262ed8a8c643ca0aaf21cc60a0ddeff1573f4e3c0e
4
- data.tar.gz: a1d8450b00960078fb2116ec40dd3f1e61a5976a4aa6aa14e4c0a3e73596f27b
3
+ metadata.gz: 5f219653ce1764d525f68ee34a5a0fe84bed8c76b8fd28fd05d01b5cbef33200
4
+ data.tar.gz: bcce1e0cf610ee3e765b8a4a9bfad310a7baebe54578d133b3a8b242314521ec
5
5
  SHA512:
6
- metadata.gz: 338cd5ee7abda4182c71c3132336b647ab5353d90934673fdf156577506167e109e557b6c139288b5dcc89476742a34eb692b95bfd99ad7159775f531f90c3ee
7
- data.tar.gz: d15361a0bc4362272ea783c5198dea4ef6dbb5beb1a3878e04eb4484126f0b5daa2fdb0dbe725b5828da9cf48519f3d43730860a5a4e7de3ceaac7284b13f765
6
+ metadata.gz: 4f2ab55ffe10956e5133cc6863138c514a4e21d75ecfc7ecb0f6b1ac002426be11b859b2f9a2d6c2da045a4d4720829610abccc993586c6e5d9e25aff31c09f7
7
+ data.tar.gz: 7cf6b5888e1cf3cc4f757736fa4f623d4e525fa45bd91f893e26ae049b915ee6522fd8109cfd8752632c29ce57a7d5a84b297f878f45a30bdbe016ab573d3809
@@ -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-core
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