Sha256: 0c054c14af012eb0341d4295075c3c08aaa98afbe815c81ac0c5f1c0cf7e4d7d

Contents?: true

Size: 1.6 KB

Versions: 34

Compression:

Stored size: 1.6 KB

Contents

require_relative 'ec2/security_groups'
require_relative 'provider/json'
require_relative 'provider/ec2'
require_relative 'renderer/graphviz'
require_relative 'renderer/json'
require_relative 'graph'
require_relative 'graph_filter'
require_relative 'exclusions'
require_relative 'debug_graph'
require_relative 'color_picker'
require_relative 'aws_config'

class VisualizeAws
  def initialize(config, options={})
    @options = options
    @config = config
    provider = options[:source_file].nil? ? Ec2Provider.new(options) : JsonProvider.new(options)
    @security_groups = SecurityGroups.new(provider, config)
  end

  def unleash(output_file)
    g = build
    g.filter(@options[:source_filter], @options[:target_filter])
    if output_file.end_with?('json')
      g.output(Renderer::Json.new(output_file, @config))
      FileUtils.copy(File.expand_path('../export/html/view.html', __FILE__),
                     File.expand_path('../view.html', output_file))
    else
      g.output(Renderer::GraphViz.new(output_file, @config))
    end
  end

  def build
    g = @config.obfuscate? ? DebugGraph.new(@config) : Graph.new(@config)
    @security_groups.each_with_index { |group, index|
      picker = ColorPicker.new(@options[:color])
      g.add_node(group.name)
      group.traffic.each { |traffic|
        if traffic.ingress
          g.add_edge(traffic.from, traffic.to, :color => picker.color(index, traffic.ingress), :label => traffic.port_range)
        else
          g.add_edge(traffic.to, traffic.from, :color => picker.color(index, traffic.ingress), :label => traffic.port_range)
        end
      }
    }
    g
  end

end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
aws_security_viz-0.1.7.pre.alpha.pre.145 lib/aws_security_viz.rb
aws_security_viz-0.1.7.pre.alpha.pre.138 lib/aws_security_viz.rb
aws_security_viz-0.1.7.pre.alpha.pre.136 lib/aws_security_viz.rb
aws_security_viz-0.1.6.pre.alpha.pre.134 lib/aws_security_viz.rb
aws_security_viz-0.1.6 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.133 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.131 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.130 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.112 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.111 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.110 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.109 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.108 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.107 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.106 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.103 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.102 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.101 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.100 lib/aws_security_viz.rb
aws_security_viz-0.1.5.pre.alpha.pre.99 lib/aws_security_viz.rb