Class: Serverspec::Type::WindowsFirewall

Inherits:
Base
  • Object
show all
Defined in:
lib/octopus_serverspec_extensions/type/windows_firewall.rb

Instance Method Summary collapse

Constructor Details

#initializeWindowsFirewall

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

Returns:

  • (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

Returns:

  • (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_sObject



21
22
23
# File 'lib/octopus_serverspec_extensions/type/windows_firewall.rb', line 21

def to_s
  "Windows Firewall"
end