2011-08-24 21:19:55 -04:00
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class AWS
|
2011-11-04 20:03:29 -04:00
|
|
|
|
2011-11-14 04:41:40 -05:00
|
|
|
require 'fog/aws/parsers/storage/access_control_list'
|
|
|
|
|
2011-08-24 21:19:55 -04:00
|
|
|
private
|
|
|
|
def self.hash_to_acl(acl)
|
2011-11-04 20:03:29 -04:00
|
|
|
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
|
2011-08-24 21:19:55 -04:00
|
|
|
|
2011-11-07 18:41:36 -05:00
|
|
|
grants = [acl['AccessControlList']].flatten.compact
|
|
|
|
|
|
|
|
data << " <AccessControlList>\n" if grants.any?
|
|
|
|
grants.each do |grant|
|
2011-08-24 21:19:55 -04:00
|
|
|
data << " <Grant>\n"
|
2011-11-07 18:41:36 -05:00
|
|
|
grantee = grant['Grantee']
|
|
|
|
type = case
|
|
|
|
when grantee.has_key?('ID')
|
2011-11-04 20:03:29 -04:00
|
|
|
'CanonicalUser'
|
2011-11-07 18:41:36 -05:00
|
|
|
when grantee.has_key?('EmailAddress')
|
2011-11-04 20:03:29 -04:00
|
|
|
'AmazonCustomerByEmail'
|
2011-11-07 18:41:36 -05:00
|
|
|
when grantee.has_key?('URI')
|
2011-11-04 20:03:29 -04:00
|
|
|
'Group'
|
2011-08-24 21:19:55 -04:00
|
|
|
end
|
2011-11-04 20:03:29 -04:00
|
|
|
|
|
|
|
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">\n"
|
2011-11-07 18:41:36 -05:00
|
|
|
case type
|
|
|
|
when 'CanonicalUser'
|
|
|
|
data << " <ID>#{grantee['ID']}</ID>\n" if grantee['ID']
|
|
|
|
data << " <DisplayName>#{grantee['DisplayName']}</DisplayName>\n" if grantee['DisplayName']
|
|
|
|
when 'AmazonCustomerByEmail'
|
|
|
|
data << " <EmailAddress>#{grantee['EmailAddress']}</EmailAddress>\n" if grantee['EmailAddress']
|
|
|
|
when 'Group'
|
|
|
|
data << " <URI>#{grantee['URI']}</URI>\n" if grantee['URI']
|
|
|
|
end
|
2011-11-04 20:03:29 -04:00
|
|
|
data << " </Grantee>\n"
|
2011-08-24 21:19:55 -04:00
|
|
|
data << " <Permission>#{grant['Permission']}</Permission>\n"
|
|
|
|
data << " </Grant>\n"
|
|
|
|
end
|
2011-11-07 18:41:36 -05:00
|
|
|
data << " </AccessControlList>\n" if grants.any?
|
2011-11-04 20:03:29 -04:00
|
|
|
|
|
|
|
data << "</AccessControlPolicy>"
|
|
|
|
|
2011-08-24 21:19:55 -04:00
|
|
|
data
|
|
|
|
end
|
2011-11-04 20:03:29 -04:00
|
|
|
|
2011-11-14 04:41:40 -05:00
|
|
|
def self.acl_to_hash(acl_xml)
|
|
|
|
parser = Fog::Parsers::Storage::AWS::AccessControlList.new
|
|
|
|
Nokogiri::XML::SAX::Parser.new(parser).parse(acl_xml)
|
|
|
|
parser.response
|
|
|
|
end
|
|
|
|
|
2011-08-24 21:19:55 -04:00
|
|
|
end
|
2011-10-27 15:19:29 -04:00
|
|
|
end
|
2011-08-24 21:19:55 -04:00
|
|
|
end
|