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:
parent
a72f7175a0
commit
2c9aab802d
4 changed files with 49 additions and 5 deletions
|
@ -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 = "<AccessControlPolicy>\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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
||||
<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
|
Loading…
Reference in a new issue