diff --git a/lib/fog/aws/requests/storage/hash_to_acl.rb b/lib/fog/aws/requests/storage/acl_utils.rb similarity index 87% rename from lib/fog/aws/requests/storage/hash_to_acl.rb rename to lib/fog/aws/requests/storage/acl_utils.rb index ea66689a2..b11689bd2 100644 --- a/lib/fog/aws/requests/storage/hash_to_acl.rb +++ b/lib/fog/aws/requests/storage/acl_utils.rb @@ -2,6 +2,8 @@ module Fog module Storage class AWS + require 'fog/aws/parsers/storage/access_control_list' + private def self.hash_to_acl(acl) data = "\n" @@ -49,6 +51,12 @@ module Fog 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 diff --git a/lib/fog/aws/requests/storage/put_bucket_acl.rb b/lib/fog/aws/requests/storage/put_bucket_acl.rb index 019396eec..20351a012 100644 --- a/lib/fog/aws/requests/storage/put_bucket_acl.rb +++ b/lib/fog/aws/requests/storage/put_bucket_acl.rb @@ -3,8 +3,8 @@ module Fog class AWS class Real - require 'fog/aws/requests/storage/hash_to_acl' - + require 'fog/aws/requests/storage/acl_utils' + # Change access control list for an S3 bucket # # ==== Parameters diff --git a/lib/fog/aws/requests/storage/put_object_acl.rb b/lib/fog/aws/requests/storage/put_object_acl.rb index 9f14cc6d8..5b151463b 100644 --- a/lib/fog/aws/requests/storage/put_object_acl.rb +++ b/lib/fog/aws/requests/storage/put_object_acl.rb @@ -3,7 +3,7 @@ module Fog class AWS class Real - require 'fog/aws/requests/storage/hash_to_acl' + require 'fog/aws/requests/storage/acl_utils' # Change access control list for an S3 object # diff --git a/tests/aws/requests/storage/hash_to_acl_tests.rb b/tests/aws/requests/storage/acl_utils_tests.rb similarity index 87% rename from tests/aws/requests/storage/hash_to_acl_tests.rb rename to tests/aws/requests/storage/acl_utils_tests.rb index 5f07a7da6..84b932596 100644 --- a/tests/aws/requests/storage/hash_to_acl_tests.rb +++ b/tests/aws/requests/storage/acl_utils_tests.rb @@ -1,6 +1,6 @@ -require 'fog/aws/requests/storage/hash_to_acl' +require 'fog/aws/requests/storage/acl_utils' -Shindo.tests('Fog::Storage::AWS | converting a hash to an ACL', [:aws]) do +Shindo.tests('Fog::Storage::AWS | ACL utils', [:aws]) do tests(".hash_to_acl") do tests(".hash_to_acl({}) at xpath //AccessControlPolicy").returns("", "has an empty AccessControlPolicy") do xml = Fog::Storage::AWS.hash_to_acl({}) @@ -170,4 +170,40 @@ Shindo.tests('Fog::Storage::AWS | converting a hash to an ACL', [:aws]) do Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/URI").first.content end end + + tests(".acl_to_hash") do + acl_xml = <<-XML + + + 2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0 + me + + + + + 2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0 + me + + FULL_CONTROL + + + +XML + + tests(".acl_to_hash(#{acl_xml.inspect})").returns({ + "Owner" => { + "DisplayName" => "me", + "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" + }, + "AccessControlList" => [{ + "Grantee" => { + "DisplayName" => "me", + "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" + }, + "Permission" => "FULL_CONTROL" + }] + }, 'returns hash of ACL XML') do + Fog::Storage::AWS.acl_to_hash(acl_xml) + end + end end