Skip to content

feat(storage): implement Object Contexts with advanced filtering and validation#9122

Open
salilg-eng wants to merge 75 commits intogoogleapis:mainfrom
salilg-eng:feat/object-contexts
Open

feat(storage): implement Object Contexts with advanced filtering and validation#9122
salilg-eng wants to merge 75 commits intogoogleapis:mainfrom
salilg-eng:feat/object-contexts

Conversation

@salilg-eng
Copy link
Copy Markdown
Contributor

@salilg-eng salilg-eng commented Apr 20, 2026

  • Updated storage-v1.json to include the contexts object definition, enabling the library to recognize context metadata in requests and responses.
  • Modified Rest.php to include contexts in the request body during object creation. This ensures that context properties are correctly serialized as part of the object resource.
  • Added logic to validate context structures early in the execution lifecycle, preventing unnecessary API calls for malformed metadata.
  • Add comprehensive unit and system tests covering CRUD, server-side
    operations, and complex filtering scenarios.

@salilg-eng salilg-eng requested review from a team as code owners April 20, 2026 10:40
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Apr 20, 2026
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 20, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

"value": {
"type": "string",
"description": "The value of the object contexts.",
"required": true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The value field is marked as required here, but in the official discovery doc, this field is not marked as required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed required

Comment thread Storage/src/Connection/ServiceDefinition/storage-v1.json
Comment thread Storage/src/Bucket.php Outdated
if (!is_array($options['contexts'])) {
throw new \InvalidArgumentException('Object contexts must be an array.');
}
$this->validateContexts($options['contexts']);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This manual regex validation is not needed at the client level. The SDKs rely on the GCS server-side API to validate context keys and values. Hardcoding these rules on the client side is redundant and could lead to issues if the GCS service updates its naming requirements. We should only verify that the input is an array and let the API handle the validation, consistent with how we handle other custom metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed ValidateContext. Thanks for your clarity.

Comment thread Storage/src/Bucket.php Outdated
* Each object context is a key-payload pair, where the key provides the
* identification and the payload holds the associated value and additional metadata.
* @type array $contexts.custom Custom user-defined contexts. Keys must start
* with an alphanumeric character and cannot contain double quotes (`"`).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need not mention these specific details here, you can add the link to the API docs - https://docs.cloud.google.com/storage/docs/use-object-contexts

Copy link
Copy Markdown
Contributor Author

@salilg-eng salilg-eng Apr 24, 2026

Choose a reason for hiding this comment

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

Removed and added link as per given by you.

Comment thread Storage/src/Bucket.php Outdated
* @type array $contexts.custom Custom user-defined contexts. Keys must start
* with an alphanumeric character and cannot contain double quotes (`"`).
* @type string $contexts.custom.{key}.value The value associated with the context.
* If not empty, must start with an alphanumeric character and cannot contain double quotes (`"`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same comment as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed

Comment thread Storage/src/StorageObject.php Outdated
* Each object context is a key-payload pair, where the key provides the
* identification and the payload holds the associated value and additional metadata.
* @type array $contexts.custom Custom user-defined contexts. Keys must start
* with an alphanumeric character and cannot contain double quotes (`"`).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Update the comments here as well. We don't need to add specific restrictions here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed as per above feedback.

@salilg-eng
Copy link
Copy Markdown
Contributor Author

"Hello, thank you for the feedback. The CLA is now approved, and I have addressed all your comments and resolved the issues."

@salilg-eng salilg-eng requested a review from nidhiii-27 April 25, 2026 09:42
@nidhiii-27
Copy link
Copy Markdown

@salilg-eng Can you please look into the failing tests?

{
const DATA = 'data';

Copy link
Copy Markdown
Collaborator

@Hectorhammett Hectorhammett Apr 28, 2026

Choose a reason for hiding this comment

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

Are these white spaces? If so, let's remove them :)

Copy link
Copy Markdown
Contributor Author

@salilg-eng salilg-eng Apr 29, 2026

Choose a reason for hiding this comment

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

Removed the extra whitespace. I’ve double-checked the rest of the code, and no other instances remain.

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

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants