chef-powershell 2.18.5 → 3.0.30

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: 36453d0835276a228072f5d76630d75a6d3ecc12a5902b0a973427cc12790fe4
4
- data.tar.gz: 19c1a4cb862cda9518f107714dcf6b8f90198339ffb30450391d1aaaa977bcf5
3
+ metadata.gz: 4d93049c98f0e42d1cf2760cf353eb4fb16d0259ff0fec3790e0d1763a835bc4
4
+ data.tar.gz: 2a162dc437e62342bf1fd54fdbf5d0aa82b77047320135c27c40b1672e6d97b5
5
5
  SHA512:
6
- metadata.gz: 342c398f8a5ec0259b6c4552708067cf3ecaa38c4f5fbdd0224ca0aa7ac0956b9e9c5740d854e39d7218173cd04d5202f3fc590fc64a2a2a9bf9adf3ad133419
7
- data.tar.gz: 5c8ca7ceab568a1f95a2233be781ea7367629fd1ac0c98a257bbe18f664e7e3c2eb044a0d3da5078800b1f2a37afa5a24f3f62146ff12a2316af750a26655dc7
6
+ metadata.gz: e13dad4b1a55c8af3bcdffdc0728ccd4bea6eeaa1d75cd17d3d3f1cffb2bb5393c42fa3f8138c2c4258f54d7ef7d66187d6a5433d77f46042db880b2577f4ce4
7
+ data.tar.gz: 4008e7bf79b9df4de1cc06facb61a9938cdddff1903880df37b3af3ba81cf01e2a99d00d13e11e1e1f84e49231bd2bab34d3dc8c2947ae81f43592c678499268
@@ -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", "~> 3.0"
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,26 +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
- @result_string = data.get_bytes(0, size).force_encoding("UTF-16LE").encode("UTF-8").bytes.reverse.drop_while {|x| x == 0}.reverse.pack("C*")
85
- @hashed_outcome = FFI_Yajl::Parser.parse(@result_string)
86
- @result = FFI_Yajl::Parser.parse(@hashed_outcome["result"])
87
- @errors = @hashed_outcome["errors"]
88
- @verbose = @hashed_outcome["verbose"]
89
- true
90
- rescue => e
91
- @retry_count += 1
92
- puts "#{e.inspect}"
93
- @exception = e
94
- return true if @retry_count > 3
95
- puts "Retrying PowerShell command execution #{@retry_count}"
96
- sleep 1
97
- false
98
- 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
99
86
  end
100
87
 
101
88
  def self.set_ps_dll(value)
@@ -111,12 +98,10 @@ class ChefPowerShell
111
98
  end
112
99
 
113
100
  def self.do_work
114
- @exception = nil
115
- @retry_count = 0
116
101
  ffi_lib @@powershell_dll
117
102
  attach_function :execute_powershell, :ExecuteScript, %i{string int pointer}, :pointer
118
103
 
119
- execute_powershell(@@ps_command, @@ps_timeout, StoreResultCallback)
104
+ execute_powershell(@@ps_command, @@ps_timeout, AllocateCallback)
120
105
  end
121
106
  end
122
107
 
@@ -132,10 +117,13 @@ class ChefPowerShell
132
117
 
133
118
  PowerMod.set_ps_command(script)
134
119
  execution = PowerMod.do_work
135
- raise PowerMod.exception if PowerMod.exception
136
- @result = PowerMod.result
137
- @errors = PowerMod.errors
138
- @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
139
127
  end
140
128
  end
141
129
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module ChefPowerShellModule
18
18
  CHEFPOWERSHELL_ROOT = File.expand_path("..", __dir__)
19
- VERSION = "2.18.5".freeze
19
+ VERSION = "3.0.30".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.5
4
+ version: 3.0.30
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-13 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: '3.0'
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: '3.0'
41
41
  description:
42
42
  email:
43
43
  - oss@chef.io