1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

AWS#hash_to_acl - add support for EmailAddress and URI grantee types.

Aside: Don't assume there will always be a DisplayName.
This commit is contained in:
Nathan Sutton 2011-11-04 17:03:29 -07:00
parent 4662b2635d
commit 48af3e5489

View file

@ -1,47 +1,46 @@
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
data = "<AccessControlPolicy>\n"
if acl['Owner'] && (acl['Owner']['ID'] || acl['Owner']['DisplayName'])
data << " <Owner>\n"
data << " <ID>#{acl['Owner']['ID']}</ID>\n" if acl['Owner']['ID']
data << " <DisplayName>#{acl['Owner']['DisplayName']}</DisplayName>\n" if acl['Owner']['DisplayName']
data << " </Owner>\n"
end
data << " <AccessControlList>\n" if acl['AccessControlList'].any?
acl['AccessControlList'].each do |grant|
data << " <Grant>\n"
case grant['Grantee'].keys.sort
when ['DisplayName', 'ID']
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\">\n"
data << " <ID>#{grant['Grantee']['ID']}</ID>\n"
data << " <DisplayName>#{grant['Grantee']['DisplayName']}</DisplayName>\n"
data << " </Grantee>\n"
type = case grant['Grantee'].keys.sort
when ['ID']
'CanonicalUser'
when ['EmailAddress']
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"AmazonCustomerByEmail\">\n"
data << " <EmailAddress>#{grant['Grantee']['EmailAddress']}</EmailAddress>\n"
data << " </Grantee>\n"
'AmazonCustomerByEmail'
when ['URI']
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Group\">\n"
data << " <URI>#{grant['Grantee']['URI']}</URI>\n"
data << " </Grantee>\n"
'Group'
end
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">\n"
data << " <ID>#{grant['Grantee']['ID']}</ID>\n" if grant['Grantee']['ID']
data << " <DisplayName>#{grant['Grantee']['DisplayName']}</DisplayName>\n" if grant['Grantee']['DisplayName']
data << " <EmailAddress>#{grant['Grantee']['EmailAddress']}</EmailAddress>\n" if grant['Grantee']['EmailAddress']
data << " <URI>#{grant['Grantee']['URI']}</URI>\n" if grant['Grantee']['URI']
data << " </Grantee>\n"
data << " <Permission>#{grant['Permission']}</Permission>\n"
data << " </Grant>\n"
end
data << " </AccessControlList>\n" if acl['AccessControlList'].any?
data << "</AccessControlPolicy>"
data <<
<<-DATA
</AccessControlList>
</AccessControlPolicy>
DATA
data
end
end
end
end