Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
0f5b378
WIP- able to fetch generation and list of soft deleted bucket
shubhangi-google Nov 25, 2024
c13c271
wip- fetch soft deleted bucket and restore bucket
shubhangi-google Nov 27, 2024
703a74f
refactor
shubhangi-google Nov 28, 2024
113e074
adding unit tests
shubhangi-google Dec 11, 2024
d8389ee
refactor
shubhangi-google Dec 12, 2024
4805dcf
update
shubhangi-google Dec 12, 2024
4628b57
fixing lint issues
shubhangi-google Dec 13, 2024
331713a
refactor
shubhangi-google Dec 13, 2024
7bb513c
removing unwanted changes
shubhangi-google Dec 16, 2024
fd595ed
removing commented code
shubhangi-google Dec 16, 2024
5876b21
removing unwanted file change
shubhangi-google Dec 16, 2024
8bb3590
refactor
shubhangi-google Dec 16, 2024
0c7316a
refactor
shubhangi-google Dec 18, 2024
dc22c71
WIP-samples
shubhangi-google Dec 12, 2024
45c0bc7
adding samples and tests
shubhangi-google Dec 17, 2024
2e96036
refactor
shubhangi-google Dec 18, 2024
3728dcf
refactor
shubhangi-google Dec 19, 2024
4265f54
updating comments
shubhangi-google Dec 19, 2024
3c89fef
fix lint issues
shubhangi-google Dec 20, 2024
d3e3db6
fix lint issues
shubhangi-google Dec 20, 2024
36fbf02
fix review comments
shubhangi-google Dec 21, 2024
69a242b
removing pry
shubhangi-google Dec 21, 2024
46b987e
fix lint
shubhangi-google Dec 21, 2024
0d902d5
try cli issue fix
shubhangi-google Dec 23, 2024
b187c21
fix lint
shubhangi-google Dec 23, 2024
b608825
removing unwanted code
shubhangi-google Jan 15, 2025
cc5dd1e
adding check to see if bucket is deleted or not
shubhangi-google Jan 15, 2025
6700876
debugging
shubhangi-google Jan 15, 2025
9538c91
debugging
shubhangi-google Jan 15, 2025
ae9e2af
debugging
shubhangi-google Jan 15, 2025
dbdbe58
debugging
shubhangi-google Jan 15, 2025
d67ebf4
debugging
shubhangi-google Jan 15, 2025
f30c889
debugging
shubhangi-google Jan 15, 2025
8040fab
debugging
shubhangi-google Jan 15, 2025
88438a3
updating gemspec
shubhangi-google Jan 16, 2025
70236f7
debugging
shubhangi-google Jan 17, 2025
b2f67ad
debugging
shubhangi-google Jan 17, 2025
6108636
undo adding static email
shubhangi-google Jan 17, 2025
04a56f1
updating gemspec -- debugging
shubhangi-google Jan 17, 2025
dcb47e7
updating gem spec -- debugging
shubhangi-google Jan 17, 2025
360f07a
debugging
shubhangi-google Jan 17, 2025
f42e11d
debugging
shubhangi-google Jan 20, 2025
49834d4
debugging
shubhangi-google Jan 20, 2025
9b023d0
addressing nit comments
shubhangi-google Jan 22, 2025
2a7f238
debugging
shubhangi-google Jan 22, 2025
63c4106
debugging
shubhangi-google Jan 22, 2025
c7a2e76
debugging
shubhangi-google Jan 23, 2025
9191faf
debugging
shubhangi-google Jan 23, 2025
6395dc5
debugging
shubhangi-google Jan 23, 2025
4feec6c
debugging
shubhangi-google Jan 23, 2025
39edb70
debugging
shubhangi-google Jan 23, 2025
25119ab
debugging
shubhangi-google Jan 23, 2025
6af39e7
debugging
shubhangi-google Jan 23, 2025
63b8485
debugging
shubhangi-google Jan 23, 2025
0bc844f
debugging
shubhangi-google Jan 23, 2025
a442451
debugging
shubhangi-google Jan 23, 2025
44b3aae
debugging
shubhangi-google Jan 23, 2025
5ba2762
debugging
shubhangi-google Jan 23, 2025
e7dcbce
debugging
shubhangi-google Jan 23, 2025
4838eb5
debugging
shubhangi-google Jan 23, 2025
2edc311
debugging
shubhangi-google Jan 23, 2025
7a6f719
debugging
shubhangi-google Jan 23, 2025
199acc5
debugging
shubhangi-google Jan 24, 2025
120d90c
debugging
shubhangi-google Jan 27, 2025
2a48db3
resolving lint issues
shubhangi-google Jan 27, 2025
a559a06
resolving lint issue
shubhangi-google Jan 27, 2025
4bdeb8b
lint issue
shubhangi-google Jan 27, 2025
da04abb
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google Feb 13, 2025
0b10a6a
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google Feb 13, 2025
4172e24
adding retention_period to sample bucket
shubhangi-google Feb 14, 2025
33b3f07
Merge remote-tracking branch 'refs/remotes/origin/soft_deleted_bucket…
shubhangi-google Feb 14, 2025
042c263
adding soft delete policy explicitly
shubhangi-google Feb 24, 2025
e84219c
adding soft delete policy explicitly
shubhangi-google Feb 25, 2025
317c79a
recheking soft delete policy
shubhangi-google Feb 26, 2025
b099a91
recheking soft delete policy
shubhangi-google Mar 2, 2025
f34fbf8
debug...
shubhangi-google Mar 19, 2025
e8df7fd
debug...
shubhangi-google Mar 19, 2025
4be3fe1
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google May 7, 2025
22a749f
removing unwanted code
shubhangi-google May 21, 2025
1b45f81
fix linnt issue
shubhangi-google May 21, 2025
8e68cef
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google Jul 14, 2025
1c501a5
wip
shubhangi-google Jul 14, 2025
ba8ca78
Update storage_get_soft_deleted_bucket.rb
shubhangi-google Jul 14, 2025
707d2c0
wip
shubhangi-google Jul 14, 2025
10fbe1d
wip
shubhangi-google Jul 14, 2025
04f233a
wip
shubhangi-google Jul 15, 2025
78e9579
Update project_test.rb
shubhangi-google Jul 15, 2025
0b76567
Merge branch 'main' into soft_deleted_bucket_restore_with_sample
shubhangi-google Aug 1, 2025
8347f2f
update
shubhangi-google Aug 1, 2025
bbf91e6
update
shubhangi-google Aug 1, 2025
0223fd4
update
shubhangi-google Aug 1, 2025
dbb81d3
update
shubhangi-google Aug 1, 2025
953be23
try
shubhangi-google Aug 1, 2025
8b96a00
try
shubhangi-google Aug 1, 2025
83336e2
try
shubhangi-google Aug 1, 2025
d771df2
try
shubhangi-google Aug 1, 2025
50238be
try
shubhangi-google Aug 1, 2025
3da781e
try
shubhangi-google Aug 1, 2025
71a3c69
try
shubhangi-google Aug 1, 2025
f5dd234
try
shubhangi-google Aug 1, 2025
cc9b665
try
shubhangi-google Aug 1, 2025
a675a90
cleanup
shubhangi-google Aug 5, 2025
7663fa4
try
shubhangi-google Aug 5, 2025
3188d47
try
shubhangi-google Aug 5, 2025
f431611
try
shubhangi-google Aug 5, 2025
e123edc
cleanup
shubhangi-google Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions google-cloud-storage/samples/acceptance/buckets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
require_relative "../storage_get_public_access_prevention"
require_relative "../storage_get_requester_pays_status"
require_relative "../storage_get_retention_policy"
require_relative "../storage_get_soft_deleted_bucket"
require_relative "../storage_get_uniform_bucket_level_access"
require_relative "../storage_list_buckets"
require_relative "../storage_list_soft_deleted_buckets"
require_relative "../storage_lock_retention_policy"
require_relative "../storage_remove_bucket_label"
require_relative "../storage_remove_cors_configuration"
Expand Down Expand Up @@ -120,6 +122,31 @@
end
end

describe "storage_soft_deleted_bucket" do
let(:new_bucket_name) { random_bucket_name }
let(:new_bucket) { create_bucket_helper new_bucket_name }
let(:new_generation) { new_bucket.generation }
before do
delete_bucket_helper new_bucket.name
end

it "get soft deleted bucket, its soft_delete_time and hard_delete_time" do
# fetching a soft deleted bucket
output, _err = capture_io do
get_soft_deleted_bucket bucket_name: new_bucket_name, generation: new_generation
end
assert_includes output, "soft_delete_time for #{new_bucket_name} is"
end

it "lists soft deleted buckets" do
# fetching list of soft deleted buckets
list_deleted_bucket, _err = capture_io do
list_soft_deleted_buckets
end
assert_includes list_deleted_bucket, new_bucket_name
end
end

describe "storage_create_bucket_dual_region" do
it "creates dual region bucket" do
location = "US"
Expand Down
16 changes: 15 additions & 1 deletion google-cloud-storage/samples/acceptance/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
require "ostruct"


def grant_storage_permissions bucket_name:
storage = Google::Cloud::Storage.new
bucket = storage.bucket bucket_name

storage_admin = "roles/storage.admin"
member = "serviceAccount:#{storage.service_account_email}"

bucket.policy do |p|
p.add storage_admin,
member
end
bucket
end

def fixture_bucket
storage_client = Google::Cloud::Storage.new
storage_client.bucket($fixture_bucket_name) ||
Expand All @@ -36,14 +50,14 @@ def create_bucket_helper bucket_name
retry_resource_exhaustion do
storage_client.create_bucket bucket_name
end
grant_storage_permissions bucket_name: bucket_name
end

def delete_bucket_helper bucket_name
storage_client = Google::Cloud::Storage.new
retry_resource_exhaustion do
bucket = storage_client.bucket bucket_name
return unless bucket

bucket.files.each(&:delete)
bucket.delete
end
Expand Down
21 changes: 21 additions & 0 deletions google-cloud-storage/samples/acceptance/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

require_relative "helper"
require_relative "../storage_get_service_account"
require_relative "../storage_restore_bucket"

describe "Storage Quickstart" do
let(:project) { Google::Cloud::Storage.new }
let(:bucket) { fixture_bucket }

it "get_service_account" do
email = nil
Expand All @@ -28,3 +30,22 @@
assert_includes out, "@gs-project-accounts.iam.gserviceaccount.com"
end
end


describe "storage_soft_deleted_bucket" do
let(:new_bucket_name) { random_bucket_name }
let(:new_bucket) { create_bucket_helper new_bucket_name }
let(:generation) { new_bucket.generation }

before do
delete_bucket_helper new_bucket.name
end

it "restores a soft deleted bucket" do
# restoring deleted bucket
_out, _err = capture_io do
restore_bucket bucket_name: new_bucket.name, generation: generation
end
assert "#{new_bucket.name} Bucket restored"
end
end
44 changes: 44 additions & 0 deletions google-cloud-storage/samples/storage_get_soft_deleted_bucket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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
puts "project_name while fetching the deleted bucket"
puts storage.project
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__
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__
36 changes: 36 additions & 0 deletions google-cloud-storage/samples/storage_restore_bucket.rb
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__
Loading