class Sgupdater::Updater

Public Class Methods

new(options = {}) click to toggle source
# File lib/sgupdater/updater.rb, line 8
def initialize(options = {})
  @options = options.dup
  @options[:without_convert] = true
  @options[:format] = :json
  AWS.config(@options)
  @client = Piculet::Client.new(@options)
  @exported = @client.export(without_convert: true)
end

Public Instance Methods

add(from, to) click to toggle source
# File lib/sgupdater/updater.rb, line 32
def add(from, to)
  @exported.each do |vpc, sgs|
    sgs.each do |sg, props|
      props[:ingress].each do |ing|
        ing[:ip_ranges].each do |cidr|
          if cidr == from
            ing[:ip_ranges] << to
            puts [vpc ? vpc : '(classic)', sg, props[:name], ing[:protocol], ing[:port_range], ing[:ip_ranges], ing[:groups]].join("\t")
          end
        end
      end
    end
  end
end
replace(from, to) click to toggle source
# File lib/sgupdater/updater.rb, line 17
def replace(from, to)
  @exported.each do |vpc, sgs|
    sgs.each do |sg, props|
      props[:ingress].each do |ing|
        ing[:ip_ranges].each_with_index do |cidr, i|
          if cidr == from
            ing[:ip_ranges][i] = to
            puts [vpc ? vpc : 'classic', sg, props[:name], ing[:protocol], ing[:port_range], ing[:ip_rages], ing[:groups], cidr].join("\t")
          end
        end
      end
    end
  end
end
update() click to toggle source
# File lib/sgupdater/updater.rb, line 47
def update
  exported = JSON.pretty_generate(@exported)
  file = Tempfile.new('exported')
  begin
    file.puts exported
    file.rewind
    file.rewind
    updated = @client.apply(file)
  ensure
    file.close
    file.unlink
  end
  updated
end