Repository navigation
fix(storage): align gRPC parsers with REST object retention fields - #16719
nidhiii-27 wants to merge 1 commit into
Conversation
The gRPC bucket and object parsers now convert object retention settings, bucket object retention configuration, and the override unlocked retention flag to and from google.storage.v2 protobuf messages. Existing REST transport serialization and other gRPC bucket and object request and metadata fields remain unchanged. Updated unit tests in bucket_request_parser_test, bucket_metadata_parser_test, object_metadata_parser_test, object_request_parser_test, and stub_test to verify protobuf conversion and error propagation for these fields. [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces support for bucket and object retention in the gRPC transport layer of the Google Cloud Storage C++ SDK. It adds conversion functions (ToProto and FromProto) for bucket and object retention metadata, handles retention-related options in request parsers, and updates the gRPC stub to handle status returns correctly. Comprehensive unit tests are also added to verify the roundtrip conversions and error handling. The reviewer suggests adding explicit JSON type validation in PatchRetention to prevent potential crashes or exceptions when parsing non-object JSON values.
| Status PatchRetention(Object& o, nlohmann::json const& p) { | ||
| if (p.is_null()) { | ||
| o.clear_retention(); | ||
| return Status{}; | ||
| } | ||
| StatusOr<std::chrono::system_clock::time_point> ts = | ||
| storage::internal::ParseTimestampField(p, "retainUntilTime"); | ||
| if (!ts) return std::move(ts).status(); | ||
| return SetRetention( | ||
| o, storage::ObjectRetention{p.value("mode", std::string{}), *ts}); | ||
| } |
There was a problem hiding this comment.
To prevent potential crashes or uncaught exceptions (especially when compiled with -fno-exceptions), we should explicitly validate that the JSON value p is an object before parsing its fields. Calling ParseTimestampField or p.value() on a non-object JSON value can throw nlohmann::json::type_error or cause undefined behavior.
Status PatchRetention(Object& o, nlohmann::json const& p) {
if (p.is_null()) {
o.clear_retention();
return Status{};
}
if (!p.is_object()) {
return Status(StatusCode::kInvalidArgument,
"retention field must be a JSON object");
}
StatusOr<std::chrono::system_clock::time_point> ts =
storage::internal::ParseTimestampField(p, "retainUntilTime");
if (!ts) return std::move(ts).status();
std::string mode;
if (p.contains("mode")) {
if (!p["mode"].is_string()) {
return Status(StatusCode::kInvalidArgument,
"retention mode must be a string");
}
mode = p["mode"].get<std::string>();
}
return SetRetention(o, storage::ObjectRetention{std::move(mode), *ts});
}
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16719 +/- ##
========================================
Coverage 92.78% 92.79%
========================================
Files 2277 2277
Lines 228147 228338 +191
========================================
+ Hits 211696 211890 +194
+ Misses 16451 16448 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The gRPC bucket and object parsers now convert object retention settings, bucket object retention configuration, and the override unlocked retention flag to and from google.storage.v2 protobuf messages. Existing REST transport serialization and other gRPC bucket and object request and metadata fields remain unchanged. Updated unit tests in bucket_request_parser_test, bucket_metadata_parser_test, object_metadata_parser_test, object_request_parser_test, and stub_test to verify protobuf conversion and error propagation for these fields.