chef-powershell 18.0.3 → 18.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: bf6e34db30449b1eeef2a30e24af5d2357839b16ca91163cc8b46fc58d3cb717
4
- data.tar.gz: e9af27d7f4a7c81ee8a43309d75aa7b355417ff850d7ca232d1a601b0c16f544
3
+ metadata.gz: f3943b91db500700d5fa545d1ac204c220f39f105ddffcfb3a9c1c7fa7d4a194
4
+ data.tar.gz: ee94470b0f02a82da5bb63aadefd4411b79398f6591f622d202264cf34a1f7ea
5
5
  SHA512:
6
- metadata.gz: 181b87d2c761fd7f9766dd2265cc49d220bf3340ca1daa5c1adc23f56301563db1f1c4b709d1b0dcd3feef7e61eb6760a5a804f60410ff038d6ba168fcd89484
7
- data.tar.gz: 9008aa802415f63719bb1b3cc0f5ca038959802e01e0a2679ca2cf67409a8ee4710f506f4c3cf60aad3f67f6051d07cdd33067b02da7f15030c1b1f839ef13f2
6
+ metadata.gz: dd20e5f7adb2d459a8f0006a919d220a1a73cb99d75d3c651166053378ffafc1bd2859ac1bd1dcdaba8074e3b84f648d4c786ea1f2789303f05562f78c7a45ab
7
+ data.tar.gz: 9c2419d28ea984490a4263588476a58726d94e1cf6c6d9da985ad649d2711a2a88484a78dd46e1170adf455b4eb4c747b664c6c1be3a0b302cac429e24a9fe8f
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.required_ruby_version = ">= 2.6"
19
19
 
20
20
  spec.add_runtime_dependency "ffi", "~> 1.15"
21
- spec.add_runtime_dependency "ffi-yajl", "~> 2.5"
21
+ spec.add_runtime_dependency "ffi-yajl", "~> 2.4"
22
22
 
23
23
  spec.metadata = {
24
24
  "bug_tracker_uri" => "https://github.com/chef/chef/issues",
@@ -64,6 +64,10 @@ class ChefPowerShell
64
64
  end
65
65
 
66
66
  module PowerMod
67
+ class << self
68
+ attr_accessor :result_string, :retry_count, :exception, :result, :errors, :verbose, :hashed_outcome
69
+ end
70
+
67
71
  extend FFI::Library
68
72
  # FFI requires attaching to modules, not classes, so we need to
69
73
  # have a module here. The module level variables *could* be refactored
@@ -72,17 +76,29 @@ class ChefPowerShell
72
76
  @@ps_command = ""
73
77
  @@ps_timeout = -1
74
78
 
75
- AllocateCallback = FFI::Function.new(:pointer, [:size_t]) do |size|
76
- # Capture the pointer here so that Ruby knows that it is an
77
- # FFI::MemoryPointer that can receive &.free. If you try to
78
- # free the pointer from execute_powershell, Ruby will not have
79
- # access to the type information and will core dump spectacularly.
80
- @@pointer = FFI::MemoryPointer.new(:uchar, size)
81
- end
82
-
83
- def self.free_pointer
84
- @@pointer&.free
85
- @@pointer = nil
79
+ StoreResultCallback = FFI::Function.new(:bool, %i{pointer size_t}) do |data, size|
80
+ # try parsing the result *first* before returning from the function, and if it fails,
81
+ # return false so that the function can be retried from the C++ side.
82
+ @result_string = data.get_bytes(0, size).force_encoding("UTF-16LE").encode("UTF-8")
83
+ @hashed_outcome = FFI_Yajl::Parser.parse(@result_string)
84
+ @result = FFI_Yajl::Parser.parse(@hashed_outcome["result"])
85
+ @errors = @hashed_outcome["errors"]
86
+ @verbose = @hashed_outcome["verbose"]
87
+ true
88
+ rescue NoMethodError, FFI_Yajl::ParseError => e
89
+ @retry_count += 1
90
+ # capture exception so that it can be raised later, since otherwise
91
+ # we will be raising back to C++.
92
+ @exception = e
93
+ return true if @retry_count > 3
94
+
95
+ puts "Retrying PowerShell command execution #{@retry_count}"
96
+ sleep 1
97
+ false
98
+ rescue => e
99
+ # no retry for other exceptions
100
+ @exception = e
101
+ true
86
102
  end
87
103
 
88
104
  def self.set_ps_dll(value)
@@ -98,10 +114,12 @@ class ChefPowerShell
98
114
  end
99
115
 
100
116
  def self.do_work
117
+ @exception = nil
118
+ @retry_count = 0
101
119
  ffi_lib @@powershell_dll
102
120
  attach_function :execute_powershell, :ExecuteScript, %i{string int pointer}, :pointer
103
121
 
104
- execute_powershell(@@ps_command, @@ps_timeout, AllocateCallback)
122
+ execute_powershell(@@ps_command, @@ps_timeout, StoreResultCallback)
105
123
  end
106
124
  end
107
125
 
@@ -117,13 +135,13 @@ class ChefPowerShell
117
135
 
118
136
  PowerMod.set_ps_command(script)
119
137
  execution = PowerMod.do_work
120
- output = execution.read_utf16string
121
- hashed_outcome = FFI_Yajl::Parser.parse(output)
122
- @result = FFI_Yajl::Parser.parse(hashed_outcome["result"])
123
- @errors = hashed_outcome["errors"]
124
- @verbose = hashed_outcome["verbose"]
125
- ensure
126
- PowerMod.free_pointer
138
+ # we returned "true" to escape retry, but we still need to check the
139
+ # exception and raise it if it exists.
140
+ raise PowerMod.exception if PowerMod.exception
141
+
142
+ @result = PowerMod.result
143
+ @errors = PowerMod.errors
144
+ @verbose = PowerMod.verbose
127
145
  end
128
146
  end
129
147
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module ChefPowerShellModule
18
18
  CHEFPOWERSHELL_ROOT = File.expand_path("..", __dir__)
19
- VERSION = "18.0.3".freeze
19
+ VERSION = "18.1.0"
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-powershell
3
3
  version: !ruby/object:Gem::Version
4
- version: 18.0.3
4
+ version: 18.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.5'
33
+ version: '2.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.5'
40
+ version: '2.4'
41
41
  description:
42
42
  email:
43
43
  - oss@chef.io