forked from googleapis/google-cloud-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Samples soft delete policy #63
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
Open
shubhangi-google
wants to merge
2
commits into
main
Choose a base branch
from
samples_soft_delete_policy
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
google-cloud-storage/samples/storage_disable_soft_delete.rb
This file contains hidden or 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,31 @@ | ||
| # Copyright 2026 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_disable_soft_delete] | ||
| def disable_soft_delete bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| bucket.soft_delete_policy = { retention_duration_seconds: 0 } | ||
|
|
||
| puts "Soft delete retention duration for #{bucket_name} is now 0 seconds." | ||
| end | ||
| # [END storage_disable_soft_delete] | ||
|
|
||
| disable_soft_delete bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ |
31 changes: 31 additions & 0 deletions
31
google-cloud-storage/samples/storage_get_soft_delete_policy.rb
This file contains hidden or 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,31 @@ | ||
| # Copyright 2026 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_delete_policy] | ||
| def get_soft_delete_policy bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| puts "Soft delete policy for #{bucket_name}:" | ||
| puts "Retention duration: #{bucket.soft_delete_policy.retention_duration_seconds} seconds" | ||
| puts "Effective time: #{bucket.soft_delete_policy.effective_time}" | ||
| end | ||
| # [END storage_get_soft_delete_policy] | ||
|
|
||
| get_soft_delete_policy bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ |
30 changes: 30 additions & 0 deletions
30
google-cloud-storage/samples/storage_list_soft_deleted_object_versions.rb
This file contains hidden or 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 2026 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_object_versions] | ||
| def list_soft_deleted_object_versions bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
| bucket.files(soft_deleted: true).each do |file| | ||
| puts "#{file.name}, generation: #{file.generation}, soft_delete_time: #{file.soft_delete_time}" | ||
| end | ||
| end | ||
| # [END storage_list_soft_deleted_object_versions] | ||
|
|
||
| list_soft_deleted_object_versions bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
31 changes: 31 additions & 0 deletions
31
google-cloud-storage/samples/storage_list_soft_deleted_objects.rb
This file contains hidden or 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,31 @@ | ||
| # Copyright 2026 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_objects] | ||
| def list_soft_deleted_objects bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| bucket.files(soft_deleted: true).each do |file| | ||
| puts "#{file.name}, soft_delete_time: #{file.soft_delete_time}" | ||
| end | ||
| end | ||
| # [END storage_list_soft_deleted_objects] | ||
|
|
||
| list_soft_deleted_objects bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ |
This file contains hidden or 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,39 @@ | ||
| # Copyright 2026 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_object] | ||
| def restore_object bucket_name:, file_name:, generation: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # The name of the soft-deleted file to restore | ||
| # file_name = "your-file-name" | ||
|
|
||
| # The generation of the soft-deleted file to restore | ||
| # generation = 1600000000000000 | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| file = bucket.restore_file file_name, generation.to_i | ||
|
|
||
| puts "Restored file #{file.name} with generation #{file.generation} in bucket #{bucket_name}." | ||
| end | ||
| # [END storage_restore_object] | ||
|
|
||
| if $PROGRAM_NAME == __FILE__ | ||
| restore_object bucket_name: ARGV.shift, file_name: ARGV.shift, generation: ARGV.shift | ||
|
shubhangi-google marked this conversation as resolved.
|
||
| end | ||
36 changes: 36 additions & 0 deletions
36
google-cloud-storage/samples/storage_set_soft_delete_policy.rb
This file contains hidden or 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 2026 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_set_soft_delete_policy] | ||
| def set_soft_delete_policy bucket_name:, retention_duration_seconds: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # The retention duration for soft-deleted objects in seconds | ||
| # retention_duration_seconds = 604800 # 7 days in seconds | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| bucket.soft_delete_policy = { retention_duration_seconds: retention_duration_seconds.to_i } | ||
|
shubhangi-google marked this conversation as resolved.
|
||
|
|
||
| puts "Soft delete retention duration for #{bucket_name} is now #{bucket.soft_delete_policy.retention_duration_seconds} seconds." | ||
| end | ||
| # [END storage_set_soft_delete_policy] | ||
|
|
||
| if $PROGRAM_NAME == __FILE__ | ||
| set_soft_delete_policy bucket_name: ARGV.shift, retention_duration_seconds: ARGV.shift | ||
| end | ||
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.
Uh oh!
There was an error while loading. Please reload this page.