From 47f5a04c3e3e7fd43e4c1482f7a515c59bc61c0a Mon Sep 17 00:00:00 2001 From: Alexander Lomov Date: Thu, 9 Jan 2014 21:47:32 +0300 Subject: [PATCH] fix put_bucket_acl request for Google Cloud Storage service --- .../google/requests/storage/put_bucket_acl.rb | 87 +++++++++---------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/lib/fog/google/requests/storage/put_bucket_acl.rb b/lib/fog/google/requests/storage/put_bucket_acl.rb index 2aa6a1163..36e03ebd5 100644 --- a/lib/fog/google/requests/storage/put_bucket_acl.rb +++ b/lib/fog/google/requests/storage/put_bucket_acl.rb @@ -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 - + + data = <<-DATA + - #{acl['Owner']['ID']} - #{acl['Owner']['DisplayName']} + #{tag('ID', acl['Owner']['ID'])} - -DATA - - acl['AccessControlList'].each do |grant| - data << " " - type = case grant['Grantee'].keys.sort - when ['DisplayName', 'ID'] - 'CanonicalUser' - when ['EmailAddress'] - 'AmazonCustomerByEmail' - when ['URI'] - 'Group' - end - data << " " - for key, value in grant['Grantee'] - data << " <#{key}>#{value}" - end - data << " " - data << " #{grant['Permission']}" - data << " " - end - - data << -<<-DATA - - + + #{entries_list(acl['AccessControlList'].dup)} + + DATA request({ @@ -67,7 +34,31 @@ DATA }) end + + private + + 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 + end + end end end