Class: Serverspec::Type::WindowsFirewall
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::WindowsFirewall
- Defined in:
- lib/octopus_serverspec_extensions/type/windows_firewall.rb
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #has_open_port?(port) ⇒ Boolean
-
#initialize ⇒ WindowsFirewall
constructor
A new instance of WindowsFirewall.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ WindowsFirewall
Returns a new instance of WindowsFirewall.
7 8 9 |
# File 'lib/octopus_serverspec_extensions/type/windows_firewall.rb', line 7 def initialize @runner = Specinfra::Runner end |
Instance Method Details
#enabled? ⇒ Boolean
16 17 18 19 |
# File 'lib/octopus_serverspec_extensions/type/windows_firewall.rb', line 16 def enabled? command_result = @runner.run_command("(get-service MpsSvc).Status") command_result.stdout.gsub(/\n/, '') == "Running" end |
#has_open_port?(port) ⇒ Boolean
11 12 13 14 |
# File 'lib/octopus_serverspec_extensions/type/windows_firewall.rb', line 11 def has_open_port?(port) command_result = @runner.run_command("((New-Object -comObject HNetCfg.FwPolicy2).rules | where-object { $_.LocalPorts -eq #{port} -and $_.Action -eq 1}).Enabled") command_result.stdout.gsub(/\n/, '') == "True" end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/octopus_serverspec_extensions/type/windows_firewall.rb', line 21 def to_s "Windows Firewall" end |