diff options
author | Davin Taddeo <davin@chef.io> | 2020-09-10 10:14:38 -0400 |
---|---|---|
committer | Davin Taddeo <davin@chef.io> | 2020-09-10 10:14:38 -0400 |
commit | e5050bbbfb578987e5a17a7c4ed27a06586fbb24 (patch) | |
tree | a016e3305fec3ef6738cb0d4f72705fad402f956 /lib | |
parent | 8f60110bfa9485eb31e33df7c27e2646fb3bcc31 (diff) | |
download | chef-e5050bbbfb578987e5a17a7c4ed27a06586fbb24.tar.gz |
Update the windows_firewall_profile resource to move the load_firewall_state method out of the action_class. Also add some firewall tests to the kitchen tests to avoid this issue in the future.
Signed-off-by: Davin Taddeo <davin@chef.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/resource/windows_firewall_profile.rb | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/chef/resource/windows_firewall_profile.rb b/lib/chef/resource/windows_firewall_profile.rb index b90d9fd4d5..72dc19da88 100644 --- a/lib/chef/resource/windows_firewall_profile.rb +++ b/lib/chef/resource/windows_firewall_profile.rb @@ -161,24 +161,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 +176,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 |