mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
fix put_bucket_acl request for Google Cloud Storage service
This commit is contained in:
parent
a5d8347887
commit
47f5a04c3e
1 changed files with 39 additions and 48 deletions
|
@ -1,60 +1,27 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def put_bucket_acl(bucket_name, acl)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
# Change access control list for an Google Storage bucket
|
||||
#
|
||||
# ==== Parameters
|
||||
# * bucket_name<~String> - name of bucket to modify
|
||||
# * acl<~Hash>:
|
||||
# * Owner<~Hash>:
|
||||
# * ID<~String>: id of owner
|
||||
# * DisplayName<~String>: display name of owner
|
||||
# * AccessControlList<~Array>:
|
||||
# * scope<~Hash>:
|
||||
# * 'type'<~String> - 'UserById'
|
||||
# * 'ID'<~String> - Id of grantee
|
||||
# or
|
||||
# * 'type'<~String> - 'UserByEmail'
|
||||
# * 'EmailAddress'<~String> - Email address of grantee
|
||||
# or
|
||||
# * 'type'<~String> - type of user to grant permission to
|
||||
# * Permission<~String> - Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
||||
def put_bucket_acl(bucket_name, acl)
|
||||
data =
|
||||
<<-DATA
|
||||
<AccessControlPolicy>
|
||||
|
||||
data = <<-DATA
|
||||
<AccessControlList>
|
||||
<Owner>
|
||||
<ID>#{acl['Owner']['ID']}</ID>
|
||||
<DisplayName>#{acl['Owner']['DisplayName']}</DisplayName>
|
||||
#{tag('ID', acl['Owner']['ID'])}
|
||||
</Owner>
|
||||
<AccessControlList>
|
||||
DATA
|
||||
|
||||
acl['AccessControlList'].each do |grant|
|
||||
data << " <Grant>"
|
||||
type = case grant['Grantee'].keys.sort
|
||||
when ['DisplayName', 'ID']
|
||||
'CanonicalUser'
|
||||
when ['EmailAddress']
|
||||
'AmazonCustomerByEmail'
|
||||
when ['URI']
|
||||
'Group'
|
||||
end
|
||||
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">"
|
||||
for key, value in grant['Grantee']
|
||||
data << " <#{key}>#{value}</#{key}>"
|
||||
end
|
||||
data << " </Grantee>"
|
||||
data << " <Permission>#{grant['Permission']}</Permission>"
|
||||
data << " </Grant>"
|
||||
end
|
||||
|
||||
data <<
|
||||
<<-DATA
|
||||
</AccessControlList>
|
||||
</AccessControlPolicy>
|
||||
<Entries>
|
||||
#{entries_list(acl['AccessControlList'].dup)}
|
||||
</Entries>
|
||||
</AccessControlList>
|
||||
DATA
|
||||
|
||||
request({
|
||||
|
@ -67,7 +34,31 @@ DATA
|
|||
})
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def tag(name, value)
|
||||
"<#{name}>#{value}</#{name}>"
|
||||
end
|
||||
|
||||
def scope_tag(scope)
|
||||
if %w(AllUsers AllAuthenticatedUsers).include?(scope['type'])
|
||||
"<Scope type='#{scope['type']}'/>"
|
||||
else
|
||||
"<Scope type='#{scope['type']}'>" +
|
||||
scope.to_a.select { |pair| pair[0] != 'type' }.map { |pair| tag(pair[0], pair[1]) }.join("\n") +
|
||||
"</Scope>"
|
||||
end
|
||||
end
|
||||
|
||||
def entries_list(access_control_list)
|
||||
access_control_list.map do |entry|
|
||||
tag('Entry', scope_tag(entry['Scope']) + tag('Permission', entry['Permission']))
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue