diff options
author | Thomas Powell <104777878+tpowell-progress@users.noreply.github.com> | 2023-04-04 07:09:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 10:09:50 -0400 |
commit | 7cda1d2d91a752de29aba2920a83a11b4f964be5 (patch) | |
tree | e5783ea9c6d54cc9dc982a1d7d3521d3ce55e933 | |
parent | 6ac6b0a8d561e2125cb651e98475c1fc7b7b3510 (diff) | |
download | chef-7cda1d2d91a752de29aba2920a83a11b4f964be5.tar.gz |
"FFI Yajl" fix (#13662)
* FFI_Yajl fix, remove shadow powershell.rb
* Update to 18.0.1 powershell-shim
Signed-off-by: Thomas Powell <powell@progress.com>
-rw-r--r-- | Gemfile.lock | 8 | ||||
-rw-r--r-- | chef-universal-mingw-ucrt.gemspec | 4 | ||||
-rw-r--r-- | lib/chef/platform/query_helpers.rb | 6 | ||||
-rw-r--r-- | lib/chef/powershell.rb | 81 |
4 files changed, 11 insertions, 88 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 3e364df40a..56d2e5126f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,7 +83,7 @@ PATH aws-sdk-s3 (~> 1.91) aws-sdk-secretsmanager (~> 1.46) chef-config (= 18.2.6) - chef-powershell (~> 1.0.12) + chef-powershell (~> 18.0.0) chef-utils (= 18.2.6) chef-vault chef-zero (>= 14.0.11) @@ -180,7 +180,7 @@ GEM debug_inspector (>= 0.0.1) builder (3.2.4) byebug (11.1.3) - chef-powershell (1.0.13) + chef-powershell (18.0.1) ffi (~> 1.15) ffi-yajl (~> 2.4) chef-telemetry (1.1.1) @@ -288,6 +288,8 @@ GEM mime-types-data (3.2023.0218.1) mixlib-archive (1.1.7) mixlib-log + mixlib-archive (1.1.7-universal-mingw32) + mixlib-log mixlib-authentication (3.0.10) mixlib-cli (2.1.8) mixlib-config (3.0.27) @@ -430,7 +432,7 @@ GEM crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webrick (1.8.1) - win32-api (1.10.1) + win32-api (1.10.1-universal-mingw32) win32-certstore (0.6.15) chef-powershell (>= 1.0.12) ffi diff --git a/chef-universal-mingw-ucrt.gemspec b/chef-universal-mingw-ucrt.gemspec index 2edfd751f9..092492e557 100644 --- a/chef-universal-mingw-ucrt.gemspec +++ b/chef-universal-mingw-ucrt.gemspec @@ -15,9 +15,9 @@ gemspec.add_dependency "wmi-lite", "~> 1.0" gemspec.add_dependency "win32-taskscheduler", "~> 2.0" gemspec.add_dependency "iso8601", ">= 0.12.1", "< 0.14" # validate 0.14 when it comes out gemspec.add_dependency "win32-certstore", "~> 0.6.15" # 0.5+ required for specifying user vs. system store -gemspec.add_dependency "chef-powershell", "~> 1.0.12" # The guts of the powershell_exec code have been moved to its own gem, chef-powershell. It's part of the chef-powershell-shim repo. +gemspec.add_dependency "chef-powershell", "~> 18.0.0" # The guts of the powershell_exec code have been moved to its own gem, chef-powershell. It's part of the chef-powershell-shim repo. gemspec.extensions << "ext/win32-eventlog/Rakefile" gemspec.files += Dir.glob("{distro,ext}/**/*") -gemspec
\ No newline at end of file +gemspec diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb index bd0703d72a..12d5240c24 100644 --- a/lib/chef/platform/query_helpers.rb +++ b/lib/chef/platform/query_helpers.rb @@ -17,11 +17,14 @@ # require "chef-utils" unless defined?(ChefUtils::CANARY) +require_relative "../mixin/powershell_exec" class Chef class Platform class << self + include Chef::Mixin::PowershellExec + def windows? ChefUtils.windows? end @@ -58,8 +61,7 @@ class Chef end def dsc_refresh_mode_disabled?(node) - require_relative "../powershell" - exec = Chef::PowerShell.new("Get-DscLocalConfigurationManager") + exec = powershell_exec!("Get-DscLocalConfigurationManager") exec.error! exec.result["RefreshMode"] == "Disabled" end diff --git a/lib/chef/powershell.rb b/lib/chef/powershell.rb deleted file mode 100644 index 399b631633..0000000000 --- a/lib/chef/powershell.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -# Author:: Stuart Preston (<stuart@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "ffi" unless defined?(FFI) -require_relative "json_compat" - -class Chef - class PowerShell - extend FFI::Library - - attr_reader :result - attr_reader :errors - attr_reader :verbose - - # Run a command under PowerShell via FFI - # This implementation requires the managed dll and native wrapper to be in the library search - # path on Windows (i.e. c:\windows\system32 or in the same location as ruby.exe). - # - # Requires: .NET Framework 4.0 or higher on the target machine. - # - # @param script [String] script to run - # @param timeout [Integer, nil] timeout in seconds. - # @return [Object] output - def initialize(script, timeout: -1) - # This Powershell DLL source lives here: https://github.com/chef/chef-powershell-shim - # Every merge into that repo triggers a Habitat build and promotion. Running - # the rake :update_chef_exec_dll task in this (chef/chef) repo will pull down - # the built packages and copy the binaries to distro/ruby_bin_folder. Bundle install - # ensures that the correct architecture binaries are installed into the path. - @dll ||= "Chef.PowerShell.Wrapper.dll" - exec(script, timeout: timeout) - end - - # - # Was there an error running the command - # - # @return [Boolean] - # - def error? - return true if errors.count > 0 - - false - end - - class CommandFailed < RuntimeError; end - - # - # @raise [Chef::PowerShell::CommandFailed] raise if the command failed - # - def error! - raise Chef::PowerShell::CommandFailed, "Unexpected exit in PowerShell command: #{@errors}" if error? - end - - private - - def exec(script, timeout: -1) - FFI.ffi_lib @dll - FFI.attach_function :execute_powershell, :ExecuteScript, %i{string int}, :pointer - timeout = -1 if timeout == 0 || timeout.nil? - execution = FFI.execute_powershell(script, timeout).read_utf16string - hashed_outcome = Chef::JSONCompat.parse(execution) - @result = Chef::JSONCompat.parse(hashed_outcome["result"]) - @errors = hashed_outcome["errors"] - @verbose = hashed_outcome["verbose"] - end - end -end |