Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(Storage): add samples for soft-delete and restore buckets #2067

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

thiyaguk09
Copy link
Contributor

Added Storage Samples:

  1. Get a Soft Deleted Bucket
  2. List Soft Deleted Buckets
  3. Restore a Soft Deleted Bucket

initial commit for bucket restore samples
@product-auto-label product-auto-label bot added api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. labels Dec 24, 2024
@thiyaguk09 thiyaguk09 marked this pull request as ready for review January 6, 2025 16:28
@thiyaguk09 thiyaguk09 requested review from a team as code owners January 6, 2025 16:28
Copy link

snippet-bot bot commented Jan 6, 2025

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@danielduhh danielduhh removed the request for review from a team January 21, 2025 04:53
@danielduhh danielduhh added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 21, 2025
@danielduhh danielduhh requested a review from bshaffer January 21, 2025 04:54
@danielduhh danielduhh added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 3, 2025
@danielduhh
Copy link
Contributor

Hi @bshaffer, this should be ready for review when you get a second!

Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

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

I ran these tests locally and received the following errors:

1) Google\Cloud\Samples\Storage\storageTest::testGetRestoreSoftDeletedBucket
Google\Cloud\Core\Exception\ServiceException: {"error":{"code":403,"message":"[email protected] does not have storage.buckets.get access to the Google Cloud Storage bucket. Permission 'storage.buckets.get' denied on resource (or it may not exist).","errors":[{"message":"[email protected] does not have storage.buckets.get access to the Google Cloud Storage bucket. Permission 'storage.buckets.get' denied on resource (or it may not exist).","domain":"global","reason":"forbidden"}]}}

vendor/google/cloud-core/src/RequestWrapper.php:434
vendor/google/cloud-core/src/RequestWrapper.php:230
vendor/google/cloud-core/src/RestTrait.php:103
vendor/google/cloud-storage/src/Connection/Rest.php:777
vendor/google/cloud-storage/src/Connection/Rest.php:202
vendor/google/cloud-storage/src/Bucket.php:1234
test/storageTest.php:959
--

There was 1 failure:

1) Google\Cloud\Samples\Storage\storageTest::testListSoftDeletedBuckets
Failed asserting that '' contains "Bucket:".

test/storageTest.php:153

Is it possible I need to enable something on the test project php-docs-samples-kokoro for these tests to pass?

@thiyaguk09
Copy link
Contributor Author

Is it possible I need to enable something on the test project php-docs-samples-kokoro for these tests to pass?

Could you try giving the storage.legacyBucketOwner permission (roles/storage.legacyBucketOwner)?

@thiyaguk09 thiyaguk09 requested a review from bshaffer February 10, 2025 05:10
@glasnt glasnt added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Feb 13, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 13, 2025
@glasnt glasnt added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 13, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 13, 2025
@danielduhh
Copy link
Contributor

@thiyaguk09 this is not the first test that creates a bucket, so I don't think permissions is an issue here

@thiyaguk09
Copy link
Contributor Author

@thiyaguk09 this is not the first test that creates a bucket, so I don't think permissions is an issue here

@danielduhh Agreed. Permissions aren't the likely issue. I suspect the softDeletePolicy isn't being set correctly during bucket creation. I've manually configured it now. Let's add a kokoro:run to confirm.

@bshaffer Could you check if the buckets created are actually configured with the soft delete policy as intended?

*"Ruby repo also experiencing the same issue."

@bshaffer
Copy link
Contributor

@thiyaguk09 the buckets are being created with the soft delete option here:

$bucket = self::$storage->createBucket($bucketName, [
'softDeletePolicy' => [
'retentionDuration' => 604800,
],
]);

I can dig a little deeper to see if this bucket is being created as expected.

@bshaffer
Copy link
Contributor

bshaffer commented Feb 24, 2025

@thiyaguk09 I figured out the issue. The way you are supplying the soft delete options to $bucket->info() and $bucket->reload() is not how SoftDelete is currently supported in the Storage client library for PHP. Rather, you need to call it by supplying the options argument to StorageClient::bucket() like this:

$storage = new StorageClient();
$options = ['softDeleted' => true, 'generation' => $generation];
$softDeletedBucket = $storage->bucket($bucketName, options: $options);

@thiyaguk09
Copy link
Contributor Author

@thiyaguk09 I figured out the issue. The way you are supplying the soft delete options to $bucket->info() and $bucket->reload() is not how SoftDelete is currently supported in the Storage client library for PHP. Rather, you need to call it by supplying the options argument to StorageClient::bucket() like this:

$storage = new StorageClient();
$options = ['softDeleted' => true, 'generation' => $generation];
$softDeletedBucket = $storage->bucket($bucketName, options: $options);

@bshaffer Thank you for your thorough investigation and for identifying the correct method for accessing soft-deleted buckets. Your explanation was very clear.

You're right, it appears there was an issue with how reload() was handling the soft delete options. We've implemented the changes you suggested, using StorageClient::bucket() with the options array. We're hoping this resolves the problem.

@danielduhh danielduhh added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 3, 2025
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 3, 2025
@bshaffer
Copy link
Contributor

bshaffer commented Mar 6, 2025

@thiyaguk09 The changes you made are still not correct, and do not follow the code example I provided. You're providing the softDelete option to the info method, while it needs to be supplied to the bucket method:

// What you have (INCORRECT)
$softDeletedBucket = self::$storage->bucket($bucketName);
$options = ['softDeleted' => true, 'generation' => $generation];
$info = $softDeletedBucket->info($options);
// What it should be (CORRECT)
$options = ['softDeleted' => true, 'generation' => $generation];
$softDeletedBucket = self::$storage->bucket($bucketName, options: $options);
$info = $softDeletedBucket->info();

@thiyaguk09
Copy link
Contributor Author

The changes you made are still not correct, and do not follow the code example I provided. You're providing the softDelete option to the info method, while it needs to be supplied to the bucket method:

I apologize for the oversight. Thank you for pointing that out. I will make the necessary corrections to ensure the softDelete option is supplied to the bucket method as per your code example. The code has been updated; could you please review it?

@danielduhh
Copy link
Contributor

@thiyaguk09 are the tests passing locally? Is this ready for a re-review?

@thiyaguk09
Copy link
Contributor Author

@thiyaguk09 are the tests passing locally? Is this ready for a re-review?

Yes, it's passing locally and ready for re-review.

@thiyaguk09
Copy link
Contributor Author

@bshaffer just a friendly nudge to check out this PR when you get a chance.

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. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants