Skip to content

Commit 7a9f0af

Browse files
authored
feat(GCS+gRPC): implement GetObjectMetadata (#8048)
1 parent 0d77e69 commit 7a9f0af

21 files changed

+225
-3
lines changed

generator/generator_config.textproto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ service {
511511
"ListNotifications",
512512
"ComposeObject",
513513
"DeleteObject",
514-
"GetObject",
515514
"UpdateObject",
516515
"ListObjects",
517516
"RewriteObject",

google/cloud/storage/internal/grpc_client.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,13 @@ StatusOr<ObjectMetadata> GrpcClient::CopyObject(CopyObjectRequest const&) {
261261
}
262262

263263
StatusOr<ObjectMetadata> GrpcClient::GetObjectMetadata(
264-
GetObjectMetadataRequest const&) {
265-
return Status(StatusCode::kUnimplemented, __func__);
264+
GetObjectMetadataRequest const& request) {
265+
auto proto = GrpcObjectRequestParser::ToProto(request);
266+
grpc::ClientContext context;
267+
ApplyQueryParameters(context, request, "");
268+
auto response = stub_->GetObject(context, proto);
269+
if (!response) return std::move(response).status();
270+
return GrpcObjectMetadataParser::FromProto(*response, options_);
266271
}
267272

268273
StatusOr<std::unique_ptr<ObjectReadSource>> GrpcClient::ReadObject(

google/cloud/storage/internal/grpc_object_request_parser.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ GrpcObjectRequestParser::ToProto(ReadObjectRangeRequest const& request) {
324324
return r;
325325
}
326326

327+
google::storage::v2::GetObjectRequest GrpcObjectRequestParser::ToProto(
328+
GetObjectMetadataRequest const& request) {
329+
google::storage::v2::GetObjectRequest result;
330+
SetGenerationConditions(result, request);
331+
SetMetagenerationConditions(result, request);
332+
SetCommonParameters(result, request);
333+
334+
result.set_bucket("projects/_/buckets/" + request.bucket_name());
335+
result.set_object(request.object_name());
336+
result.set_generation(request.GetOption<Generation>().value_or(0));
337+
auto projection = request.GetOption<Projection>().value_or("");
338+
if (projection == "full") result.mutable_read_mask()->add_paths("*");
339+
return result;
340+
}
341+
327342
} // namespace internal
328343
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
329344
} // namespace storage

google/cloud/storage/internal/grpc_object_request_parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct GrpcObjectRequestParser {
4141

4242
static StatusOr<google::storage::v2::ReadObjectRequest> ToProto(
4343
ReadObjectRangeRequest const& request);
44+
45+
static google::storage::v2::GetObjectRequest ToProto(
46+
GetObjectMetadataRequest const& request);
4447
};
4548

4649
} // namespace internal

google/cloud/storage/internal/grpc_object_request_parser_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,33 @@ TEST(GrpcObjectRequestParser, PredefinedAclObject) {
550550
GrpcObjectRequestParser::ToProtoObject(PredefinedAcl::BucketOwnerRead()));
551551
}
552552

553+
TEST(GrpcObjectRequestParser, GetObjectMetadataAllFields) {
554+
google::storage::v2::GetObjectRequest expected;
555+
EXPECT_TRUE(google::protobuf::TextFormat::ParseFromString(
556+
R"pb(
557+
bucket: "projects/_/buckets/test-bucket"
558+
object: "test-object"
559+
generation: 7
560+
if_generation_match: 1
561+
if_generation_not_match: 2
562+
if_metageneration_match: 3
563+
if_metageneration_not_match: 4
564+
common_request_params: { user_project: "test-user-project" }
565+
read_mask { paths: "*" }
566+
)pb",
567+
&expected));
568+
569+
GetObjectMetadataRequest req("test-bucket", "test-object");
570+
req.set_multiple_options(
571+
Generation(7), IfGenerationMatch(1), IfGenerationNotMatch(2),
572+
IfMetagenerationMatch(3), IfMetagenerationNotMatch(4), Projection("full"),
573+
UserProject("test-user-project"), UserProject("test-user-project"),
574+
QuotaUser("test-quota-user"), UserIp("test-user-ip"));
575+
576+
auto const actual = GrpcObjectRequestParser::ToProto(req);
577+
EXPECT_THAT(actual, IsProtoEqual(expected));
578+
}
579+
553580
} // namespace
554581
} // namespace internal
555582
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/storage/internal/storage_auth_decorator.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ StorageAuth::StorageAuth(
3030
std::shared_ptr<StorageStub> child)
3131
: auth_(std::move(auth)), child_(std::move(child)) {}
3232

33+
StatusOr<google::storage::v2::Object> StorageAuth::GetObject(
34+
grpc::ClientContext& context,
35+
google::storage::v2::GetObjectRequest const& request) {
36+
auto status = auth_->ConfigureContext(context);
37+
if (!status.ok()) return status;
38+
return child_->GetObject(context, request);
39+
}
40+
3341
std::unique_ptr<google::cloud::internal::StreamingReadRpc<
3442
google::storage::v2::ReadObjectResponse>>
3543
StorageAuth::ReadObject(std::unique_ptr<grpc::ClientContext> context,

google/cloud/storage/internal/storage_auth_decorator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class StorageAuth : public StorageStub {
3838
std::shared_ptr<google::cloud::internal::GrpcAuthenticationStrategy> auth,
3939
std::shared_ptr<StorageStub> child);
4040

41+
StatusOr<google::storage::v2::Object> GetObject(
42+
grpc::ClientContext& context,
43+
google::storage::v2::GetObjectRequest const& request) override;
44+
4145
std::unique_ptr<google::cloud::internal::StreamingReadRpc<
4246
google::storage::v2::ReadObjectResponse>>
4347
ReadObject(std::unique_ptr<grpc::ClientContext> context,

google/cloud/storage/internal/storage_logging_decorator.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ StorageLogging::StorageLogging(std::shared_ptr<StorageStub> child,
3636
tracing_options_(std::move(tracing_options)),
3737
components_(std::move(components)) {}
3838

39+
StatusOr<google::storage::v2::Object> StorageLogging::GetObject(
40+
grpc::ClientContext& context,
41+
google::storage::v2::GetObjectRequest const& request) {
42+
return google::cloud::internal::LogWrapper(
43+
[this](grpc::ClientContext& context,
44+
google::storage::v2::GetObjectRequest const& request) {
45+
return child_->GetObject(context, request);
46+
},
47+
context, request, __func__, tracing_options_);
48+
}
49+
3950
std::unique_ptr<google::cloud::internal::StreamingReadRpc<
4051
google::storage::v2::ReadObjectResponse>>
4152
StorageLogging::ReadObject(

google/cloud/storage/internal/storage_logging_decorator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class StorageLogging : public StorageStub {
3838
TracingOptions tracing_options,
3939
std::set<std::string> components);
4040

41+
StatusOr<google::storage::v2::Object> GetObject(
42+
grpc::ClientContext& context,
43+
google::storage::v2::GetObjectRequest const& request) override;
44+
4145
std::unique_ptr<google::cloud::internal::StreamingReadRpc<
4246
google::storage::v2::ReadObjectResponse>>
4347
ReadObject(std::unique_ptr<grpc::ClientContext> context,

google/cloud/storage/internal/storage_metadata_decorator.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ StorageMetadata::StorageMetadata(std::shared_ptr<StorageStub> child)
3232
api_client_header_(
3333
google::cloud::internal::ApiClientHeader("generator")) {}
3434

35+
StatusOr<google::storage::v2::Object> StorageMetadata::GetObject(
36+
grpc::ClientContext& context,
37+
google::storage::v2::GetObjectRequest const& request) {
38+
SetMetadata(context, {});
39+
return child_->GetObject(context, request);
40+
}
41+
3542
std::unique_ptr<google::cloud::internal::StreamingReadRpc<
3643
google::storage::v2::ReadObjectResponse>>
3744
StorageMetadata::ReadObject(

0 commit comments

Comments
 (0)