2009-07-11 16:41:21 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
|
|
|
|
class DescribeSecurityGroups < Fog::Parsers::Base
|
|
|
|
|
|
|
|
def reset
|
|
|
|
@group = {}
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_permission = { 'groups' => [], 'ipRanges' => []}
|
2009-07-11 16:41:21 -04:00
|
|
|
@ip_range = {}
|
2009-08-01 04:15:44 -04:00
|
|
|
@security_group = { 'ipPermissions' => [] }
|
|
|
|
@response = { 'securityGroupInfo' => [] }
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_element(name, attrs = [])
|
2009-07-18 00:52:22 -04:00
|
|
|
if name == 'groups'
|
|
|
|
@in_groups = true
|
2009-07-17 03:36:42 -04:00
|
|
|
elsif name == 'ipPermissions'
|
2009-07-11 16:41:21 -04:00
|
|
|
@in_ip_permissions = true
|
2009-07-18 00:52:22 -04:00
|
|
|
elsif name == 'ipRanges'
|
|
|
|
@in_ip_ranges = true
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
@value = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
2009-07-18 00:52:22 -04:00
|
|
|
case name
|
|
|
|
when 'cidrIp'
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_range[name] = @value
|
|
|
|
when 'fromPort', 'toPort'
|
|
|
|
@ip_permission[name] = @value.to_i
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'groups'
|
|
|
|
@in_groups = false
|
2009-08-01 04:15:44 -04:00
|
|
|
when 'groupDescription', 'ownerId'
|
|
|
|
@security_group[name] = @value
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'groupName'
|
|
|
|
if @in_groups
|
2009-08-01 04:15:44 -04:00
|
|
|
@group[name] = @value
|
2009-07-18 00:52:22 -04:00
|
|
|
else
|
2009-08-01 04:15:44 -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
|
|
|
|
when 'ipProtocol'
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_permission[name] = @value
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'ipRanges'
|
|
|
|
@in_ip_ranges = false
|
|
|
|
when 'item'
|
|
|
|
if @in_groups
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_permission['groups'] << @group
|
2009-07-18 00:52:22 -04:00
|
|
|
@group = {}
|
|
|
|
elsif @in_ip_permissions
|
2009-08-01 04:15:44 -04:00
|
|
|
@security_group['ipPermissions'] << @ip_permission
|
|
|
|
@ip_permission = { 'groups' => [], 'ipRanges' => []}
|
2009-07-18 00:52:22 -04:00
|
|
|
elsif @in_ip_ranges
|
2009-08-01 04:15:44 -04:00
|
|
|
@ip_permission['ipRanges'] << @ip_range
|
2009-07-18 00:52:22 -04:00
|
|
|
@ip_range = {}
|
|
|
|
else
|
2009-08-01 04:15:44 -04:00
|
|
|
@response['securityGroupInfo'] << @security_group
|
|
|
|
@security_group = { 'ipPermissions' => [] }
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'requestId'
|
2009-08-01 04:15:44 -04:00
|
|
|
@response[name] = @value
|
2009-07-18 00:52:22 -04:00
|
|
|
when 'userId'
|
2009-08-01 04:15:44 -04:00
|
|
|
@group[name] = @value
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|