summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-09-10 08:55:25 -0700
committerGitHub <noreply@github.com>2020-09-10 08:55:25 -0700
commita624e55fd1d8513247bcabf9d896c43130ec4e44 (patch)
tree7d56b81b1dc4df1609e36eba88169f512524ba84
parent8f60110bfa9485eb31e33df7c27e2646fb3bcc31 (diff)
parent5365d075d9ba9e239f053b83ae21987d02cdf168 (diff)
downloadchef-a624e55fd1d8513247bcabf9d896c43130ec4e44.tar.gz
Merge pull request #10412 from chef-davin/main
Update the windows_firewall_profile resource to fix NoMethodError
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/windows.rb10
-rw-r--r--lib/chef/resource/windows_firewall_profile.rb42
2 files changed, 32 insertions, 20 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
index 3e069a43b0..33fc16e38a 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -32,6 +32,16 @@ windows_security_policy "EnableGuestAccount" do
secvalue "1"
end
+windows_firewall_profile "Domain" do
+ default_inbound_action "Allow"
+ default_outbound_action "Allow"
+ action :enable
+end
+
+windows_firewall_profile "Public" do
+ action :disable
+end
+
users_manage "remove sysadmin" do
group_name "sysadmin"
group_id 2300
diff --git a/lib/chef/resource/windows_firewall_profile.rb b/lib/chef/resource/windows_firewall_profile.rb
index b90d9fd4d5..f67d8fb8ed 100644
--- a/lib/chef/resource/windows_firewall_profile.rb
+++ b/lib/chef/resource/windows_firewall_profile.rb
@@ -19,8 +19,6 @@
class Chef
class Resource
class WindowsFirewallProfile < Chef::Resource
- unified_mode true
-
provides :windows_firewall_profile
description "Use the **windows_firewall_profile** resource to enable, disable, and configure the Windows firewall."
introduced "16.3"
@@ -161,24 +159,6 @@ class Chef
cmd
end
- def load_firewall_state(profile_name)
- <<-EOH
- Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
- $#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
- ([PSCustomObject]@{
- default_inbound_action = $#{profile_name}.DefaultInboundAction.ToString()
- default_outbound_action = $#{profile_name}.DefaultOutboundAction.ToString()
- allow_inbound_rules = $#{profile_name}.AllowInboundRules.ToString()
- allow_local_firewall_rules = $#{profile_name}.AllowLocalFirewallRules.ToString()
- allow_local_ipsec_rules = $#{profile_name}.AllowLocalIPsecRules.ToString()
- allow_user_apps = $#{profile_name}.AllowUserApps.ToString()
- allow_user_ports = $#{profile_name}.AllowUserPorts.ToString()
- allow_unicast_response = $#{profile_name}.AllowUnicastResponseToMulticast.ToString()
- display_notification = $#{profile_name}.NotifyOnListen.ToString()
- }) | ConvertTo-Json
- EOH
- end
-
def firewall_enabled?(profile_name)
cmd = <<~CODE
$#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
@@ -194,6 +174,28 @@ class Chef
end
end
end
+
+ private
+
+ # build the command to load the current resource
+ # @return [String] current firewall state
+ def load_firewall_state(profile_name)
+ <<-EOH
+ Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
+ $#{profile_name} = Get-NetFirewallProfile -Profile #{profile_name}
+ ([PSCustomObject]@{
+ default_inbound_action = $#{profile_name}.DefaultInboundAction.ToString()
+ default_outbound_action = $#{profile_name}.DefaultOutboundAction.ToString()
+ allow_inbound_rules = $#{profile_name}.AllowInboundRules.ToString()
+ allow_local_firewall_rules = $#{profile_name}.AllowLocalFirewallRules.ToString()
+ allow_local_ipsec_rules = $#{profile_name}.AllowLocalIPsecRules.ToString()
+ allow_user_apps = $#{profile_name}.AllowUserApps.ToString()
+ allow_user_ports = $#{profile_name}.AllowUserPorts.ToString()
+ allow_unicast_response = $#{profile_name}.AllowUnicastResponseToMulticast.ToString()
+ display_notification = $#{profile_name}.NotifyOnListen.ToString()
+ }) | ConvertTo-Json
+ EOH
+ end
end
end
end