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

Added acl_to_hash helper method to Fog::Storage::AWS

* Added test for acl_to_hash
* Renamed hash_to_acl.rb to acl_utils.rb
This commit is contained in:
Arvid Andersson 2011-11-14 10:41:40 +01:00
parent a72f7175a0
commit 2c9aab802d
4 changed files with 49 additions and 5 deletions

View file

@ -2,6 +2,8 @@ module Fog
module Storage module Storage
class AWS class AWS
require 'fog/aws/parsers/storage/access_control_list'
private private
def self.hash_to_acl(acl) def self.hash_to_acl(acl)
data = "<AccessControlPolicy>\n" data = "<AccessControlPolicy>\n"
@ -49,6 +51,12 @@ module Fog
data data
end 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 end
end end

View file

@ -3,7 +3,7 @@ module Fog
class AWS class AWS
class Real 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 # Change access control list for an S3 bucket
# #

View file

@ -3,7 +3,7 @@ module Fog
class AWS class AWS
class Real 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 # Change access control list for an S3 object
# #

View file

@ -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") do
tests(".hash_to_acl({}) at xpath //AccessControlPolicy").returns("", "has an empty AccessControlPolicy") do tests(".hash_to_acl({}) at xpath //AccessControlPolicy").returns("", "has an empty AccessControlPolicy") do
xml = Fog::Storage::AWS.hash_to_acl({}) 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 Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/URI").first.content
end end
end end
tests(".acl_to_hash") do
acl_xml = <<-XML
<AccessControlPolicy>
<Owner>
<ID>2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0</ID>
<DisplayName>me</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
<ID>2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0</ID>
<DisplayName>me</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>
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 end