lib/provider/ec2.rb in aws_security_viz-0.1.5 vs lib/provider/ec2.rb in aws_security_viz-0.1.6.pre.alpha.pre.134
- old
+ new
@@ -1,27 +1,23 @@
-require 'fog/aws'
+require 'aws-sdk-ec2'
class Ec2Provider
def initialize(options)
@options = options
conn_opts = {
- region: options[:region]
- }
+ region: options[:region],
+ access_key_id: options[:access_key],
+ secret_access_key: options[:secret_key],
+ session_token: options[:session_token]
+ }.delete_if {|k,v| v.nil?}
- conn_opts[:aws_access_key_id] = options[:access_key]
- conn_opts[:aws_secret_access_key] = options[:secret_key]
-
- if options[:session_token]
- conn_opts[:aws_session_token] = options[:session_token]
- end
-
- @compute = Fog::Compute::AWS.new conn_opts
+ @client = Aws::EC2::Client.new(conn_opts)
end
def security_groups
- @compute.security_groups.reject { |sg|
+ @client.describe_security_groups.security_groups.reject { |sg|
@options[:vpc_id] && sg.vpc_id != @options[:vpc_id]
}.collect { |sg|
Ec2::SecurityGroup.new(sg)
}
end
@@ -33,10 +29,14 @@
def_delegators :@sg, :name, :group_id
def initialize(sg)
@sg = sg
end
+ def name
+ @sg.group_name
+ end
+
def ip_permissions
@sg.ip_permissions.collect { |ip|
Ec2::IpPermission.new(ip)
}
end
@@ -52,29 +52,29 @@
def initialize(ip)
@ip = ip
end
def protocol
- @ip['ipProtocol']
+ @ip['ip_protocol']
end
def from
- @ip['fromPort']
+ @ip['from_port']
end
def to
- @ip['toPort']
+ @ip['to_port']
end
def ip_ranges
- @ip['ipRanges'].collect {|gp|
+ @ip['ip_ranges'].collect {|gp|
Ec2::IpPermissionRange.new(gp)
}
end
def groups
- @ip['groups'].collect {|gp|
+ @ip['user_id_group_pairs'].collect {|gp|
Ec2::IpPermissionGroup.new(gp)
}
end
end
@@ -82,11 +82,11 @@
def initialize(range)
@range = range
end
def cidr_ip
- @range['cidrIp']
+ @range['cidr_ip']
end
def to_str
cidr_ip
end
@@ -96,10 +96,10 @@
def initialize(gp)
@gp = gp
end
def name
- @gp['groupName'] || @gp['groupId']
+ @gp['group_name'] || @gp['group_id']
end
end
end