Skip to content

Commit

Permalink
Fix error on file predefined ACL helpers
Browse files Browse the repository at this point in the history
The helpers were not working and returning the following error:

    Cannot provide both a predefinedAcl and access controls.

This is because the predefinedAcl was being set and the existing acl rules were
not being overridden. The fix is to provide empty rules so the predefinedAcl
rule can be applied.

[refs googleapis#381]
  • Loading branch information
blowmage committed Oct 20, 2015
1 parent 7b9923d commit fd63239
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/gcloud/storage/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def download_file bucket_name, file_path
def patch_file bucket_name, file_path, options = {}
params = { bucket: bucket_name,
object: file_path,
predefinedAcl: options[:acl]
predefinedAcl: options[:predefined_acl]
}.delete_if { |_, v| v.nil? }

@client.execute(
Expand Down Expand Up @@ -395,7 +395,8 @@ def patch_file_request options = {}
"contentEncoding" => options[:content_encoding],
"contentLanguage" => options[:content_language],
"contentType" => options[:content_type],
"metadata" => options[:metadata]
"metadata" => options[:metadata],
"acl" => options[:acl]
}.delete_if { |_, v| v.nil? }
end

Expand Down
3 changes: 2 additions & 1 deletion lib/gcloud/storage/file/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ def clear!

def update_predefined_acl! acl_role
resp = @connection.patch_file @bucket, @file,
acl: acl_role
predefined_acl: acl_role,
acl: []

return clear! if resp.success?
fail Gcloud::Storage::ApiError.from_response(resp)
Expand Down
1 change: 1 addition & 0 deletions test/gcloud/storage/file_acl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
def predefined_acl_update acl_role
mock_connection.patch "/storage/v1/b/#{bucket_name}/o/#{file_name}" do |env|
env.params["predefinedAcl"].must_equal acl_role
JSON.parse(env.body)["acl"].must_equal []
[200, {"Content-Type"=>"application/json"},
random_file_hash(bucket_name, file_name).to_json]
end
Expand Down

0 comments on commit fd63239

Please sign in to comment.