Created
October 4, 2010 04:02
-
-
Save raws/609239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distribution_config_to_xml(config, xml_wrapper='DistributionConfig') # :nodoc:= | |
cnames = '' | |
logging = '' | |
origin_access_identity = '' | |
trusted_signers = '' | |
# CNAMES | |
unless config[:cnames].blank? | |
Array(config[:cnames]).each { |cname| cnames += " <CNAME>#{cname}</CNAME>\n" } | |
end | |
# Logging | |
unless config[:logging].blank? | |
logging = " <Logging>\n" + | |
" <Bucket>#{config[:logging][:bucket]}</Bucket>\n" + | |
" <Prefix>#{config[:logging][:prefix]}</Prefix>\n" + | |
" </Logging>\n" | |
end | |
# Origin Access Identity | |
unless config[:origin_access_identity].blank? | |
origin_access_identity = config[:origin_access_identity] | |
unless origin_access_identity[%r{^origin-access-identity}] | |
origin_access_identity = "origin-access-identity/cloudfront/#{origin_access_identity}" | |
end | |
origin_access_identity = " <OriginAccessIdentity>#{origin_access_identity}</OriginAccessIdentity>\n" | |
end | |
# Trusted Signers | |
unless config[:trusted_signers].blank? | |
trusted_signers = " <TrustedSigners>\n" | |
Array(config[:trusted_signers]).each do |trusted_signer| | |
trusted_signers += if trusted_signer.to_s[/self/i] | |
" <Self/>\n" | |
else | |
" <AwsAccountNumber>#{trusted_signer}</AwsAccountNumber>\n" | |
end | |
end | |
trusted_signers += " </TrustedSigners>\n" | |
end | |
# XML | |
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | |
"<#{xml_wrapper} xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" + | |
" <Origin>#{config[:origin]}</Origin>\n" + | |
" <CallerReference>#{config[:caller_reference]}</CallerReference>\n" + | |
" <Comment>#{AcfInterface::escape(config[:comment].to_s)}</Comment>\n" + | |
" <Enabled>#{config[:enabled]}</Enabled>\n" + | |
cnames + | |
logging + | |
origin_access_identity + | |
trusted_signers + | |
"</#{xml_wrapper}>" | |
puts xml | |
xml | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment