mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
add put_object_acl request to Google Cloud Storage service
This commit is contained in:
parent
a5d8347887
commit
25d128d329
2 changed files with 56 additions and 0 deletions
55
lib/fog/google/requests/storage/put_object_acl.rb
Normal file
55
lib/fog/google/requests/storage/put_object_acl.rb
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
module Fog
|
||||||
|
module Storage
|
||||||
|
class Google
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# TODO: move this methods to helper to use them with put_bucket_acl request
|
||||||
|
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
|
||||||
|
|
||||||
|
def put_object_acl(bucket_name, object_name, acl)
|
||||||
|
|
||||||
|
data = <<-DATA
|
||||||
|
<AccessControlList>
|
||||||
|
<Owner>
|
||||||
|
#{tag('ID', acl['Owner']['ID'])}
|
||||||
|
</Owner>
|
||||||
|
<Entries>
|
||||||
|
#{entries_list(acl['AccessControlList'])}
|
||||||
|
</Entries>
|
||||||
|
</AccessControlList>
|
||||||
|
DATA
|
||||||
|
|
||||||
|
request({
|
||||||
|
:body => data,
|
||||||
|
:expects => 200,
|
||||||
|
:headers => {},
|
||||||
|
:host => "#{bucket_name}.#{@host}",
|
||||||
|
:method => 'PUT',
|
||||||
|
:query => {'acl' => nil},
|
||||||
|
:path => CGI.escape(object_name)
|
||||||
|
})
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -31,6 +31,7 @@ module Fog
|
||||||
request :put_bucket
|
request :put_bucket
|
||||||
request :put_bucket_acl
|
request :put_bucket_acl
|
||||||
request :put_object
|
request :put_object
|
||||||
|
request :put_object_acl
|
||||||
request :put_object_url
|
request :put_object_url
|
||||||
|
|
||||||
module Utils
|
module Utils
|
||||||
|
|
Loading…
Reference in a new issue