-
Notifications
You must be signed in to change notification settings - Fork 555
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
Sample(storage): Soft deleted Bucket Restore #28760
Draft
shubhangi-google
wants to merge
71
commits into
googleapis:main
Choose a base branch
from
shubhangi-google:soft_deleted_bucket_restore_with_sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
0f5b378
WIP- able to fetch generation and list of soft deleted bucket
shubhangi-google c13c271
wip- fetch soft deleted bucket and restore bucket
shubhangi-google 703a74f
refactor
shubhangi-google 113e074
adding unit tests
shubhangi-google d8389ee
refactor
shubhangi-google 4805dcf
update
shubhangi-google 4628b57
fixing lint issues
shubhangi-google 331713a
refactor
shubhangi-google 7bb513c
removing unwanted changes
shubhangi-google fd595ed
removing commented code
shubhangi-google 5876b21
removing unwanted file change
shubhangi-google 8bb3590
refactor
shubhangi-google 0c7316a
refactor
shubhangi-google dc22c71
WIP-samples
shubhangi-google 45c0bc7
adding samples and tests
shubhangi-google 2e96036
refactor
shubhangi-google 3728dcf
refactor
shubhangi-google 4265f54
updating comments
shubhangi-google 3c89fef
fix lint issues
shubhangi-google d3e3db6
fix lint issues
shubhangi-google 36fbf02
fix review comments
shubhangi-google 69a242b
removing pry
shubhangi-google 46b987e
fix lint
shubhangi-google 0d902d5
try cli issue fix
shubhangi-google b187c21
fix lint
shubhangi-google b608825
removing unwanted code
shubhangi-google cc5dd1e
adding check to see if bucket is deleted or not
shubhangi-google 6700876
debugging
shubhangi-google 9538c91
debugging
shubhangi-google ae9e2af
debugging
shubhangi-google dbdbe58
debugging
shubhangi-google d67ebf4
debugging
shubhangi-google f30c889
debugging
shubhangi-google 8040fab
debugging
shubhangi-google 88438a3
updating gemspec
shubhangi-google 70236f7
debugging
shubhangi-google b2f67ad
debugging
shubhangi-google 6108636
undo adding static email
shubhangi-google 04a56f1
updating gemspec -- debugging
shubhangi-google dcb47e7
updating gem spec -- debugging
shubhangi-google 360f07a
debugging
shubhangi-google f42e11d
debugging
shubhangi-google 49834d4
debugging
shubhangi-google 9b023d0
addressing nit comments
shubhangi-google 2a7f238
debugging
shubhangi-google 63c4106
debugging
shubhangi-google c7a2e76
debugging
shubhangi-google 9191faf
debugging
shubhangi-google 6395dc5
debugging
shubhangi-google 4feec6c
debugging
shubhangi-google 39edb70
debugging
shubhangi-google 25119ab
debugging
shubhangi-google 6af39e7
debugging
shubhangi-google 63b8485
debugging
shubhangi-google 0bc844f
debugging
shubhangi-google a442451
debugging
shubhangi-google 44b3aae
debugging
shubhangi-google 5ba2762
debugging
shubhangi-google e7dcbce
debugging
shubhangi-google 4838eb5
debugging
shubhangi-google 2edc311
debugging
shubhangi-google 7a6f719
debugging
shubhangi-google 199acc5
debugging
shubhangi-google 120d90c
debugging
shubhangi-google 2a48db3
resolving lint issues
shubhangi-google a559a06
resolving lint issue
shubhangi-google 4bdeb8b
lint issue
shubhangi-google da04abb
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google 0b10a6a
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google 4172e24
adding retention_period to sample bucket
shubhangi-google 33b3f07
Merge remote-tracking branch 'refs/remotes/origin/soft_deleted_bucket…
shubhangi-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
google-cloud-storage/samples/storage_get_soft_deleted_bucket.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START storage_get_soft_deleted_bucket] | ||
def get_soft_deleted_bucket bucket_name:, generation: | ||
# The ID of your GCS bucket | ||
# bucket_name = "your-unique-bucket-name" | ||
# The generation no of your GCS bucket | ||
# generation = "1234567896987" | ||
|
||
require "google/cloud/storage" | ||
|
||
storage = Google::Cloud::Storage.new | ||
# fetching soft deleted bucket with soft_delete_time and hard_delete_time | ||
deleted_bucket_fetch = storage.bucket bucket_name, generation: generation, soft_deleted: true | ||
|
||
soft_delete_time = deleted_bucket_fetch.soft_delete_time | ||
hard_delete_time = deleted_bucket_fetch.hard_delete_time | ||
|
||
if (soft_delete_time && hard_delete_time).nil? | ||
puts "Not Found" | ||
else | ||
puts "soft_delete_time for #{deleted_bucket_fetch.name} is - #{soft_delete_time}" | ||
puts "hard_delete_time for #{deleted_bucket_fetch.name} is - #{hard_delete_time}" | ||
end | ||
end | ||
# [END storage_get_soft_deleted_bucket] | ||
|
||
|
||
get_soft_deleted_bucket bucket_name: ARGV.shift, generation: ARGV.shift if $PROGRAM_NAME == __FILE__ |
30 changes: 30 additions & 0 deletions
30
google-cloud-storage/samples/storage_list_soft_deleted_buckets.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START storage_list_soft_deleted_buckets] | ||
def list_soft_deleted_buckets | ||
require "google/cloud/storage" | ||
|
||
storage = Google::Cloud::Storage.new | ||
|
||
# fetching soft deleted bucket list | ||
deleted_buckets = storage.buckets soft_deleted: true | ||
|
||
deleted_buckets.each do |bucket| | ||
puts bucket.name | ||
end | ||
end | ||
# [END storage_list_soft_deleted_buckets] | ||
|
||
list_soft_deleted_buckets if $PROGRAM_NAME == __FILE__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START storage_restore_bucket] | ||
def restore_bucket bucket_name:, generation: | ||
# The ID of your GCS bucket | ||
# bucket_name = "your-unique-bucket-name" | ||
# The generation no of your GCS bucket | ||
# generation = "1234567896987" | ||
|
||
require "google/cloud/storage" | ||
|
||
storage = Google::Cloud::Storage.new | ||
|
||
bucket_restored = storage.restore_bucket bucket_name, generation | ||
|
||
if bucket_restored.name == bucket_name | ||
puts "#{bucket_name} Bucket restored" | ||
else | ||
puts "#{bucket_name} Bucket not restored" | ||
end | ||
end | ||
# [END storage_restore_bucket] | ||
|
||
restore_bucket bucket_name: ARGV.shift, generation: ARGV.shift if $PROGRAM_NAME == __FILE__ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this new bucket have
soft_delete_policy
?If not, we won't be able to recover the bucket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajajneha27 on console I can see this for one of the ruby sample test bucket
![image](https://private-user-images.githubusercontent.com/179678678/410797505-68af1e64-b2b0-4b5d-8f1c-08bcdd447e36.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3MDA5ODQsIm5iZiI6MTczOTcwMDY4NCwicGF0aCI6Ii8xNzk2Nzg2NzgvNDEwNzk3NTA1LTY4YWYxZTY0LWIyYjAtNGI1ZC04ZjFjLTA4YmNkZDQ0N2UzNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNlQxMDExMjRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00YTI0NWRlMzg5MjQzYzk5Y2M5Zjc1YmM5ZWNjMzIwMjU5MTE1MjdkMWZkNGZkNzcwNWJlMzhlNzNiZDhlOGRiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Ds2x2quyAqzEuvkt33g-9LHK8Po9sircgRxxF9PZcPw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
soft_delete_policy
set by default if you create a new bucket?If not, you'll have to pass it while creating the new bucket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is set by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. Can you explicitly check the policy in test too, so that we're sure we've the policy in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajajneha27 tried to set retention period for the bucket explicitly but getting same result
also I can see in this doc (https://cloud.google.com/storage/docs/soft-delete#retention-duration) that default soft deleted policy is set as 7 days for a bucket