Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): per-operation options / DefaultObjectAccessControl #9203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions google/cloud/storage/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,7 @@ class Client {
template <typename... Options>
StatusOr<std::vector<ObjectAccessControl>> ListDefaultObjectAcl(
std::string const& bucket_name, Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::ListDefaultObjectAclRequest request(bucket_name);
request.set_multiple_options(std::forward<Options>(options)...);
auto response = raw_client_->ListDefaultObjectAcl(request);
Expand Down Expand Up @@ -2250,6 +2251,7 @@ class Client {
StatusOr<ObjectAccessControl> CreateDefaultObjectAcl(
std::string const& bucket_name, std::string const& entity,
std::string const& role, Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::CreateDefaultObjectAclRequest request(bucket_name, entity, role);
request.set_multiple_options(std::forward<Options>(options)...);
return raw_client_->CreateDefaultObjectAcl(request);
Expand Down Expand Up @@ -2282,6 +2284,7 @@ class Client {
Status DeleteDefaultObjectAcl(std::string const& bucket_name,
std::string const& entity,
Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::DeleteDefaultObjectAclRequest request(bucket_name, entity);
request.set_multiple_options(std::forward<Options>(options)...);
return raw_client_->DeleteDefaultObjectAcl(request).status();
Expand Down Expand Up @@ -2313,6 +2316,7 @@ class Client {
StatusOr<ObjectAccessControl> GetDefaultObjectAcl(
std::string const& bucket_name, std::string const& entity,
Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::GetDefaultObjectAclRequest request(bucket_name, entity);
request.set_multiple_options(std::forward<Options>(options)...);
return raw_client_->GetDefaultObjectAcl(request);
Expand Down Expand Up @@ -2355,6 +2359,7 @@ class Client {
StatusOr<ObjectAccessControl> UpdateDefaultObjectAcl(
std::string const& bucket_name, ObjectAccessControl const& acl,
Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::UpdateDefaultObjectAclRequest request(bucket_name, acl.entity(),
acl.role());
request.set_multiple_options(std::forward<Options>(options)...);
Expand Down Expand Up @@ -2404,6 +2409,7 @@ class Client {
std::string const& bucket_name, std::string const& entity,
ObjectAccessControl const& original_acl,
ObjectAccessControl const& new_acl, Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::PatchDefaultObjectAclRequest request(bucket_name, entity,
original_acl, new_acl);
request.set_multiple_options(std::forward<Options>(options)...);
Expand Down Expand Up @@ -2451,6 +2457,7 @@ class Client {
StatusOr<ObjectAccessControl> PatchDefaultObjectAcl(
std::string const& bucket_name, std::string const& entity,
ObjectAccessControlPatchBuilder const& builder, Options&&... options) {
auto const span = MakeSpan(std::forward<Options>(options)...);
internal::PatchDefaultObjectAclRequest request(bucket_name, entity,
builder);
request.set_multiple_options(std::forward<Options>(options)...);
Expand Down
37 changes: 29 additions & 8 deletions google/cloud/storage/client_default_object_acl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace storage {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

using ::google::cloud::internal::CurrentOptions;
using ::google::cloud::storage::testing::canonical_errors::TransientError;
using ::testing::Return;
using ms = std::chrono::milliseconds;
Expand Down Expand Up @@ -58,14 +59,17 @@ TEST_F(DefaultObjectAccessControlsTest, ListDefaultObjectAcl) {
.WillOnce(Return(
StatusOr<internal::ListDefaultObjectAclResponse>(TransientError())))
.WillOnce([&expected](internal::ListDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());

return make_status_or(internal::ListDefaultObjectAclResponse{expected});
});

auto client = ClientForMock();
StatusOr<std::vector<ObjectAccessControl>> actual =
client.ListDefaultObjectAcl("test-bucket");
client.ListDefaultObjectAcl("test-bucket",
Options{}.set<UserProjectOption>("u-p-test"));
ASSERT_STATUS_OK(actual);
EXPECT_EQ(expected, *actual);
}
Expand Down Expand Up @@ -100,6 +104,8 @@ TEST_F(DefaultObjectAccessControlsTest, CreateDefaultObjectAcl) {
EXPECT_CALL(*mock_, CreateDefaultObjectAcl)
.WillOnce(Return(StatusOr<ObjectAccessControl>(TransientError())))
.WillOnce([&expected](internal::CreateDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());
EXPECT_EQ("user-test-user-1", r.entity());
EXPECT_EQ("READER", r.role());
Expand All @@ -108,7 +114,8 @@ TEST_F(DefaultObjectAccessControlsTest, CreateDefaultObjectAcl) {
});
auto client = ClientForMock();
StatusOr<ObjectAccessControl> actual = client.CreateDefaultObjectAcl(
"test-bucket", "user-test-user-1", ObjectAccessControl::ROLE_READER());
"test-bucket", "user-test-user-1", ObjectAccessControl::ROLE_READER(),
Options{}.set<UserProjectOption>("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.
Expand Down Expand Up @@ -153,13 +160,17 @@ TEST_F(DefaultObjectAccessControlsTest, DeleteDefaultObjectAcl) {
EXPECT_CALL(*mock_, DeleteDefaultObjectAcl)
.WillOnce(Return(StatusOr<internal::EmptyResponse>(TransientError())))
.WillOnce([](internal::DeleteDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());
EXPECT_EQ("user-test-user", r.entity());

return make_status_or(internal::EmptyResponse{});
});
auto client = ClientForMock();
auto status = client.DeleteDefaultObjectAcl("test-bucket", "user-test-user");
auto status = client.DeleteDefaultObjectAcl(
"test-bucket", "user-test-user",
Options{}.set<UserProjectOption>("u-p-test"));
ASSERT_STATUS_OK(status);
}

Expand Down Expand Up @@ -201,14 +212,17 @@ TEST_F(DefaultObjectAccessControlsTest, GetDefaultObjectAcl) {
EXPECT_CALL(*mock_, GetDefaultObjectAcl)
.WillOnce(Return(StatusOr<ObjectAccessControl>(TransientError())))
.WillOnce([&expected](internal::GetDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());
EXPECT_EQ("user-test-user-1", r.entity());

return make_status_or(expected);
});
auto client = ClientForMock();
StatusOr<ObjectAccessControl> actual =
client.GetDefaultObjectAcl("test-bucket", "user-test-user-1");
client.GetDefaultObjectAcl("test-bucket", "user-test-user-1",
Options{}.set<UserProjectOption>("u-p-test"));
ASSERT_STATUS_OK(actual);
EXPECT_EQ(expected, *actual);
}
Expand Down Expand Up @@ -247,6 +261,8 @@ TEST_F(DefaultObjectAccessControlsTest, UpdateDefaultObjectAcl) {
EXPECT_CALL(*mock_, UpdateDefaultObjectAcl)
.WillOnce(Return(StatusOr<ObjectAccessControl>(TransientError())))
.WillOnce([&expected](internal::UpdateDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());
EXPECT_EQ("user-test-user-1", r.entity());
EXPECT_EQ("READER", r.role());
Expand All @@ -255,9 +271,11 @@ TEST_F(DefaultObjectAccessControlsTest, UpdateDefaultObjectAcl) {
});
auto client = ClientForMock();
StatusOr<ObjectAccessControl> actual = client.UpdateDefaultObjectAcl(
"test-bucket", ObjectAccessControl()
.set_entity("user-test-user-1")
.set_role(ObjectAccessControl::ROLE_READER()));
"test-bucket",
ObjectAccessControl()
.set_entity("user-test-user-1")
.set_role(ObjectAccessControl::ROLE_READER()),
Options{}.set<UserProjectOption>("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.
Expand Down Expand Up @@ -307,6 +325,8 @@ TEST_F(DefaultObjectAccessControlsTest, PatchDefaultObjectAcl) {
EXPECT_CALL(*mock_, PatchDefaultObjectAcl)
.WillOnce(Return(StatusOr<ObjectAccessControl>(TransientError())))
.WillOnce([result](internal::PatchDefaultObjectAclRequest const& r) {
EXPECT_EQ(CurrentOptions().get<AuthorityOption>(), "a-default");
EXPECT_EQ(CurrentOptions().get<UserProjectOption>(), "u-p-test");
EXPECT_EQ("test-bucket", r.bucket_name());
EXPECT_EQ("user-test-user-1", r.entity());
nlohmann::json expected{{"role", "OWNER"}};
Expand All @@ -318,7 +338,8 @@ TEST_F(DefaultObjectAccessControlsTest, PatchDefaultObjectAcl) {
auto client = ClientForMock();
auto actual = client.PatchDefaultObjectAcl(
"test-bucket", "user-test-user-1",
ObjectAccessControlPatchBuilder().set_role("OWNER"));
ObjectAccessControlPatchBuilder().set_role("OWNER"),
Options{}.set<UserProjectOption>("u-p-test"));
ASSERT_STATUS_OK(actual);
EXPECT_EQ(result, *actual);
}
Expand Down