2009-07-11 16:41:21 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
module AWS
|
2009-07-11 16:41:21 -04:00
|
|
|
|
|
|
|
class DescribeSecurityGroups < Fog::Parsers::Base
|
|
|
|
|
|
|
|
def reset
|
|
|
|
@group = {}
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_permission = { 'groups' => [], 'ipRanges' => []}
|
2011-07-25 16:03:41 -04:00
|
|
|
@ip_permission_egress = { 'groups' => [], 'ipRanges' => []}
|
2009-07-11 16:41:21 -04:00
|
|
|
@ip_range = {}
|
2011-07-25 16:03:41 -04:00
|
|
|
@security_group = { 'ipPermissions' => [], 'ipPermissionsEgress' => [] }
|
2009-08-01 04:15:44 -04:00
|
|
|
@response = { 'securityGroupInfo' => [] }
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_element(name, attrs = [])
|
2010-05-05 16:39:41 -04:00
|
|
|
super
|
2010-10-04 18:46:12 -04:00
|
|
|
case name
|
|
|
|
when 'groups'
|
2009-07-18 00:52:22 -04:00
|
|
|
@in_groups = true
|
2010-10-04 18:46:12 -04:00
|
|
|
when 'ipPermissions'
|
2009-07-11 16:41:21 -04:00
|
|
|
@in_ip_permissions = true
|
2011-07-25 16:03:41 -04:00
|
|
|
when 'ipPermissionsEgress'
|
|
|
|
@in_ip_permissions_egress = true
|
2010-10-04 18:46:12 -04:00
|
|
|
when 'ipRanges'
|
2009-07-18 00:52:22 -04:00
|
|
|
@in_ip_ranges = true
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
2009-07-18 00:52:22 -04:00
|
|
|
case name
|
|
|
|
when 'cidrIp'
|
2011-05-12 16:15:13 -04:00
|
|
|
@ip_range[name] = value
|
2009-08-01 04:15:44 -04:00
|
|
|
when 'fromPort', 'toPort'
|
2011-07-25 16:03:41 -04:00
|
|
|
if @in_ip_permissions_egress
|
|
|
|
@ip_permission_egress[name] = value.to_i
|
|
|
|
else
|
|
|
|
@ip_permission[name] = value.to_i
|
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'groups'
|
|
|
|
@in_groups = false
|
2009-08-01 04:15:44 -04:00
|
|
|
when 'groupDescription', 'ownerId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@security_group[name] = value
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'groupName'
|
|
|
|
if @in_groups
|
2011-05-12 16:15:13 -04:00
|
|
|
@group[name] = value
|
2009-07-18 00:52:22 -04:00
|
|
|
else
|
2011-05-12 16:15:13 -04:00
|
|
|
@security_group[name] = value
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'ipPermissions'
|
|
|
|
@in_ip_permissions = false
|
2011-07-25 16:03:41 -04:00
|
|
|
when 'ipPermissionsEgress'
|
|
|
|
@in_ip_permissions_egress = false
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'ipProtocol'
|
2011-07-25 16:03:41 -04:00
|
|
|
if @in_ip_permissions_egress
|
|
|
|
@ip_permission_egress[name] = value
|
|
|
|
else
|
|
|
|
@ip_permission[name] = value
|
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'ipRanges'
|
|
|
|
@in_ip_ranges = false
|
|
|
|
when 'item'
|
|
|
|
if @in_groups
|
2011-07-25 16:03:41 -04:00
|
|
|
if @in_ip_permissions_egress
|
|
|
|
@ip_permission_egress['group'] << @group
|
|
|
|
else
|
|
|
|
@ip_permission['groups'] << @group
|
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
@group = {}
|
|
|
|
elsif @in_ip_ranges
|
2011-07-25 16:03:41 -04:00
|
|
|
if @in_ip_permissions_egress
|
|
|
|
@ip_permission_egress['ipRanges'] << @ip_range
|
|
|
|
else
|
|
|
|
@ip_permission['ipRanges'] << @ip_range
|
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
@ip_range = {}
|
2010-07-25 17:03:25 -04:00
|
|
|
elsif @in_ip_permissions
|
|
|
|
@security_group['ipPermissions'] << @ip_permission
|
|
|
|
@ip_permission = { 'groups' => [], 'ipRanges' => []}
|
2011-07-25 16:03:41 -04:00
|
|
|
elsif @in_ip_permissions_egress
|
|
|
|
@security_group['ipPermissionsEgress'] << @ip_permission_egress
|
|
|
|
@ip_permission_egress = { 'groups' => [], 'ipRanges' => []}
|
|
|
|
else
|
2009-08-01 04:15:44 -04:00
|
|
|
@response['securityGroupInfo'] << @security_group
|
2011-07-25 16:03:41 -04:00
|
|
|
@security_group = { 'ipPermissions' => [], 'ipPermissionsEgress' => [] }
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'requestId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@response[name] = value
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'userId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@group[name] = value
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|