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/requests/storage/hash_to_acl.rb
2011-09-23 10:53:53 -05:00

44 lines
1.2 KiB
Ruby

module Fog
module Storage
class AWS
private
def self.hash_to_acl(acl)
data =
<<-DATA
<AccessControlPolicy>
<Owner>
<ID>#{acl['Owner']['ID']}</ID>
<DisplayName>#{acl['Owner']['DisplayName']}</DisplayName>
</Owner>
<AccessControlList>
DATA
acl['AccessControlList'].each do |grant|
data << " <Grant>\n"
type = case grant['Grantee'].keys.sort
when ['DisplayName', 'ID']
'CanonicalUser'
when ['EmailAddress']
'AmazonCustomerByEmail'
when ['URI']
'Group'
end
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">\n"
data << " <ID>#{grant['Grantee']['ID']}</ID>\n"
data << " <DisplayName>#{grant['Grantee']['DisplayName']}</DisplayName>\n"
data << " </Grantee>\n"
data << " <Permission>#{grant['Permission']}</Permission>\n"
data << " </Grant>\n"
end
data <<
<<-DATA
</AccessControlList>
</AccessControlPolicy>
DATA
data
end
end
end
end