diff --git a/lib/fog/aws/requests/storage/hash_to_acl.rb b/lib/fog/aws/requests/storage/hash_to_acl.rb index 31431f5dd..0d939243e 100644 --- a/lib/fog/aws/requests/storage/hash_to_acl.rb +++ b/lib/fog/aws/requests/storage/hash_to_acl.rb @@ -1,47 +1,46 @@ module Fog module Storage class AWS + private def self.hash_to_acl(acl) - data = -<<-DATA - - - #{acl['Owner']['ID']} - #{acl['Owner']['DisplayName']} - - -DATA + 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 + + data << " \n" if acl['AccessControlList'].any? acl['AccessControlList'].each do |grant| data << " \n" - case grant['Grantee'].keys.sort - when ['DisplayName', 'ID'] - data << " \n" - data << " #{grant['Grantee']['ID']}\n" - data << " #{grant['Grantee']['DisplayName']}\n" - data << " \n" + type = case grant['Grantee'].keys.sort + when ['ID'] + 'CanonicalUser' when ['EmailAddress'] - data << " \n" - data << " #{grant['Grantee']['EmailAddress']}\n" - data << " \n" + 'AmazonCustomerByEmail' when ['URI'] - data << " \n" - data << " #{grant['Grantee']['URI']}\n" - data << " \n" + 'Group' end + + data << " \n" + data << " #{grant['Grantee']['ID']}\n" if grant['Grantee']['ID'] + data << " #{grant['Grantee']['DisplayName']}\n" if grant['Grantee']['DisplayName'] + data << " #{grant['Grantee']['EmailAddress']}\n" if grant['Grantee']['EmailAddress'] + data << " #{grant['Grantee']['URI']}\n" if grant['Grantee']['URI'] + data << " \n" data << " #{grant['Permission']}\n" data << " \n" end - - data << -<<-DATA - - -DATA + data << " \n" if acl['AccessControlList'].any? + + data << "" + data end + end end end -