summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorNimesh-Msys <nimesh.patni@msystechnologies.com>2019-01-29 16:04:02 +0530
committerNimesh-Msys <nimesh.patni@msystechnologies.com>2019-02-04 11:50:25 +0530
commit13fd78e7b6523d8f172c2173ae8153168c319ff6 (patch)
tree478070373f832253075f9922533436542ebacd7a /lib/chef/provider
parentcdb329bb9ff22f84c445410e1fc819c04bd94699 (diff)
downloadchef-13fd78e7b6523d8f172c2173ae8153168c319ff6.tar.gz
As per the review comments
- Using `flags` attribute from resources itself - Fixed and add the required test cases Signed-off-by: Nimesh-Msys <nimesh.patni@msystechnologies.com>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/powershell_script.rb34
1 files changed, 2 insertions, 32 deletions
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index 34d2655c80..7430fabfec 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -48,7 +48,7 @@ class Chef
# end of the script, it gets changed to '1'.
#
# Nano only supports -Command
- cmd = "\"#{interpreter_path}\" #{flags}"
+ cmd = "\"#{interpreter_path}\" #{new_resource.flags}"
if Chef::Platform.windows_nano_server?
cmd << " -Command \". '#{script_file.path}'\""
else
@@ -57,16 +57,6 @@ class Chef
cmd
end
- def flags
- interpreter_flags = [*default_interpreter_flags].join(" ")
-
- unless new_resource.flags.nil?
- interpreter_flags = [interpreter_flags, new_resource.flags].join(" ")
- end
-
- interpreter_flags
- end
-
protected
# Process exit codes are strange with PowerShell and require
@@ -78,7 +68,7 @@ class Chef
end
def validate_script_syntax!
- interpreter_arguments = default_interpreter_flags.join(" ")
+ interpreter_arguments = new_resource.flags
Tempfile.open(["chef_powershell_script-user-code", ".ps1"]) do |user_script_file|
# Wrap the user's code in a PowerShell script block so that
# it isn't executed. However, syntactically invalid script
@@ -115,26 +105,6 @@ class Chef
end
end
- def default_interpreter_flags
- return [] if Chef::Platform.windows_nano_server?
-
- # Execution policy 'Bypass' is preferable since it doesn't require
- # user input confirmation for files such as PowerShell modules
- # downloaded from the Internet. However, 'Bypass' is not supported
- # prior to PowerShell 3.0, so the fallback is 'Unrestricted'
- execution_policy = Chef::Platform.supports_powershell_execution_bypass?(run_context.node) ? "Bypass" : "Unrestricted"
-
- [
- "-NoLogo",
- "-NonInteractive",
- "-NoProfile",
- "-ExecutionPolicy #{execution_policy}",
- # PowerShell will hang if STDIN is redirected
- # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
- "-InputFormat None",
- ]
- end
-
# A wrapper script is used to launch user-supplied script while
# still obtaining useful process exit codes. Unless you
# explicitly call exit in PowerShell, the powershell.exe