From 3ba8eb2d9e78ed02c2f54626bcc7f7e9b2c99c38 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Tue, 7 Jun 2022 23:41:47 +0000 Subject: [PATCH] feat(storage): per-operation options / ObjectAccessControl Support per-operation `google::cloud::Options` for operations related to `ObjectAccessControl` resources. --- google/cloud/storage/client.h | 7 ++++ .../cloud/storage/client_object_acl_test.cc | 36 ++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/google/cloud/storage/client.h b/google/cloud/storage/client.h index c2006762910a4..43521ded3b86c 100644 --- a/google/cloud/storage/client.h +++ b/google/cloud/storage/client.h @@ -1938,6 +1938,7 @@ class Client { StatusOr> ListObjectAcl( std::string const& bucket_name, std::string const& object_name, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::ListObjectAclRequest request(bucket_name, object_name); request.set_multiple_options(std::forward(options)...); auto result = raw_client_->ListObjectAcl(request); @@ -1975,6 +1976,7 @@ class Client { std::string const& entity, std::string const& role, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::CreateObjectAclRequest request(bucket_name, object_name, entity, role); request.set_multiple_options(std::forward(options)...); @@ -2005,6 +2007,7 @@ class Client { Status DeleteObjectAcl(std::string const& bucket_name, std::string const& object_name, std::string const& entity, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::DeleteObjectAclRequest request(bucket_name, object_name, entity); request.set_multiple_options(std::forward(options)...); return raw_client_->DeleteObjectAcl(request).status(); @@ -2033,6 +2036,7 @@ class Client { std::string const& object_name, std::string const& entity, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::GetObjectAclRequest request(bucket_name, object_name, entity); request.set_multiple_options(std::forward(options)...); return raw_client_->GetObjectAcl(request); @@ -2072,6 +2076,7 @@ class Client { std::string const& object_name, ObjectAccessControl const& acl, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::UpdateObjectAclRequest request(bucket_name, object_name, acl.entity(), acl.role()); request.set_multiple_options(std::forward(options)...); @@ -2119,6 +2124,7 @@ class Client { std::string const& bucket_name, std::string const& object_name, std::string const& entity, ObjectAccessControl const& original_acl, ObjectAccessControl const& new_acl, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::PatchObjectAclRequest request(bucket_name, object_name, entity, original_acl, new_acl); request.set_multiple_options(std::forward(options)...); @@ -2164,6 +2170,7 @@ class Client { std::string const& bucket_name, std::string const& object_name, std::string const& entity, ObjectAccessControlPatchBuilder const& builder, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::PatchObjectAclRequest request(bucket_name, object_name, entity, builder); request.set_multiple_options(std::forward(options)...); diff --git a/google/cloud/storage/client_object_acl_test.cc b/google/cloud/storage/client_object_acl_test.cc index 048a2947bf112..f0e1804bfc8d8 100644 --- a/google/cloud/storage/client_object_acl_test.cc +++ b/google/cloud/storage/client_object_acl_test.cc @@ -27,6 +27,7 @@ namespace cloud { namespace storage { namespace { +using ::google::cloud::internal::CurrentOptions; using ::google::cloud::storage::testing::canonical_errors::TransientError; using ::testing::Return; using ms = std::chrono::milliseconds; @@ -59,6 +60,8 @@ TEST_F(ObjectAccessControlsTest, ListObjectAcl) { .WillOnce( Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::ListObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); @@ -66,7 +69,8 @@ TEST_F(ObjectAccessControlsTest, ListObjectAcl) { }); auto client = ClientForMock(); StatusOr> actual = - client.ListObjectAcl("test-bucket", "test-object"); + client.ListObjectAcl("test-bucket", "test-object", + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -104,6 +108,8 @@ TEST_F(ObjectAccessControlsTest, CreateObjectAcl) { EXPECT_CALL(*mock_, CreateObjectAcl) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::CreateObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); EXPECT_EQ("user-test-user-1", r.entity()); @@ -114,7 +120,8 @@ TEST_F(ObjectAccessControlsTest, CreateObjectAcl) { auto client = ClientForMock(); StatusOr actual = client.CreateObjectAcl("test-bucket", "test-object", "user-test-user-1", - ObjectAccessControl::ROLE_READER()); + ObjectAccessControl::ROLE_READER(), + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); // Compare just a few fields because the values for most of the fields are // hard to predict when testing against the production environment. @@ -159,6 +166,8 @@ TEST_F(ObjectAccessControlsTest, DeleteObjectAcl) { EXPECT_CALL(*mock_, DeleteObjectAcl) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([](internal::DeleteObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); EXPECT_EQ("user-test-user", r.entity()); @@ -166,7 +175,8 @@ TEST_F(ObjectAccessControlsTest, DeleteObjectAcl) { return make_status_or(internal::EmptyResponse{}); }); auto client = ClientForMock(); - client.DeleteObjectAcl("test-bucket", "test-object", "user-test-user"); + client.DeleteObjectAcl("test-bucket", "test-object", "user-test-user", + Options{}.set("u-p-test")); SUCCEED(); } @@ -207,6 +217,8 @@ TEST_F(ObjectAccessControlsTest, GetObjectAcl) { EXPECT_CALL(*mock_, GetObjectAcl) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::GetObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); EXPECT_EQ("user-test-user-1", r.entity()); @@ -215,7 +227,8 @@ TEST_F(ObjectAccessControlsTest, GetObjectAcl) { }); auto client = ClientForMock(); StatusOr actual = - client.GetObjectAcl("test-bucket", "test-object", "user-test-user-1"); + client.GetObjectAcl("test-bucket", "test-object", "user-test-user-1", + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -256,6 +269,8 @@ TEST_F(ObjectAccessControlsTest, UpdateObjectAcl) { EXPECT_CALL(*mock_, UpdateObjectAcl) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([expected](internal::UpdateObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); EXPECT_EQ("user-test-user", r.entity()); @@ -266,7 +281,9 @@ TEST_F(ObjectAccessControlsTest, UpdateObjectAcl) { ObjectAccessControl acl = ObjectAccessControl().set_role("OWNER").set_entity("user-test-user"); auto client = ClientForMock(); - auto actual = client.UpdateObjectAcl("test-bucket", "test-object", acl); + auto actual = + client.UpdateObjectAcl("test-bucket", "test-object", acl, + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -313,6 +330,8 @@ TEST_F(ObjectAccessControlsTest, PatchObjectAcl) { EXPECT_CALL(*mock_, PatchObjectAcl) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([result](internal::PatchObjectAclRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket", r.bucket_name()); EXPECT_EQ("test-object", r.object_name()); EXPECT_EQ("user-test-user-1", r.entity()); @@ -323,9 +342,10 @@ TEST_F(ObjectAccessControlsTest, PatchObjectAcl) { return make_status_or(result); }); auto client = ClientForMock(); - auto actual = client.PatchObjectAcl( - "test-bucket", "test-object", "user-test-user-1", - ObjectAccessControlPatchBuilder().set_role("OWNER")); + auto actual = + client.PatchObjectAcl("test-bucket", "test-object", "user-test-user-1", + ObjectAccessControlPatchBuilder().set_role("OWNER"), + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(result, *actual); }