summaryrefslogtreecommitdiff
path: root/lib/chef/powershell.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/powershell.rb')
-rw-r--r--lib/chef/powershell.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/chef/powershell.rb b/lib/chef/powershell.rb
index 5063e599c6..4800708dfc 100644
--- a/lib/chef/powershell.rb
+++ b/lib/chef/powershell.rb
@@ -34,8 +34,6 @@ class Chef
# @param script [String] script to run
# @return [Object] output
def initialize(script)
- raise "Chef::PowerShell can only be used on the Windows platform." unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
-
@dll ||= "Chef.PowerShell.Wrapper.dll"
exec(script)
end
@@ -65,7 +63,15 @@ class Chef
def exec(script)
FFI.ffi_lib @dll
FFI.attach_function :execute_powershell, :ExecuteScript, [:string], :pointer
- execution = FFI.execute_powershell(script).read_utf16string
+ # This is a temporary fix for running in a Habitat environment
+ # In habitat we set CHEF_POWERSHELL_BIN so that .Net resolves our
+ # managed shim assembly from the correct location.
+ # It seems that that is preventing .Net from successfully loading GAC assemblies
+ # and can break all sorts of edge (and not so edge) scenarios. Once we are actually
+ # inside the powershell run space, we know our shim was loaded and can unset
+ # CHEF_POWERSHELL_BIN which will bypass our custom resolver logic. The real fix is
+ # to fix our resolver. Oh and OH MY GOD this was a pain to track down.
+ execution = FFI.execute_powershell("$ENV:CHEF_POWERSHELL_BIN=$NULL;#{script}").read_utf16string
hashed_outcome = Chef::JSONCompat.parse(execution)
@result = Chef::JSONCompat.parse(hashed_outcome["result"])
@errors = hashed_outcome["errors"]