Skip to content

Commit

Permalink
Merge pull request #180 from djberg96/network_security_groups
Browse files Browse the repository at this point in the history
Handle possibility of arrays for Network Security Groups
(cherry picked from commit 41eb3c470ff19476b422701eadb8bee194695e40)

https://bugzilla.redhat.com/show_bug.cgi?id=1521043
  • Loading branch information
agrare authored and simaishi committed Dec 5, 2017
1 parent 166a4fa commit 8f56fc8
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,45 @@ def parse_firewall_rules(security_group)
{
:name => rule.name,
:host_protocol => rule.properties.protocol.upcase,
:port => rule.properties.destination_port_range.split('-').first,
:end_port => rule.properties.destination_port_range.split('-').last,
:port => calculate_start_port(rule),
:end_port => calculate_end_port(rule),
:direction => rule.properties.direction,
:source_ip_range => rule.properties.source_address_prefix,
:source_ip_range => calculate_source_ip_range(rule),
:source_security_group => @data_index.fetch_path(:security_groups, security_group.id)
}
end
end

def calculate_source_ip_range(rule)
if rule.properties.respond_to?(:source_address_prefix)
rule.properties.source_address_prefix
elsif rule.properties.respond_to?(:source_address_prefixes)
rule.properties.source_address_prefixes.join(',')
else
nil # Old api-version
end
end

def calculate_start_port(rule)
if rule.properties.respond_to?(:destination_port_range)
rule.properties.destination_port_range.split('-').first.to_i
elsif rule.properties.respond_to?(:destination_port_ranges)
rule.properties.destination_port_ranges.flat_map{ |e| e.split('-') }.map(&:to_i).min
else
nil # Old api-version
end
end

def calculate_end_port(rule)
if rule.properties.respond_to?(:destination_port_range)
rule.properties.destination_port_range.split('-').last.to_i
elsif rule.properties.respond_to?(:destination_port_ranges)
rule.properties.destination_port_ranges.flat_map{ |e| e.split('-') }.map(&:to_i).max
else
nil # Old api-version
end
end

def parse_load_balancer(lb)
name = lb.name
uid = lb.id
Expand Down

0 comments on commit 8f56fc8

Please sign in to comment.