winrm-transport 1.0.1 → 1.0.2

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
  SHA1:
3
- metadata.gz: ed77e7070e00d3297d006565411a84fa4c7599b9
4
- data.tar.gz: 0d6ae6a15fb437ed6bb691cc937fe0d5125b08d2
3
+ metadata.gz: 66b0b892802274668ed50e030ce87b881beb8ed5
4
+ data.tar.gz: 8d8706354672deab32c49a2df17d9e8f3b9b2d79
5
5
  SHA512:
6
- metadata.gz: 34d86ef488009afa559bed219b460745f2b74838b94eff8aca67ed225dd8ac1c84f65f56a18ac9a10e908b25cc7db9b039494f36d3c53da07195c470a1b78a9a
7
- data.tar.gz: 12891bec59e93d70c6d0b85e9d368c3a2598977a9200c16fd86fb85390d7835f1b2b9e2df07db6131d29a236d0ffa86a81b57c67b3ccd4294a24c5db1c1548bf
6
+ metadata.gz: b5bf53cacd7076b98987a99521a8882a57cade93b7433bb429ddecf5f49143cff19f559d90d10698a430a4e5e131c3e007eb233e73f168f38727dc52dfc5ab8d
7
+ data.tar.gz: 4d31347e809699128cc47348c59c901fcd07b4b1f7def0150bf46fff499030e4e97048ef3955b9bd2fd9ad5e0cf509840327f10c7cef0eb5436007220e709ba7
@@ -1,3 +1,14 @@
1
+ ## 1.0.2 / 2015-06-24
2
+
3
+ ### Bug fixes
4
+
5
+ * Pull request [#8][]: Fix unzipping from COM, fix failed single file copies (when parent directory was not present), adding more tests around decode_files.ps1, cleaner error output. ([@smurawski][], [@xmik][])
6
+
7
+ ### Improvements
8
+
9
+ * Pull request [#10][]: Fix winrm-transport/issues link in README.md. ([@hh][])
10
+
11
+
1
12
  ## 1.0.1 / 2015-05-20
2
13
 
3
14
  ### Bug fixes
@@ -18,6 +29,10 @@ The initial release.
18
29
  [#4]: https://github.com/test-kitchen/winrm-transport/issues/4
19
30
  [#5]: https://github.com/test-kitchen/winrm-transport/issues/5
20
31
  [#6]: https://github.com/test-kitchen/winrm-transport/issues/6
32
+ [#8]: https://github.com/test-kitchen/winrm-transport/issues/8
33
+ [#10]: https://github.com/test-kitchen/winrm-transport/issues/10
21
34
  [@fnichol]: https://github.com/fnichol
35
+ [@hh]: https://github.com/hh
22
36
  [@jmccann]: https://github.com/jmccann
23
37
  [@smurawski]: https://github.com/smurawski
38
+ [@xmik]: https://github.com/xmik
data/README.md CHANGED
@@ -73,7 +73,7 @@ Apache License, Version 2.0 (see [LICENSE.txt][license])
73
73
  [contributors]: https://github.com/test-kitchen/winrm-transport/graphs/contributors
74
74
  [file_transporter]: https://github.com/test-kitchen/winrm-transport/blob/master/lib/winrm/transport/file_transporter.rb
75
75
  [fnichol]: https://github.com/fnichol
76
- [issues]: https://github.com/test-kitchen/winrm-transpor/issues
76
+ [issues]: https://github.com/test-kitchen/winrm-transport/issues
77
77
  [license]: https://github.com/test-kitchen/winrm-transport/blob/master/LICENSE.txt
78
78
  [repo]: https://github.com/test-kitchen/winrm-transport
79
79
  [semver]: http://semver.org/
@@ -252,8 +252,8 @@ module WinRM
252
252
  vars = %{$hash_file = "#{hash_file}"\n}
253
253
 
254
254
  output = service.run_powershell_script(
255
- [vars,
256
- ". #{decode_files_script}",
255
+ ["#{decode_files_script}",
256
+ vars,
257
257
  "Decode-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation"
258
258
  ].join("\n")
259
259
  )
@@ -348,6 +348,20 @@ module WinRM
348
348
  " " * depth
349
349
  end
350
350
 
351
+ # Parses CLIXML String into regular String (without any XML syntax).
352
+ # Inspired by https://github.com/WinRb/WinRM/issues/106.
353
+ #
354
+ # @param clixml [String] clixml text
355
+ # @return [String] parsed clixml into String
356
+ def clixml_to_s(clixml)
357
+ doc = REXML::Document.new(clixml)
358
+ text = doc.get_elements("//S").map(&:text).join
359
+ text.gsub(/_x(\h\h\h\h)_/) do
360
+ code = Regexp.last_match[1]
361
+ code.hex.chr
362
+ end
363
+ end
364
+
351
365
  # Parses response of a PowerShell script or CMD command which contains
352
366
  # a CSV-formatted document in the standard output stream.
353
367
  #
@@ -356,10 +370,24 @@ module WinRM
356
370
  # @return [Hash] report hash, keyed by the local MD5 digest
357
371
  # @api private
358
372
  def parse_response(output)
359
- if output[:exitcode] != 0
373
+ exitcode = output[:exitcode]
374
+ stderr = output.stderr
375
+ if stderr.include?("The command line is too long")
376
+ # The powershell script which should result in `output` parameter
377
+ # is too long, remove some newlines, comments, etc from it.
378
+ raise StandardError, "The command line is too long" \
379
+ " (powershell script is too long)"
380
+ end
381
+ pretty_stderr = clixml_to_s(stderr)
382
+
383
+ if exitcode != 0
360
384
  raise FileTransporterFailed, "[#{self.class}] Upload failed " \
361
- "(exitcode: #{output[:exitcode]})\n#{output.stderr}"
385
+ "(exitcode: #{exitcode})\n#{pretty_stderr}"
386
+ elsif stderr != '\r\n' && stderr != ""
387
+ raise FileTransporterFailed, "[#{self.class}] Upload failed " \
388
+ "(exitcode: 0), but stderr present\n#{pretty_stderr}"
362
389
  end
390
+
363
391
  array = CSV.parse(output.stdout, :headers => true).map(&:to_hash)
364
392
  array.each { |h| h.each { |key, value| h[key] = nil if value == "" } }
365
393
  Hash[array.map { |entry| [entry.fetch("src_md5"), entry] }]
@@ -20,6 +20,6 @@ module WinRM
20
20
 
21
21
  module Transport
22
22
 
23
- VERSION = "1.0.1"
23
+ VERSION = "1.0.2"
24
24
  end
25
25
  end
@@ -1,50 +1,52 @@
1
- Function Cleanup($o) { if (($o) -and ($o.GetType().GetMethod("Dispose") -ne $null)) { $o.Dispose() } }
2
- Function Decode-Base64File($src, $dst) {set-content -Encoding Byte -Path $dst -Value ([Convert]::FromBase64String([IO.File]::ReadAllLines($src)))}
3
- Function Copy-Stream($src, $dst) { $b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
1
+ trap {$e = $_.Exception; $e.InvocationInfo.ScriptName; do {$e.Message; $e = $e.InnerException} while ($e); break;}
2
+ $progresspreference = 'SilentlyContinue'
3
+ function Decode-Base64File($src, $dst) {folder (split-path $dst);sc -force -Encoding Byte -Path $dst -Value ([Convert]::FromBase64String([IO.File]::ReadAllLines($src)))}
4
+ function Copy-Stream($src, $dst) {$b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
4
5
  function Resolve-ProviderPath{ $input | % {if ($_){(Resolve-Path $_).ProviderPath} else{$null}} }
5
- Function Release-COM($o) { if ($o -ne $null) { [void][Runtime.Interopservices.Marshal]::ReleaseComObject($o) } }
6
- function Test-NETStack($Version, $r = 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4') { [bool]("$r\Full", "$r\Client" | ? {(gp $_).Version -like "$($Version)*"}) }
6
+ function Get-FrameworkVersion { "Full", "Client" | % {([version](gp "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\$_").Version)} | select -first 1}
7
+ function Test-NETStack($Version){ Get-FrameworkVersion -ge $Version }
7
8
  function Test-IOCompression {($PSVersionTable.PSVersion.Major -ge 3) -and (Test-NETStack '4.5')}
9
+ function folder($path){ $path | ? {-not (test-path $_)} | % {$null = mkdir $_}}
10
+ function disposable($o){($o -is [IDisposable]) -and (($o | gm | %{$_.name}) -contains 'Dispose')}
11
+ function use($obj, [scriptblock]$sb){try {& $sb} catch [exception]{throw $_} finally {if (disposable $obj) {$obj.Dispose()}} }
8
12
  set-alias RPP -Value Resolve-ProviderPath
9
13
 
10
14
  Function Decode-Files($hash) {
11
15
  foreach ($key in $hash.keys) {
12
16
  $value = $hash[$key]
13
17
  $tmp, $tzip, $dst = $Key, $Value["tmpzip"], $Value["dst"]
14
- $sMd5 = (Get-Item $tmp).BaseName.Replace("b64-", "")
18
+ $sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
15
19
  $decoded = if ($tzip -ne $null) { $tzip } else { $dst }
16
20
  Decode-Base64File $tmp $decoded
17
- Remove-Item $tmp -Force
21
+ rm $tmp -Force
18
22
  $dMd5 = Get-MD5Sum $decoded
19
23
  $verifies = $sMd5 -like $dMd5
20
- if ($tzip) {Unzip-File $tzip $dst;Remove-Item $tzip -Force}
21
- New-Object psobject -Property @{ dst = $dst; verifies = $verifies; src_md5 = $sMd5; dst_md5 = $dMd5; tmpfile = $tmp; tmpzip = $tzip }
24
+ if ($tzip) {Unzip-File $tzip $dst;rm $tzip -Force}
25
+ New-Object psobject -Property @{dst=$dst;verifies=$verifies;src_md5=$sMd5;dst_md5=$dMd5;tmpfile=$tmp;tmpzip=$tzip}
22
26
  }
23
27
  }
24
28
 
25
29
  Function Get-MD5Sum($src) {
26
- Try {
27
- $c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider
28
- $bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
29
- ([BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
30
- } catch [exception]{throw $_} finally { Cleanup $c; Cleanup $in }
30
+ if ($src -and (test-path $src)) {
31
+ use ($c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider) {
32
+ use ($in = (gi $src).OpenRead()) {([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToLower()}}
33
+ }
31
34
  }
32
35
 
33
36
  Function Invoke-Input($in) {
34
37
  $in = $in | rpp
35
- Decode-Base64File $in ($decoded = "$($in).ps1")
36
- $expr = Get-Content $decoded | Out-String
37
- Remove-Item $in,$decoded -Force
38
- Invoke-Expression "$expr"
38
+ $d = "$($in).ps1"
39
+ Decode-Base64File $in $d
40
+ $expr = gc $d | Out-String
41
+ rm $in,$d -Force
42
+ iex "$expr"
39
43
  }
40
44
 
41
45
  Function Unzip-File($src, $dst) {
42
46
  $unpack = $src -replace '\.zip'
47
+ folder $unpack, $dst
43
48
  if (Test-IOCompression) {Add-Type -AN System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack)}
44
- else {
45
- Try {$s = New-Object -ComObject Shell.Application; ($dp = $s.NameSpace($unpack)).CopyHere(($z = $s.NameSpace($src)).Items(), 0x610)} Finally {Release-Com $s; Release-Com $z; Release-COM $dp}
46
- }
47
- if (-not (test-path $dst)) {$null = mkdir $dst }
49
+ else {Try {$s = New-Object -ComObject Shell.Application; ($s.NameSpace($unpack)).CopyHere(($s.NameSpace($src)).Items(), 0x610)} Finally {[void][Runtime.Interopservices.Marshal]::ReleaseComObject($s)}}
48
50
  dir $unpack | cp -dest "$dst/" -force -recurse
49
51
  rm $unpack -recurse -force
50
52
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: winrm