Class: Inspec::Resources::WindowsFirewallRule

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ WindowsFirewallRule

Returns a new instance of WindowsFirewallRule.



17
18
19
20
21
22
23
24
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 17

def initialize(name)
  @name = name
  @state = {}

  query = load_firewall_state(name)
  cmd = inspec.powershell(query)
  @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”`



71
72
73
74
75
76
77
78
79
80
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 71

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

#allowed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 38

def allowed?
  @state["action"] == "Allow"
end

#enabled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 34

def enabled?
  @state["enabled"]
end

#exist?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 30

def exist?
  !@state.empty?
end

#icmp?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 58

def icmp?
  @state["protocol"].start_with? "ICMP"
end

#icmpv4?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 62

def icmpv4?
  @state["protocol"] == "ICMPv4"
end

#icmpv6?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 66

def icmpv6?
  @state["protocol"] == "ICMPv6"
end

#inbound?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 42

def inbound?
  @state["direction"] == "Inbound"
end

#outbound?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 46

def outbound?
  ! inbound?
end

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

Returns:

  • (Boolean)


82
83
84
85
86
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 82

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

  @state.key? property
end

#tcp?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 50

def tcp?
  @state["protocol"] == "TCP"
end

#to_sObject



26
27
28
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 26

def to_s
  "Windows Firewall Rule #{@name}"
end

#udp?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 54

def udp?
  @state["protocol"] == "UDP"
end