1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/parsers/iam/policy_parser.rb
2015-05-21 12:42:25 -07:00

57 lines
1.5 KiB
Ruby

module Fog
module Parsers
module AWS
module IAM
class PolicyParser < Fog::Parsers::Base
def reset
@policy = fresh_policy
@stack = []
end
def start_element(name,attrs = [])
case name
when 'Policies'
@stack << name
when 'Policy'
@policy = fresh_policy
when 'member'
if @stack.last == 'Policies'
@policy = fresh_policy
end
end
super
end
def fresh_policy
{'AttachmentCount' => 0, 'Description' => ''}
end
def end_element(name)
case name
when 'Arn', 'DefaultVersionId', 'Description', 'Path', 'PolicyName', 'PolicyId'
@policy[name] = value
when 'CreateDate', 'UpdateDate'
@policy[name] = Time.parse(value)
when 'IsAttachable'
@policy[name] = (value == 'true')
when 'AttachmentCount'
@policy[name] = value.to_i
when 'Policy'
finished_policy(@policy)
@policy = nil
when 'Policies'
if @stack.last == 'Policies'
@stack.pop
end
when 'member'
if @stack.last == 'Policies'
finished_policy(@policy)
@policy = nil
end
end
end
end
end
end
end
end