Class: Inspec::Resources::WindowsFirewall

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/windows_firewall.rb

Instance Method Summary collapse

Constructor Details

#initialize(profile = "Public") ⇒ WindowsFirewall

Returns a new instance of WindowsFirewall.



14
15
16
17
18
19
20
21
22
# File 'lib/inspec/resources/windows_firewall.rb', line 14

def initialize(profile = "Public")
  @profile = profile
  @state = {}

  load_profile_cmd = load_firewall_profile(profile)
  cmd = inspec.powershell(load_profile_cmd)

  @state = JSON.load(cmd.stdout) unless cmd.stdout.empty?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &_block) ⇒ Object

Access to return values from Powershell via ‘its(“PROPERTY”)` and `have_PROPERTY “VALUE”`



45
46
47
48
49
50
51
52
53
54
# File 'lib/inspec/resources/windows_firewall.rb', line 45

def method_missing(method_name, *arguments, &_block)
  property = normalize_for_have_access(method_name)

  if method_name.to_s.start_with? "has_"
    expected_value = arguments.first
    respond_to_have(property, expected_value)
  else
    access_property(property)
  end
end

Instance Method Details

#default_inbound_allowed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/inspec/resources/windows_firewall.rb', line 36

def default_inbound_allowed?
  @state["default_inbound_action"] == "Allow"
end

#default_outbound_allowed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/inspec/resources/windows_firewall.rb', line 40

def default_outbound_allowed?
  @state["default_outbound_action"] == "Allow"
end

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/inspec/resources/windows_firewall.rb', line 32

def enabled?
  @state["enabled"]
end

#exist?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/inspec/resources/windows_firewall.rb', line 28

def exist?
  !@state.empty?
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/inspec/resources/windows_firewall.rb', line 56

def respond_to_missing?(method_name, _include_private = false)
  property = normalize_for_have_access(method_name)

  @state.key? property
end

#to_sObject



24
25
26
# File 'lib/inspec/resources/windows_firewall.rb', line 24

def to_s
  "Windows Firewall (Profile #{@profile})"
end