Skip to content

fix(storage): align gRPC parsers with REST object retention fields - #16719

Draft
nidhiii-27 wants to merge 1 commit into
mainfrom
fix/storage-grpc-object-retention-parsers
Draft

nidhiii-27 wants to merge 1 commit into
mainfrom
fix/storage-grpc-object-retention-parsers

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

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.

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]
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +235 to +245
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});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.49246% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (4a2bfb0) to head (281c3b2).

Files with missing lines Patch % Lines
...ud/storage/internal/grpc/object_metadata_parser.cc 97.05% 1 Missing ⚠️
...orage/internal/grpc/object_metadata_parser_test.cc 96.29% 1 Missing ⚠️
google/cloud/storage/internal/grpc/stub_test.cc 93.33% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant