Sha256: 11d0d34a2bea5d7ae6e4c43d4c7667fb962ee708d2ae690444a61f5b21c53e48

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'json'

class JsonProvider
  def initialize(options)
    @groups = JSON.parse(File.read(options[:source_file]))['SecurityGroups']
  end

  def security_groups
    @groups.collect { |sg|
      Json::SecurityGroup.new(sg)
    }
  end
end

module Json
  class SecurityGroup
    def initialize(sg)
      @sg = sg
    end

    def name
      @sg['GroupName']
    end

    def ip_permissions
      @sg['IpPermissions'].collect { |ip|
        Json::IpPermission.new(ip)
      }
    end

    def group_id
      @sg['GroupId']
    end

    def ip_permissions_egress
      @sg['IpPermissionsEgress'].collect { |ip|
        Json::IpPermission.new(ip)
      }
    end
  end

  class IpPermission
    def initialize(ip)
      @ip = ip
    end

    def protocol
      @ip['IpProtocol']
    end

    def from
      @ip['FromPort']
    end

    def to
      @ip['ToPort']
    end

    def ip_ranges
      @ip['IpRanges'].collect { |gp|
        Json::IpPermissionRange.new(gp)
      }
    end

    def groups
      @ip['UserIdGroupPairs'].collect { |pair|
        Json::IpPermissionGroup.new(pair)
      }
    end

  end

  class IpPermissionRange
    def initialize(range)
      @range = range
    end

    def cidr_ip
      @range['CidrIp']
    end
  end

  class IpPermissionGroup
    def initialize(gp)
      @gp = gp
    end

    def name
      @gp['GroupName'] || @gp['GroupId']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aws_security_viz-0.1.1 lib/provider/json.rb
aws_security_viz-0.1.1.pre.alpha.pre.56 lib/provider/json.rb
aws_security_viz-0.1.0 lib/provider/json.rb