From a53b5ed4935042d2407217697c87f3d47cbb4352 Mon Sep 17 00:00:00 2001 From: Ivan Angelov Date: Tue, 20 Nov 2018 17:29:57 +0100 Subject: [PATCH] Fix an error when the bucket ACL doesn't exist Obvious fix. --- libraries/google_storage_bucket_acl.rb | 8 +++++++- .../verify/controls/google_storage_bucket_acl.rb | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/google_storage_bucket_acl.rb b/libraries/google_storage_bucket_acl.rb index 6c285f74e..53b57245b 100644 --- a/libraries/google_storage_bucket_acl.rb +++ b/libraries/google_storage_bucket_acl.rb @@ -18,9 +18,15 @@ def initialize(opts = {}) super(opts) @bucket = opts[:bucket] @entity = opts[:entity] - catch_gcp_errors do + begin @acl = @gcp.gcp_storage_client.get_bucket_access_control(@bucket, @entity) create_resource_methods(@acl) + # all non-existing entities raise a "Not Found" client error + rescue Google::Apis::ClientError => e + # re-raise the exception if the error is not "Not Found" + raise e unless e.status_code == 404 + @acl = nil + @error = JSON.parse(e.body) end end diff --git a/test/integration/verify/controls/google_storage_bucket_acl.rb b/test/integration/verify/controls/google_storage_bucket_acl.rb index acf6c9458..adc0ab8bb 100644 --- a/test/integration/verify/controls/google_storage_bucket_acl.rb +++ b/test/integration/verify/controls/google_storage_bucket_acl.rb @@ -18,4 +18,7 @@ its('bucket') { should eq gcp_storage_bucket_acl } end -end \ No newline at end of file + describe google_storage_bucket_acl(bucket: gcp_storage_bucket_acl, entity: 'allUsers') do + it { should_not exist } + end +end