1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/parsers/ec2/describe_security_groups.rb

76 lines
2.2 KiB
Ruby
Raw Normal View History

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' => []}
@ip_range = {}
2009-08-01 04:15:44 -04:00
@security_group = { 'ipPermissions' => [] }
@response = { 'securityGroupInfo' => [] }
end
def start_element(name, attrs = [])
if name == 'groups'
@in_groups = true
elsif name == 'ipPermissions'
@in_ip_permissions = true
elsif name == 'ipRanges'
@in_ip_ranges = true
end
@value = ''
end
def end_element(name)
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
when 'groups'
@in_groups = false
2009-08-01 04:15:44 -04:00
when 'groupDescription', 'ownerId'
@security_group[name] = @value
when 'groupName'
if @in_groups
2009-08-01 04:15:44 -04:00
@group[name] = @value
else
2009-08-01 04:15:44 -04:00
@security_group[name] = @value
end
when 'ipPermissions'
@in_ip_permissions = false
when 'ipProtocol'
2009-08-01 04:15:44 -04:00
@ip_permission[name] = @value
when 'ipRanges'
@in_ip_ranges = false
when 'item'
if @in_groups
2009-08-01 04:15:44 -04:00
@ip_permission['groups'] << @group
@group = {}
elsif @in_ip_permissions
2009-08-01 04:15:44 -04:00
@security_group['ipPermissions'] << @ip_permission
@ip_permission = { 'groups' => [], 'ipRanges' => []}
elsif @in_ip_ranges
2009-08-01 04:15:44 -04:00
@ip_permission['ipRanges'] << @ip_range
@ip_range = {}
else
2009-08-01 04:15:44 -04:00
@response['securityGroupInfo'] << @security_group
@security_group = { 'ipPermissions' => [] }
end
when 'requestId'
2009-08-01 04:15:44 -04:00
@response[name] = @value
when 'userId'
2009-08-01 04:15:44 -04:00
@group[name] = @value
end
end
end
end
end
end
end