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): Soft deleted Bucket Restore #28138

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

Conversation

shubhangi-google
Copy link
Contributor

Add support for restoring soft deleted bucket.

Operation Supported:

  • Get Bucket Generation
  • Get a Soft Deleted Bucket (Also soft-delete time and hard-delete time)
  • List Soft Deleted Buckets
  • Restore a Soft Deleted Bucket
@example
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
bucket.delete
##fetch bucket generation
 generation= bucket.generation
## list soft_deleted buckets
deleted_buckets= storage.buckets soft_deleted: true
## restore bucket
bucket = storage.restore_bucket "my-bucket", generation

Copy link
Contributor

@bajajneha27 bajajneha27 left a comment

Choose a reason for hiding this comment

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

Mark the PR ready for review once you're ready for it to be reviewed. Also please check the CI job failures.

google-cloud-storage/lib/google/cloud/storage/bucket.rb Outdated Show resolved Hide resolved
google-cloud-storage/lib/google/cloud/storage/bucket.rb Outdated Show resolved Hide resolved
google-cloud-storage/lib/google/cloud/storage/bucket.rb Outdated Show resolved Hide resolved
google-cloud-storage/lib/google/cloud/storage/project.rb Outdated Show resolved Hide resolved
google-cloud-storage/samples/Gemfile Outdated Show resolved Hide resolved
google-cloud-storage/samples/acceptance/buckets_test.rb Outdated Show resolved Hide resolved
def object_retention_param enable_object_retention
enable_object_retention ? Google::Apis::StorageV1::Bucket::ObjectRetention.new(mode: "Enabled") : nil
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to revert this change back and add the newline character back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did not understand your concerns here

google-cloud-storage/test/helper.rb Outdated Show resolved Hide resolved
@shubhangi-google shubhangi-google marked this pull request as ready for review December 21, 2024 05:52
Copy link

snippet-bot bot commented Dec 21, 2024

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

Copy link
Contributor

@bajajneha27 bajajneha27 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Please fix the CI issues.

@@ -223,6 +232,10 @@ def buckets prefix: nil, token: nil, max: nil, user_project: nil
# account, transit costs will be billed to the given project. This
# parameter is required with requester pays-enabled buckets. The
# default is `nil`.
# @param [Integer] generation generation no of bucket
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# @param [Integer] generation generation no of bucket
# @param [Integer] generation Generation of the bucket

google-cloud-storage/lib/google/cloud/storage/project.rb Outdated Show resolved Hide resolved
@shubhangi-google
Copy link
Contributor Author

Hi @bajajneha27 @JesseLovelace can you please take a look at the sample failure
getting permission error on sample run

Google::Cloud::PermissionDeniedError: forbidden: 542339357638-cr0dserr2evg7sv1meghqeu703274f3h@developer.gserviceaccount.com 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).

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket_name = bucket_name.gsub(/[^a-zA-Z0-9\- ]/, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't do validation like this in a sample, remove this line

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may have something to do with the PermissionDenied error you're getting, this may be causing you to check two different bucket names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @bajajneha27 @JesseLovelace
I have removed the suspected line of code but still getting same failure

@bajajneha27
Copy link
Contributor

@shubhangi-google Does the yard / rubocop ci work in your local?

bucket_name = bucket_name.gsub(/[^a-zA-Z0-9\- ]/, "")

# fetching soft deleted bucket with soft_delete_time and hard_delete_time
deleted_bucket_fetch = storage.bucket bucket_name, generation: generation, soft_deleted: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Error occurs at this line. This could be because the bucket_name is modified in the previous line and the new bucket doesn't exist.
Like Jesse said, try removing the above line. We shouldn't be modifying the bucket_name passed.

@bajajneha27
Copy link
Contributor

Can you please double check that the APIARY i.e. google-apis-storage_v1 has soft delete changes? We might have to bump the storage_v1 version in storage gemspec

@shubhangi-google shubhangi-google force-pushed the soft_deleted_bucket_restore_samples_new3 branch from 209b570 to 59a3f9c Compare January 17, 2025 05:41
@shubhangi-google
Copy link
Contributor Author

Can you please double check that the APIARY i.e. google-apis-storage_v1 has soft delete changes? We might have to bump the storage_v1 version in storage gemspec

updating the version in gemspec did not help will debug this further

@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "google-cloud-core", "~> 1.6"
gem.add_dependency "google-apis-core", "~> 0.13"
gem.add_dependency "google-apis-iamcredentials_v1", "~> 0.18"
gem.add_dependency "google-apis-storage_v1", "~> 0.38"
gem.add_dependency "google-apis-storage_v1", "~> 0.40"
Copy link
Contributor

Choose a reason for hiding this comment

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

The soft_deleted field on get_bucket was introduced in storage_v1 0.42 version. Ref
Which version were you using in local?
Also generally, just update to the latest version of the dependency when you do this.
This should solve the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

current gem version present on KOKORO is 0.49 (as seen in sample logs)
image
"~> 0.40" will specify that we want to use a version of the gem that is at least 0.40, but less than 0.5.

@bajajneha27 bajajneha27 added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 17, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 17, 2025
@shubhangi-google shubhangi-google force-pushed the soft_deleted_bucket_restore_samples_new3 branch from 582f12a to b2f67ad Compare January 17, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants