train-core 3.5.4 → 3.5.5

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: 42c74943ab6ac7282ce80dc0ba284dde6552262b4309015e58bbe71a9864bb8a
4
- data.tar.gz: 6aa5084e8141a4a47b5ced46793a163871ea3e2712882422d2e124daf7e8da3d
3
+ metadata.gz: dbe3fad014697c3f0a1d5fb5d3f4ff422f9e552362179f72019f7c2f9784f975
4
+ data.tar.gz: 337a74095aa5e41b4dd4f24ba2e41857190161a035c2adaf809617205525e442
5
5
  SHA512:
6
- metadata.gz: 39c6dc8ba54238f20aa45982a3153dc6df1dc203d2e2345b4a03246463b3d1bbd8ff332c9da1fc9c5f751373d0ccdea92a42737cf384f3bf240b7c28890180f6
7
- data.tar.gz: efd9e6b920b5a800df45d907f6440829e6639eb6e2f37084a4426724708042c231e7538976be3920dff180559543aa6bb68620445b11fd9c3126470411e17e8d
6
+ metadata.gz: a066352b95be252da1de517176e98fe67804484bfb7f9371a23762b04a5050e7a3a7ca814eb27c773c5b23e7eb85a6eb26fd251df67bfd25c500e34a1075f7dc
7
+ data.tar.gz: fdfa95f6c1278dd04760e5dface6b4feacac3d0dd2b77f8844215d6f9b17760967afa482181415368fd8c3ca869e697e205c5abd45913e6cbfb12dcfc93044c1
@@ -86,9 +86,9 @@ module Train::Transports
86
86
  end
87
87
  end
88
88
 
89
- def run_command_via_connection(cmd, &_data_handler)
89
+ def run_command_via_connection(cmd, opts, &_data_handler)
90
90
  # Use the runner if it is available
91
- return @runner.run_command(cmd) if defined?(@runner)
91
+ return @runner.run_command(cmd, opts) if defined?(@runner)
92
92
 
93
93
  # If we don't have a runner, such as at the beginning of setting up the
94
94
  # transport and performing the first few steps of OS detection, fall
@@ -115,13 +115,18 @@ module Train::Transports
115
115
  @cmd_wrapper = Local::CommandWrapper.load(connection, options)
116
116
  end
117
117
 
118
- def run_command(cmd)
118
+ def run_command(cmd, opts = {})
119
119
  if defined?(@cmd_wrapper) && !@cmd_wrapper.nil?
120
120
  cmd = @cmd_wrapper.run(cmd)
121
121
  end
122
122
 
123
123
  res = Mixlib::ShellOut.new(cmd)
124
- res.run_command
124
+ res.timeout = opts[:timeout]
125
+ begin
126
+ res.run_command
127
+ rescue Mixlib::ShellOut::CommandTimeout
128
+ raise Train::CommandTimeoutReached
129
+ end
125
130
  Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
126
131
  end
127
132
 
@@ -138,7 +143,7 @@ module Train::Transports
138
143
  @powershell_cmd = powershell_cmd
139
144
  end
140
145
 
141
- def run_command(script)
146
+ def run_command(script, opts)
142
147
  # Prevent progress stream from leaking into stderr
143
148
  script = "$ProgressPreference='SilentlyContinue';" + script
144
149
 
@@ -149,7 +154,12 @@ module Train::Transports
149
154
  cmd = "#{@powershell_cmd} -NoProfile -EncodedCommand #{base64_script}"
150
155
 
151
156
  res = Mixlib::ShellOut.new(cmd)
152
- res.run_command
157
+ res.timeout = opts[:timeout]
158
+ begin
159
+ res.run_command
160
+ rescue Mixlib::ShellOut::CommandTimeout
161
+ raise Train::CommandTimeoutReached
162
+ end
153
163
  Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
154
164
  end
155
165
 
@@ -176,9 +186,10 @@ module Train::Transports
176
186
  # A command that succeeds without setting an exit code will have exitstatus 0
177
187
  # A command that exits with an exit code will have that value as exitstatus
178
188
  # A command that fails (e.g. throws exception) before setting an exit code will have exitstatus 1
179
- def run_command(cmd)
189
+ def run_command(cmd, _opts)
180
190
  script = "$ProgressPreference='SilentlyContinue';" + cmd
181
191
  encoded_script = Base64.strict_encode64(script)
192
+ # TODO: no way to safely implement timeouts here.
182
193
  @pipe.puts(encoded_script)
183
194
  @pipe.flush
184
195
  res = OpenStruct.new(JSON.parse(Base64.decode64(@pipe.readline)))
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.5.4".freeze
5
+ VERSION = "3.5.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.5.4
4
+ version: 3.5.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-03-15 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable