From 25d128d329ec2a60f906eb5997d68552c0d4b9bf Mon Sep 17 00:00:00 2001 From: Alexander Lomov Date: Thu, 9 Jan 2014 22:23:31 +0300 Subject: [PATCH] add put_object_acl request to Google Cloud Storage service --- .../google/requests/storage/put_object_acl.rb | 55 +++++++++++++++++++ lib/fog/google/storage.rb | 1 + 2 files changed, 56 insertions(+) create mode 100644 lib/fog/google/requests/storage/put_object_acl.rb diff --git a/lib/fog/google/requests/storage/put_object_acl.rb b/lib/fog/google/requests/storage/put_object_acl.rb new file mode 100644 index 000000000..69f320dd1 --- /dev/null +++ b/lib/fog/google/requests/storage/put_object_acl.rb @@ -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}" + end + + def scope_tag(scope) + if %w(AllUsers AllAuthenticatedUsers).include?(scope['type']) + "" + else + "" + + scope.to_a.select {|pair| pair[0] != 'type'}.map { |pair| tag(pair[0], pair[1]) }.join("\n") + + "" + 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 + + + #{tag('ID', acl['Owner']['ID'])} + + + #{entries_list(acl['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 diff --git a/lib/fog/google/storage.rb b/lib/fog/google/storage.rb index da20907cf..ea3ea49d7 100644 --- a/lib/fog/google/storage.rb +++ b/lib/fog/google/storage.rb @@ -31,6 +31,7 @@ module Fog request :put_bucket request :put_bucket_acl request :put_object + request :put_object_acl request :put_object_url module Utils