Skip to content

Instantly share code, notes, and snippets.

@raws
Created October 4, 2010 04:04
Show Gist options
  • Save raws/609241 to your computer and use it in GitHub Desktop.
Save raws/609241 to your computer and use it in GitHub Desktop.
class AcfDistributionListParser < RightAWSParser # :nodoc:
def reset
@result = { :distributions => [] }
end
def tagstart(name, attributes)
case full_tag_name
when %r{/Signer$}
@active_signer = {}
when %r{(Streaming)?DistributionSummary$},
%r{^(Streaming)?Distribution$},
%r{^(Streaming)?DistributionConfig$}
@distribution = { }
end
end
def tagend(name)
puts "tagend(#{name})"
case name
when 'Marker' then @result[:marker] = @text
when 'NextMarker' then @result[:next_marker] = @text
when 'MaxItems' then @result[:max_items] = @text.to_i
when 'IsTruncated' then @result[:is_truncated] = (@text == 'true')
when 'Id' then @distribution[:aws_id] = @text
when 'Status' then @distribution[:status] = @text
when 'LastModifiedTime' then @distribution[:last_modified_time] = @text
when 'DomainName' then @distribution[:domain_name] = @text
when 'Origin' then @distribution[:origin] = @text
when 'Comment' then @distribution[:comment] = AcfInterface::unescape(@text)
when 'CallerReference' then @distribution[:caller_reference] = @text
when 'CNAME' then (@distribution[:cnames] ||= []) << @text
when 'Enabled' then @distribution[:enabled] = (@text == 'true')
when 'Bucket' then (@distribution[:logging] ||= {})[:bucket] = @text
when 'Prefix' then (@distribution[:logging] ||= {})[:prefix] = @text
when 'OriginAccessIdentity' then @distribution[:origin_access_identity] = @text
end
case full_tag_name
when %r{/TrustedSigners/Self$} then (@distribution[:trusted_signers] ||= []) << 'self'
when %r{/TrustedSigners/AwsAccountNumber$} then (@distribution[:trusted_signers] ||= []) << @text
when %r{/Signer/Self$} then @active_signer[:aws_account_number] = 'self'
when %r{/Signer/AwsAccountNumber$} then @active_signer[:aws_account_number] = @text
when %r{/Signer/KeyPairId$} then (@active_signer[:key_pair_ids] ||= []) << @text
when %r{/Signer$} then (@distribution[:active_trusted_signers] ||= []) << @active_signer
when %r{(Streaming)?DistributionSummary$},
%r{^(Streaming)?Distribution$},
%r{^(Streaming)?DistributionConfig$}
@result[:distributions] << @distribution
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment