class Awspec::Type::NetworkAcl
Constants
- PROTOCOLS
-
rubocop:disable Layout/LineLength
Public Instance Methods
Source
# File lib/awspec/type/network_acl.rb, line 27 def allowed?(port = nil, protocol = nil, cidr = nil, rule_number = nil) rule_action = 'allow' entry?(rule_action, port, protocol, cidr, rule_number) end
Source
# File lib/awspec/type/network_acl.rb, line 32 def denied?(port = nil, protocol = nil, cidr = nil, rule_number = nil) rule_action = 'deny' entry?(rule_action, port, protocol, cidr, rule_number) end
Source
# File lib/awspec/type/network_acl.rb, line 16 def has_subnet?(subnet_id) resource_via_client.associations.find do |a| next true if a.subnet_id == subnet_id subnet = find_subnet(subnet_id) next false unless subnet next a.subnet_id == subnet.subnet_id end end
Source
# File lib/awspec/type/network_acl.rb, line 12 def id @id ||= resource_via_client.network_acl_id if resource_via_client end
Source
# File lib/awspec/type/network_acl.rb, line 37 def inbound @egress = false self end
Source
# File lib/awspec/type/network_acl.rb, line 47 def inbound_entries_count resource_via_client.entries.count do |entry| entry.egress == false end end
Source
# File lib/awspec/type/network_acl.rb, line 42 def outbound @egress = true self end
Source
# File lib/awspec/type/network_acl.rb, line 53 def outbound_entries_count resource_via_client.entries.count do |entry| entry.egress == true end end
Source
# File lib/awspec/type/network_acl.rb, line 8 def resource_via_client @resource_via_client ||= find_network_acl(@display_name) end
Private Instance Methods
Source
# File lib/awspec/type/network_acl.rb, line 79 def entry?(rule_action, port = nil, protocol = nil, cidr = nil, rule_number = nil) resource_via_client.entries.find do |entry| # egress rule_action next false if entry.egress != @egress next false if entry.rule_action != rule_action # protocol unless protocol.nil? next false unless protocol_match?(protocol, entry.protocol) end # cidr next false if !cidr.nil? && entry.cidr_block != cidr # rule_number rule_number = 32_767 if rule_number == '*' next false if !rule_number.nil? && entry.rule_number != rule_number # port unless entry.port_range.nil? next false unless port_between?(port, entry.port_range.from, entry.port_range.to) end next true end end
rubocop:enable Layout/LineLength
Source
# File lib/awspec/type/network_acl.rb, line 115 def port_between?(port, from_port, to_port) if port.is_a?(String) && port.include?('-') f, t = port.split('-') from_port == f.to_i && to_port == t.to_i else port.between?(from_port, to_port) end end
Source
# File lib/awspec/type/network_acl.rb, line 104 def protocol_match?(a, b) if a.match(/\A\d+\z/) && a.to_i >= 0 return false unless b.to_i == a.to_i else lower_h = PROTOCOLS.map { |k, v| [k.downcase, v] }.to_h return false unless lower_h.key?(a.downcase) return false unless b.to_i == lower_h[a.downcase] end true end