Sha256: 492487348b8f2ce52b5cf48641daa3a7ebead97aa9cd4dca4c986d20452a019f

Contents?: true

Size: 1.49 KB

Versions: 143

Compression:

Stored size: 1.49 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 group_id
      @sg['GroupId']
    end

    def vpc_id
      @sg['VpcId']
    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

    def to_str
      cidr_ip
    end
  end

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

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

Version data entries

143 entries across 143 versions & 1 rubygems

Version Path
aws_security_viz-0.2.5.pre.alpha.pre.35 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.34 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.33 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.32 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.31 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.30 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.29 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.28 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.27 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.26 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.25 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.24 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.23 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.22 lib/provider/json.rb
aws_security_viz-0.2.5.pre.alpha.pre.21 lib/provider/json.rb
aws_security_viz-0.2.4 lib/provider/json.rb
aws_security_viz-0.2.4.pre.alpha.pre.20 lib/provider/json.rb
aws_security_viz-0.2.4.pre.alpha.pre.19 lib/provider/json.rb
aws_security_viz-0.2.4.pre.alpha.pre.18 lib/provider/json.rb
aws_security_viz-0.2.4.pre.alpha.pre.15 lib/provider/json.rb