Class: Inspec::Resources::WindowsFirewallRule
- Inherits:
-
Object
- Object
- Inspec::Resources::WindowsFirewallRule
show all
- Defined in:
- lib/inspec/resources/windows_firewall_rule.rb
Instance Method Summary
collapse
Constructor Details
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”`
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 75
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
42
43
44
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 42
def allowed?
@state["action"] == "Allow"
end
|
#enabled? ⇒ Boolean
38
39
40
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 38
def enabled?
@state["enabled"]
end
|
#exist? ⇒ Boolean
34
35
36
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 34
def exist?
!@state.empty?
end
|
#icmp? ⇒ Boolean
62
63
64
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 62
def icmp?
@state["protocol"].start_with? "ICMP"
end
|
#icmpv4? ⇒ Boolean
66
67
68
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 66
def icmpv4?
@state["protocol"] == "ICMPv4"
end
|
#icmpv6? ⇒ Boolean
70
71
72
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 70
def icmpv6?
@state["protocol"] == "ICMPv6"
end
|
#inbound? ⇒ Boolean
46
47
48
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 46
def inbound?
@state["direction"] == "Inbound"
end
|
#outbound? ⇒ Boolean
50
51
52
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 50
def outbound?
! inbound?
end
|
#resource_id ⇒ Object
26
27
28
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 26
def resource_id
@name || "windows_firewall_rule"
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
86
87
88
89
90
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 86
def respond_to_missing?(method_name, _include_private = false)
property = normalize_for_have_access(method_name)
@state.key? property
end
|
#tcp? ⇒ Boolean
54
55
56
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 54
def tcp?
@state["protocol"] == "TCP"
end
|
#to_s ⇒ Object
30
31
32
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 30
def to_s
"Windows Firewall Rule #{@name}"
end
|
#udp? ⇒ Boolean
58
59
60
|
# File 'lib/inspec/resources/windows_firewall_rule.rb', line 58
def udp?
@state["protocol"] == "UDP"
end
|