module Fog module Storage class AWS require 'fog/aws/parsers/storage/access_control_list' private def self.hash_to_acl(acl) data = "\n" if acl['Owner'] && (acl['Owner']['ID'] || acl['Owner']['DisplayName']) data << " \n" data << " #{acl['Owner']['ID']}\n" if acl['Owner']['ID'] data << " #{acl['Owner']['DisplayName']}\n" if acl['Owner']['DisplayName'] data << " \n" end grants = [acl['AccessControlList']].flatten.compact data << " \n" if grants.any? grants.each do |grant| data << " \n" grantee = grant['Grantee'] type = case when grantee.key?('ID') 'CanonicalUser' when grantee.key?('EmailAddress') 'AmazonCustomerByEmail' when grantee.key?('URI') 'Group' end data << " \n" case type when 'CanonicalUser' data << " #{grantee['ID']}\n" if grantee['ID'] data << " #{grantee['DisplayName']}\n" if grantee['DisplayName'] when 'AmazonCustomerByEmail' data << " #{grantee['EmailAddress']}\n" if grantee['EmailAddress'] when 'Group' data << " #{grantee['URI']}\n" if grantee['URI'] end data << " \n" data << " #{grant['Permission']}\n" data << " \n" end data << " \n" if grants.any? data << "" data end 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 end end end