Skip to content

Commit 33798e7

Browse files
committed
Delete SDK level validation
1 parent 7bd081d commit 33798e7

5 files changed

Lines changed: 0 additions & 230 deletions

File tree

google/cloud/storage/internal/grpc/object_request_parser.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ Status SetObjectMetadata(google::storage::v2::Object& resource,
157157
google::cloud::internal::ToProtoTimestamp(metadata.custom_time());
158158
}
159159
if (metadata.has_contexts()) {
160-
auto status =
161-
storage::internal::ValidateObjectContextsAggregate(metadata.contexts());
162-
if (!status.ok()) return status;
163-
164160
auto& custom_map = *resource.mutable_contexts()->mutable_custom();
165161
for (auto const& kv : metadata.contexts().custom()) {
166162
// In request, the create_time and update_time are ignored by the server,
@@ -306,10 +302,6 @@ Status PatchGrpcContexts(
306302
auto const& v = kv.value();
307303
if (v.is_object() && v.contains("value")) {
308304
std::string value_str = v["value"].get<std::string>();
309-
auto status =
310-
storage::internal::ValidateObjectContext(kv.key(), value_str);
311-
if (!status.ok()) return status;
312-
313305
auto& payload =
314306
(*object.mutable_contexts()->mutable_custom())[kv.key()];
315307
payload.set_value(std::move(value_str));
@@ -339,10 +331,6 @@ StatusOr<google::storage::v2::ComposeObjectRequest> ToProto(
339331
(*destination.mutable_metadata())[kv.first] = kv.second;
340332
}
341333
if (metadata.has_contexts()) {
342-
status = storage::internal::ValidateObjectContextsAggregate(
343-
metadata.contexts());
344-
if (!status.ok()) return status;
345-
346334
for (auto const& kv : metadata.contexts().custom()) {
347335
auto& payload =
348336
(*destination.mutable_contexts()->mutable_custom())[kv.first];
@@ -573,10 +561,6 @@ StatusOr<google::storage::v2::UpdateObjectRequest> ToProto(
573561
}
574562

575563
if (request.metadata().has_contexts()) {
576-
auto contexts_status = storage::internal::ValidateObjectContextsAggregate(
577-
request.metadata().contexts());
578-
if (!contexts_status.ok()) return contexts_status;
579-
580564
result.mutable_update_mask()->add_paths("contexts");
581565
auto& custom_map = *object.mutable_contexts()->mutable_custom();
582566

google/cloud/storage/object_contexts.cc

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,77 +23,6 @@ namespace cloud {
2323
namespace storage {
2424
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2525

26-
namespace internal {
27-
28-
Status ValidateObjectContext(std::string const& key, std::string const& value) {
29-
// Helper lambda to validate shared rules for both keys and values
30-
auto validate_component = [](std::string const& str,
31-
char const* name) -> Status {
32-
// The GCS spec requires each object context key / value to
33-
// contain 1 - 256 UTF-8 code units. Since each UTF-8 code unit is
34-
// equivalent to 1 byte, we use std::string::size() to check the
35-
// number of bytes.
36-
if (str.empty() || str.size() > 256) {
37-
return Status(StatusCode::kInvalidArgument,
38-
std::string("Object context ") + name +
39-
" must be between 1 and 256 UTF-8 code units.");
40-
}
41-
if (!std::isalnum(static_cast<unsigned char>(str.front()))) {
42-
return Status(StatusCode::kInvalidArgument,
43-
std::string("Object context ") + name +
44-
" must begin with an alphanumeric character.");
45-
}
46-
if (str.find_first_of("'\"\\/") != std::string::npos) {
47-
return Status(StatusCode::kInvalidArgument,
48-
std::string("Object context ") + name +
49-
" cannot contain ', \", \\, or /.");
50-
}
51-
return Status();
52-
};
53-
54-
auto status = validate_component(key, "keys");
55-
if (!status.ok()) return status;
56-
57-
status = validate_component(value, "values");
58-
if (!status.ok()) return status;
59-
60-
// Rule specific to keys: Cannot begin with 'goog' (case-insensitive)
61-
if (key.size() >= 4) {
62-
std::string prefix = key.substr(0, 4);
63-
std::transform(prefix.begin(), prefix.end(), prefix.begin(),
64-
[](unsigned char c) { return std::tolower(c); });
65-
66-
if (prefix == "goog") {
67-
return Status(
68-
StatusCode::kInvalidArgument,
69-
"Object context keys cannot begin with 'goog' (case-insensitive).");
70-
}
71-
}
72-
return Status();
73-
}
74-
75-
Status ValidateObjectContextsAggregate(ObjectContexts const& contexts) {
76-
// Validate each individual key-value pair and calculate aggregate size.
77-
for (auto const& kv : contexts.custom()) {
78-
auto status = ValidateObjectContext(kv.first, kv.second.value);
79-
if (!status.ok()) return status;
80-
}
81-
82-
// Rule: Count limited to 50.
83-
if (contexts.custom().size() > 50) {
84-
return Status(StatusCode::kInvalidArgument,
85-
"Object contexts are limited to 50 entries per object.");
86-
}
87-
88-
// Note: The API limits the aggregate size to 25 KiB (25,600 bytes).
89-
// With a max of 50 items and a max of 256 bytes per key and value,
90-
// the maximum possible size is exactly 50 * (256 + 256) = 25,600 bytes.
91-
// Therefore, an explicit aggregate size check is mathematically redundant.
92-
return Status();
93-
}
94-
95-
} // namespace internal
96-
9726
std::ostream& operator<<(std::ostream& os,
9827
ObjectCustomContextPayload const& rhs) {
9928
return os << "ObjectCustomContextPayload{value=" << rhs.value

google/cloud/storage/object_contexts.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ class ObjectContexts {
9797

9898
std::ostream& operator<<(std::ostream& os, ObjectContexts const& rhs);
9999

100-
namespace internal {
101-
// Validates a single context key/value pair and returns a Status on invalid
102-
// inputs.
103-
Status ValidateObjectContext(std::string const& key, std::string const& value);
104-
105-
// Validates the aggregate constraints (size & count) and all individual pairs.
106-
// Returns a Status on invalid inputs.
107-
Status ValidateObjectContextsAggregate(ObjectContexts const& contexts);
108-
} // namespace internal
109-
110100
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
111101
} // namespace storage
112102
} // namespace cloud

google/cloud/storage/object_contexts_test.cc

Lines changed: 0 additions & 132 deletions
This file was deleted.

google/cloud/storage/storage_client_unit_tests.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ storage_client_unit_tests = [
9898
"list_objects_reader_test.cc",
9999
"notification_metadata_test.cc",
100100
"object_access_control_test.cc",
101-
"object_contexts_test.cc",
102101
"object_metadata_test.cc",
103102
"object_retention_test.cc",
104103
"object_stream_test.cc",

0 commit comments

Comments
 (0)