class Sgupdater::Client

Attributes

logger[R]

Public Class Methods

new(cli_options = {}, aws_configuration = {}) click to toggle source
# File lib/sgupdater/client.rb, line 8
def initialize(cli_options = {}, aws_configuration = {})
  @cli_options = cli_options
  @logger ||= Logger.new STDOUT

  aws_configuration[:logger] = Logger.new STDOUT if @cli_options[:verbose]

  @ec2 = Aws::EC2::Resource.new aws_configuration
end

Public Instance Methods

add() click to toggle source
# File lib/sgupdater/client.rb, line 27
def add
  updater = Sgupdater::Updater.new(@cli_options)
  updater.add(@cli_options[:from_cidr], @cli_options[:to_cidr])
  updater.update
end
get(cidr = @cli_options[:from_cidr]) click to toggle source
# File lib/sgupdater/client.rb, line 17
def get(cidr = @cli_options[:from_cidr])
  security_groups_with_cidr(cidr)
end
put_perms(sg, cidr) click to toggle source
# File lib/sgupdater/client.rb, line 41
def put_perms(sg, cidr)
  sg.ip_permissions.each do |perm|
    perm.ip_ranges.select {|ip| ip.values.include? cidr}.each do
      puts [sg.vpc_id, sg.group_id, sg.group_name, perm.from_port, perm.to_port, cidr].join("\t")
    end
  end
end
security_groups_with_cidr(cidr) click to toggle source
# File lib/sgupdater/client.rb, line 33
def security_groups_with_cidr(cidr)
  @ec2.security_groups(
    filters: [
      {name: 'ip-permission.cidr', values: [cidr]}
    ]
  )
end
update() click to toggle source
# File lib/sgupdater/client.rb, line 21
def update
  updater = Sgupdater::Updater.new(@cli_options)
  updater.replace(@cli_options[:from_cidr], @cli_options[:to_cidr])
  updater.update
end