Skip to content
Open
Show file tree
Hide file tree
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 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
9e65e28
removing samples and related tests
shubhangi-google Jan 27, 2025
3825108
fix lint issue
shubhangi-google Jan 27, 2025
6b7e70a
refactoring
shubhangi-google Jan 28, 2025
c20645f
Merge branch 'main' into soft_deleted_bucket_restore_samples_new3
shubhangi-google Feb 6, 2025
bb0c08c
fixing doc issue
shubhangi-google Feb 13, 2025
f97aa05
Merge branch 'main' into soft_deleted_bucket_restore_samples_new3
shubhangi-google Feb 13, 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
2 changes: 1 addition & 1 deletion google-cloud-storage/google-cloud-storage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.42"
gem.add_dependency "googleauth", "~> 1.9"
gem.add_dependency "digest-crc", "~> 0.4"
gem.add_dependency "addressable", "~> 2.8"
Expand Down
25 changes: 25 additions & 0 deletions google-cloud-storage/lib/google/cloud/storage/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,31 @@ def signed_url path = nil,
end
end

# Fetches generation of the bucket
# @example
# require "google/cloud/storage"
# storage = Google::Cloud::Storage.new
# bucket = storage.bucket "my-bucket"
# generation= bucket.generation
def generation
@gapi.generation
end

# Fetches soft_delete_time of a soft deleted bucket
# @example
# bucket.delete
# bucket.soft_delete_time
def soft_delete_time
@gapi.soft_delete_time
end

# Fetches hard_delete_time of a soft deleted bucket
# @example
# bucket.hard_delete_time
def hard_delete_time
@gapi.hard_delete_time
end

##
# Generate a PostObject that includes the fields and URL to
# upload objects via HTML forms.
Expand Down
6 changes: 4 additions & 2 deletions google-cloud-storage/lib/google/cloud/storage/bucket/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def next
return nil unless next?
ensure_service!
gapi = @service.list_buckets prefix: @prefix, token: @token,
max: @max, user_project: @user_project
max: @max, user_project: @user_project,
soft_deleted: @soft_deleted
Bucket::List.from_gapi gapi, @service, @prefix, @max,
user_project: @user_project
end
Expand Down Expand Up @@ -146,7 +147,7 @@ def all request_limit: nil, &block
# @private New Bucket::List from a Google API Client
# Google::Apis::StorageV1::Buckets object.
def self.from_gapi gapi_list, service, prefix = nil, max = nil,
user_project: nil
user_project: nil, soft_deleted: nil
buckets = new(Array(gapi_list.items).map do |gapi_object|
Bucket.from_gapi gapi_object, service, user_project: user_project
end)
Expand All @@ -155,6 +156,7 @@ def self.from_gapi gapi_list, service, prefix = nil, max = nil,
buckets.instance_variable_set :@prefix, prefix
buckets.instance_variable_set :@max, max
buckets.instance_variable_set :@user_project, user_project
buckets.instance_variable_set :@soft_deleted, soft_deleted
buckets
end

Expand Down
61 changes: 57 additions & 4 deletions google-cloud-storage/lib/google/cloud/storage/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,20 @@ def add_custom_header header_name, header_value
# puts bucket.name
# end
#
def buckets prefix: nil, token: nil, max: nil, user_project: nil
# @example Retrieve soft deleted buckets
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# soft_deleted_buckets = storage.buckets soft_deleted: true
# soft_deleted_buckets.each do |bucket|
# puts bucket.name
# end
def buckets prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil
gapi = service.list_buckets \
prefix: prefix, token: token, max: max, user_project: user_project
prefix: prefix, token: token, max: max, user_project: user_project, soft_deleted: soft_deleted
Bucket::List.from_gapi \
gapi, service, prefix, max, user_project: user_project
gapi, service, prefix, max, user_project: user_project, soft_deleted: soft_deleted
end
alias find_buckets buckets

Expand All @@ -222,6 +231,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
# on whether the bucket's current metageneration matches the given value.
# @param [Boolean] soft_deleted If true, returns the soft-deleted bucket.
# This parameter is required if generation is specified.
#
# The value provided will be applied to all operations on the returned
# bucket instance and its files.
Expand Down Expand Up @@ -255,9 +268,20 @@ def buckets prefix: nil, token: nil, max: nil, user_project: nil
# bucket = storage.bucket "other-project-bucket",
# user_project: "my-other-project"
# files = bucket.files # Billed to "my-other-project"
# @example With `soft_deleted` set to true and generation specified:
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# bucket = storage.bucket "my-bucket",
# soft_deleted: true,
# generation: 1234567889
# puts bucket.name
#
def bucket bucket_name,
skip_lookup: false,
generation: nil,
soft_deleted: nil,
if_metageneration_match: nil,
if_metageneration_not_match: nil,
user_project: nil
Expand All @@ -268,7 +292,10 @@ def bucket bucket_name,
gapi = service.get_bucket bucket_name,
if_metageneration_match: if_metageneration_match,
if_metageneration_not_match: if_metageneration_not_match,
user_project: user_project
user_project: user_project,
soft_deleted: soft_deleted,
generation: generation

Bucket.from_gapi gapi, service, user_project: user_project
rescue Google::Cloud::NotFoundError
nil
Expand Down Expand Up @@ -553,6 +580,32 @@ def hmac_keys service_account_email: nil, project_id: nil,
max: max, user_project: user_project
end

##
# Restores a soft deleted bucket with bucket name and generation.
#
# @param [String] bucket_name Name of the bucket.
# @param [Fixnum] generation Generation of the bucket.
#
# @return [Google::Cloud::Storage::Bucket, nil] Returns nil if bucket
# does not exist
#
# @example
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
# generation= 123
#
# bucket = storage.restore_bucket "my-bucket", generation
# puts bucket.name
#
def restore_bucket bucket_name,
generation,
options: {}
gapi = service.restore_bucket bucket_name, generation,
options: options
Bucket.from_gapi gapi, service
end

##
# Generates a signed URL. See [Signed
# URLs](https://cloud.google.com/storage/docs/access-control/signed-urls)
Expand Down
20 changes: 18 additions & 2 deletions google-cloud-storage/lib/google/cloud/storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ def project_service_account

##
# Retrieves a list of buckets for the given project.
def list_buckets prefix: nil, token: nil, max: nil, user_project: nil, options: {}
def list_buckets prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil, options: {}
execute do
service.list_buckets \
@project, prefix: prefix, page_token: token, max_results: max,
user_project: user_project(user_project), options: options
user_project: user_project(user_project),
soft_deleted: soft_deleted, options: options
end
end

Expand All @@ -111,12 +112,16 @@ def get_bucket bucket_name,
if_metageneration_match: nil,
if_metageneration_not_match: nil,
user_project: nil,
soft_deleted: nil,
generation: nil,
options: {}
execute do
service.get_bucket bucket_name,
if_metageneration_match: if_metageneration_match,
if_metageneration_not_match: if_metageneration_not_match,
user_project: user_project(user_project),
soft_deleted: soft_deleted,
generation: generation,
options: options
end
end
Expand Down Expand Up @@ -653,6 +658,17 @@ def delete_file bucket_name,
end
end

##
# Restore soft deleted bucket
def restore_bucket bucket_name,
generation,
options: {}
execute do
service.restore_bucket bucket_name, generation,
options: options
end
end

##
# Restores a soft-deleted object.
def restore_file bucket_name,
Expand Down
Loading