Sha256: 6ea8719fcaa795055ca7094ba59d09669edb53a6fba17d270470de404d872f85

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

require_relative 'traffic.rb'

class IpPermission
  def initialize(group, ip, ingress, exclusions)
    @group = group
    @ip = ip
    @ingress = ingress
    @exclusions = exclusions
  end

  def traffic
    cidr_traffic + group_traffic
  end

  private
  def port_range
    @ip.protocol == '-1' ? '*' : [@ip.from, @ip.to].uniq.join('-') + '/' + @ip.protocol
  end

  def cidr_traffic
    @ip.ip_ranges.collect { |range|
      Traffic.new(@ingress, range.cidr_ip, @group.name, port_range)
    }
  end

  def group_traffic
    @ip.groups
      .select { |gp| !@exclusions.match(gp.name)}
      .collect { |gp|
      Traffic.new(@ingress, gp.name, @group.name, port_range)
    }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aws_security_viz-0.1.1 lib/ec2/ip_permission.rb
aws_security_viz-0.1.1.pre.alpha.pre.56 lib/ec2/ip_permission.rb
aws_security_viz-0.1.0 lib/ec2/ip_permission.rb