chef-powershell 2.18.6 → 3.0.31

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: f019aa6ec88c30ebe38c6a43aa2200421ba37f6d0b8205cbd58ddccec496f8e8
4
- data.tar.gz: 313478b0ad0850b795de5cf0a54db8a970341b5f8fa06ca39c030cf9135dc82f
3
+ metadata.gz: 1b3d7d0cfcea3798ced68ae7efb8bbf974bedca98336133a44aa48f1f429a83f
4
+ data.tar.gz: 15354f61587a5fa79873f22a59c33396cbf4b0aca1790666df6a21b428d9614b
5
5
  SHA512:
6
- metadata.gz: 3e5be4e69ae8804a3eebabbcbf0dd1b39079e28b17d42f6085d67f6832ac0cc52285753fa87109688dd96b79bc4410b3f8b2e2e836b1659aae73a62c3d997b3c
7
- data.tar.gz: 5b6952643227ac0dfa25b5818288e5dfed465e871e842d618a46636dd2702153531715fe80f86c0cbebc0d22ba2cd0dc583a537b205f8d2a845e7d91f5a59f8e
6
+ metadata.gz: 97b0985a8a3e12d49310634e7bf72cbac989cf8608bdb33149117821fba20b929e8dc49bc184deadfda68cbd7a5deb1972d07d24377119965bec782fcd5fe735
7
+ data.tar.gz: 4705dbe0a51917b216a6acfe844389f5bc03b4d11d2840ecaa866ec53e7519c86346aec6bcfc8254f4264ef849f1026834d8ad85c39a77b600a12d613dfa81b9
@@ -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.4"
21
+ spec.add_runtime_dependency "ffi-yajl", "~> 2.2.4"
22
22
 
23
23
  spec.metadata = {
24
24
  "bug_tracker_uri" => "https://github.com/chef/chef/issues",
@@ -64,10 +64,6 @@ 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
-
71
67
  extend FFI::Library
72
68
  # FFI requires attaching to modules, not classes, so we need to
73
69
  # have a module here. The module level variables *could* be refactored
@@ -76,30 +72,17 @@ class ChefPowerShell
76
72
  @@ps_command = ""
77
73
  @@ps_timeout = -1
78
74
 
79
- StoreResultCallback = FFI::Function.new(:bool, [: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
- begin
83
- @result_string = data.get_bytes(0, size).force_encoding("UTF-16LE").encode("UTF-8")
84
- @hashed_outcome = FFI_Yajl::Parser.parse(@result_string)
85
- @result = FFI_Yajl::Parser.parse(@hashed_outcome["result"])
86
- @errors = @hashed_outcome["errors"]
87
- @verbose = @hashed_outcome["verbose"]
88
- true
89
- rescue NoMethodError, FFI_Yajl::ParseError => e
90
- @retry_count += 1
91
- # capture exception so that it can be raised later, since otherwise
92
- # we will be raising back to C++.
93
- @exception = e
94
- return true if @retry_count > 3
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
102
- end
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
103
86
  end
104
87
 
105
88
  def self.set_ps_dll(value)
@@ -115,12 +98,10 @@ class ChefPowerShell
115
98
  end
116
99
 
117
100
  def self.do_work
118
- @exception = nil
119
- @retry_count = 0
120
101
  ffi_lib @@powershell_dll
121
102
  attach_function :execute_powershell, :ExecuteScript, %i{string int pointer}, :pointer
122
103
 
123
- execute_powershell(@@ps_command, @@ps_timeout, StoreResultCallback)
104
+ execute_powershell(@@ps_command, @@ps_timeout, AllocateCallback)
124
105
  end
125
106
  end
126
107
 
@@ -136,10 +117,13 @@ class ChefPowerShell
136
117
 
137
118
  PowerMod.set_ps_command(script)
138
119
  execution = PowerMod.do_work
139
- raise PowerMod.exception if PowerMod.exception
140
- @result = PowerMod.result
141
- @errors = PowerMod.errors
142
- @verbose = PowerMod.verbose
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
143
127
  end
144
128
  end
145
129
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module ChefPowerShellModule
18
18
  CHEFPOWERSHELL_ROOT = File.expand_path("..", __dir__)
19
- VERSION = "2.18.6".freeze
19
+ VERSION = "3.0.31".freeze
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: 2.18.6
4
+ version: 3.0.31
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-07-11 00:00:00.000000000 Z
11
+ date: 2023-07-14 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.4'
33
+ version: 2.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.4'
40
+ version: 2.2.4
41
41
  description:
42
42
  email:
43
43
  - oss@chef.io