From 62c6d40005b4636a1c53412ed60443bb0893fe5c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 13 Feb 2025 15:12:52 +0000 Subject: [PATCH 01/33] functionality working --- google-cloud-storage/lib/google/cloud/storage.rb | 8 ++++++-- google-cloud-storage/lib/google/cloud/storage/service.rb | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage.rb b/google-cloud-storage/lib/google/cloud/storage.rb index cfc063f60be1..38fce2374552 100644 --- a/google-cloud-storage/lib/google/cloud/storage.rb +++ b/google-cloud-storage/lib/google/cloud/storage.rb @@ -94,7 +94,9 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, endpoint: nil, project: nil, keyfile: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, - multiplier: nil, upload_chunk_size: nil, universe_domain: nil + multiplier: nil, upload_chunk_size: nil, universe_domain: nil, + upload_url: nil, delete_upload: nil + scope ||= configure.scope retries ||= configure.retries timeout ||= configure.timeout @@ -109,7 +111,8 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, multiplier ||= configure.multiplier upload_chunk_size ||= configure.upload_chunk_size universe_domain ||= configure.universe_domain - + upload_url ||= configure.upload_url + delete_upload ||= configure.delete_upload unless credentials.is_a? Google::Auth::Credentials credentials = Storage::Credentials.new credentials, scope: scope end @@ -125,6 +128,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, host: endpoint, quota_project: configure.quota_project, max_elapsed_time: max_elapsed_time, base_interval: base_interval, max_interval: max_interval, multiplier: multiplier, upload_chunk_size: upload_chunk_size, + upload_url: upload_url, delete_upload: delete_upload, universe_domain: universe_domain ) ) diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index d9adf2acff65..22bc2549dd24 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -49,7 +49,9 @@ def initialize project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, - multiplier: nil, upload_chunk_size: nil, universe_domain: nil + multiplier: nil, upload_chunk_size: nil, universe_domain: nil, + upload_url: nil, delete_upload: nil + host ||= Google::Cloud::Storage.configure.endpoint @project = project @credentials = credentials @@ -72,6 +74,8 @@ def initialize project, credentials, retries: nil, @service.request_options.multiplier = multiplier if multiplier @service.request_options.add_invocation_id_header = true @service.request_options.upload_chunk_size = upload_chunk_size if upload_chunk_size + @service.request_options.upload_url = upload_url if upload_url + @service.request_options.delete_upload = delete_upload if delete_upload @service.authorization = @credentials.client if @credentials @service.root_url = host if host @service.universe_domain = universe_domain || Google::Cloud::Storage.configure.universe_domain From b02f88161af7a06a7dd7401b532b5343f15fd459 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 27 Feb 2025 05:23:56 +0000 Subject: [PATCH 02/33] adding missing config --- google-cloud-storage/lib/google-cloud-storage.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/lib/google-cloud-storage.rb b/google-cloud-storage/lib/google-cloud-storage.rb index 1dba01af5dcc..dd0ccb660b28 100644 --- a/google-cloud-storage/lib/google-cloud-storage.rb +++ b/google-cloud-storage/lib/google-cloud-storage.rb @@ -142,7 +142,7 @@ def storage scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_time def self.storage project_id = nil, credentials = nil, scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, - upload_chunk_size: nil + upload_chunk_size: nil, upload_url: nil, delete_upload: nil require "google/cloud/storage" Google::Cloud::Storage.new project_id: project_id, credentials: credentials, @@ -156,7 +156,9 @@ def self.storage project_id = nil, credentials = nil, scope: nil, base_interval: base_interval, max_interval: max_interval, multiplier: multiplier, - upload_chunk_size: upload_chunk_size + upload_chunk_size: upload_chunk_size, + upload_url: upload_url, + delete_upload: delete_upload end end end @@ -193,4 +195,6 @@ def self.storage project_id = nil, credentials = nil, scope: nil, config.add_field! :upload_chunk_size, nil, match: Integer config.add_field! :endpoint, nil, match: String, allow_nil: true config.add_field! :universe_domain, nil, match: String, allow_nil: true + config.add_field! :upload_url, nil, match: String, allow_nil: true + config.add_field! :delete_upload, nil, match: Integer, allow_nil: true end From 4a6d3cab510ec36064def83d6718bcd54d145469 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 27 Feb 2025 19:17:39 +0000 Subject: [PATCH 03/33] fixing unit tests --- .../test/google/cloud/storage_test.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage_test.rb b/google-cloud-storage/test/google/cloud/storage_test.rb index 66033eb11448..a5a9b73ce214 100644 --- a/google-cloud-storage/test/google/cloud/storage_test.rb +++ b/google-cloud-storage/test/google/cloud/storage_test.rb @@ -126,7 +126,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -223,7 +223,7 @@ def creds.is_a? target it "uses provided endpoint and universe_domain" do stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal default_credentials _(retries).must_be :nil? @@ -263,7 +263,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -305,7 +305,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -347,7 +347,7 @@ def creds.is_a? target OpenStruct.new project_id: "project-id" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_be_kind_of OpenStruct _(credentials.project_id).must_equal "project-id" @@ -401,7 +401,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -449,7 +449,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -497,7 +497,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -553,7 +553,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -609,7 +609,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -667,7 +667,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 From bb4d94de81a330496959254e20559f9acd5fb6e8 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 27 Feb 2025 19:22:06 +0000 Subject: [PATCH 04/33] fixing lint issues --- google-cloud-storage/lib/google/cloud/storage.rb | 1 - google-cloud-storage/lib/google/cloud/storage/service.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage.rb b/google-cloud-storage/lib/google/cloud/storage.rb index 38fce2374552..a2ead9271120 100644 --- a/google-cloud-storage/lib/google/cloud/storage.rb +++ b/google-cloud-storage/lib/google/cloud/storage.rb @@ -96,7 +96,6 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil - scope ||= configure.scope retries ||= configure.retries timeout ||= configure.timeout diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index 22bc2549dd24..df27bcb7be91 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -51,7 +51,6 @@ def initialize project, credentials, retries: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil - host ||= Google::Cloud::Storage.configure.endpoint @project = project @credentials = credentials From a8a5a3657dabb76fd77e36b4b90c4eb03a27c06c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 10 Mar 2025 19:38:27 +0000 Subject: [PATCH 05/33] changing storage_cleint approach --- .../lib/google-cloud-storage.rb | 8 ++---- .../lib/google/cloud/storage.rb | 6 +--- .../lib/google/cloud/storage/bucket.rb | 28 +++++++++++++++++-- .../lib/google/cloud/storage/service.rb | 13 ++++++--- .../test/google/cloud/storage_test.rb | 22 +++++++-------- google-cloud-storage/test/helper.rb | 2 ++ 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/google-cloud-storage/lib/google-cloud-storage.rb b/google-cloud-storage/lib/google-cloud-storage.rb index dd0ccb660b28..1dba01af5dcc 100644 --- a/google-cloud-storage/lib/google-cloud-storage.rb +++ b/google-cloud-storage/lib/google-cloud-storage.rb @@ -142,7 +142,7 @@ def storage scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_time def self.storage project_id = nil, credentials = nil, scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, - upload_chunk_size: nil, upload_url: nil, delete_upload: nil + upload_chunk_size: nil require "google/cloud/storage" Google::Cloud::Storage.new project_id: project_id, credentials: credentials, @@ -156,9 +156,7 @@ def self.storage project_id = nil, credentials = nil, scope: nil, base_interval: base_interval, max_interval: max_interval, multiplier: multiplier, - upload_chunk_size: upload_chunk_size, - upload_url: upload_url, - delete_upload: delete_upload + upload_chunk_size: upload_chunk_size end end end @@ -195,6 +193,4 @@ def self.storage project_id = nil, credentials = nil, scope: nil, config.add_field! :upload_chunk_size, nil, match: Integer config.add_field! :endpoint, nil, match: String, allow_nil: true config.add_field! :universe_domain, nil, match: String, allow_nil: true - config.add_field! :upload_url, nil, match: String, allow_nil: true - config.add_field! :delete_upload, nil, match: Integer, allow_nil: true end diff --git a/google-cloud-storage/lib/google/cloud/storage.rb b/google-cloud-storage/lib/google/cloud/storage.rb index a2ead9271120..ef98c3311087 100644 --- a/google-cloud-storage/lib/google/cloud/storage.rb +++ b/google-cloud-storage/lib/google/cloud/storage.rb @@ -94,8 +94,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, endpoint: nil, project: nil, keyfile: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, - multiplier: nil, upload_chunk_size: nil, universe_domain: nil, - upload_url: nil, delete_upload: nil + multiplier: nil, upload_chunk_size: nil, universe_domain: nil scope ||= configure.scope retries ||= configure.retries timeout ||= configure.timeout @@ -110,8 +109,6 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, multiplier ||= configure.multiplier upload_chunk_size ||= configure.upload_chunk_size universe_domain ||= configure.universe_domain - upload_url ||= configure.upload_url - delete_upload ||= configure.delete_upload unless credentials.is_a? Google::Auth::Credentials credentials = Storage::Credentials.new credentials, scope: scope end @@ -127,7 +124,6 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, host: endpoint, quota_project: configure.quota_project, max_elapsed_time: max_elapsed_time, base_interval: base_interval, max_interval: max_interval, multiplier: multiplier, upload_chunk_size: upload_chunk_size, - upload_url: upload_url, delete_upload: delete_upload, universe_domain: universe_domain ) ) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index ca8461354bb7..f7e8acfd5801 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1410,6 +1410,28 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil user_project: user_project end + ## + # Delete ongoing resumable upload + # @param [String, ::File] file Path of the file on the filesystem to + # upload. Can be an File object, or File-like object such as StringIO. + # (If the object does not have path, a `path` argument must be also be + # provided.) + # @param [String] upload_id Unique Id of an Ongoing resumable upload + # + # @example + # require "google/cloud/storage" + # + # storage = Google::Cloud::Storage.new + # + # bucket = storage.bucket "my-bucket" + # bucket.delete_ongoing_resumable_upload file,upload_id + + + def delete_ongoing_resumable_upload file, upload_id + ensure_service! + ensure_io_or_file_exists! file + service.delete_ongoing_resumable_upload name, file, upload_id + end ## # Retrieves a list of files matching the criteria. # @@ -1799,7 +1821,8 @@ def create_file file, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, - if_metageneration_not_match: nil + if_metageneration_not_match: nil, + upload_id: nil ensure_service! ensure_io_or_file_exists! file path ||= file.path if file.respond_to? :path @@ -1830,7 +1853,8 @@ def create_file file, if_generation_not_match: if_generation_not_match, if_metageneration_match: if_metageneration_match, if_metageneration_not_match: if_metageneration_not_match, - user_project: user_project + user_project: user_project, + upload_id: upload_id File.from_gapi gapi, service, user_project: user_project end alias upload_file create_file diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index df27bcb7be91..c0578e4a8e6d 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -49,8 +49,7 @@ def initialize project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, - multiplier: nil, upload_chunk_size: nil, universe_domain: nil, - upload_url: nil, delete_upload: nil + multiplier: nil, upload_chunk_size: nil, universe_domain: nil host ||= Google::Cloud::Storage.configure.endpoint @project = project @credentials = credentials @@ -73,8 +72,6 @@ def initialize project, credentials, retries: nil, @service.request_options.multiplier = multiplier if multiplier @service.request_options.add_invocation_id_header = true @service.request_options.upload_chunk_size = upload_chunk_size if upload_chunk_size - @service.request_options.upload_url = upload_url if upload_url - @service.request_options.delete_upload = delete_upload if delete_upload @service.authorization = @credentials.client if @credentials @service.root_url = host if host @service.universe_domain = universe_domain || Google::Cloud::Storage.configure.universe_domain @@ -412,6 +409,7 @@ def insert_file bucket_name, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil, + upload_id: nil, options: {} params = { cache_control: cache_control, @@ -451,6 +449,7 @@ def insert_file bucket_name, if_metageneration_not_match: if_metageneration_not_match, kms_key_name: kms_key, user_project: user_project(user_project), + upload_id: upload_id, options: options end end @@ -699,6 +698,12 @@ def delete_file bucket_name, end end + def delete_ongoing_resumable_upload bucket_name, source, upload_id + execute do + service.delete_ongoing_resumable_upload bucket_name, source, upload_id + end + end + ## # Restore soft deleted bucket def restore_bucket bucket_name, diff --git a/google-cloud-storage/test/google/cloud/storage_test.rb b/google-cloud-storage/test/google/cloud/storage_test.rb index a5a9b73ce214..66033eb11448 100644 --- a/google-cloud-storage/test/google/cloud/storage_test.rb +++ b/google-cloud-storage/test/google/cloud/storage_test.rb @@ -126,7 +126,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -223,7 +223,7 @@ def creds.is_a? target it "uses provided endpoint and universe_domain" do stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal default_credentials _(retries).must_be :nil? @@ -263,7 +263,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -305,7 +305,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -347,7 +347,7 @@ def creds.is_a? target OpenStruct.new project_id: "project-id" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_be_kind_of OpenStruct _(credentials.project_id).must_equal "project-id" @@ -401,7 +401,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -449,7 +449,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_be :nil? @@ -497,7 +497,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -553,7 +553,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -609,7 +609,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 @@ -667,7 +667,7 @@ def creds.is_a? target "storage-credentials" } stubbed_service = ->(project, credentials, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, host: nil, quota_project: nil, max_elapsed_time: nil, base_interval: nil, - max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil, upload_url: nil, delete_upload: nil) { + max_interval: nil, multiplier: nil, upload_chunk_size: nil, universe_domain: nil) { _(project).must_equal "project-id" _(credentials).must_equal "storage-credentials" _(retries).must_equal 3 diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 5d37f92feb26..b1528e89c0c1 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -374,6 +374,7 @@ def insert_object_args name: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil, + upload_id: nil, options: {} { name: name, @@ -387,6 +388,7 @@ def insert_object_args name: nil, if_metageneration_match: if_metageneration_match, if_metageneration_not_match: if_metageneration_not_match, user_project: user_project, + upload_id: upload_id, options: options } end From 7b155785a2b5964fc74b9502dcca24ea12cc40fa Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 10 Mar 2025 20:22:50 +0000 Subject: [PATCH 06/33] fix linter --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index f7e8acfd5801..300d2849ea50 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1487,6 +1487,7 @@ def delete_ongoing_resumable_upload file, upload_id # puts file.name # end # + def files prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil, match_glob: nil, include_folders_as_prefixes: nil, soft_deleted: nil From 238c1900618386821bc37db19677ba465e684c80 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 13 Mar 2025 10:02:27 +0000 Subject: [PATCH 07/33] code refactoring --- .../lib/google/cloud/storage/bucket.rb | 14 ++++--- .../lib/google/cloud/storage/service.rb | 11 ++---- .../test/google/cloud/storage/bucket_test.rb | 38 +++++++++++++++++++ google-cloud-storage/test/helper.rb | 2 - 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 300d2849ea50..2b04891174b7 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1416,6 +1416,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # upload. Can be an File object, or File-like object such as StringIO. # (If the object does not have path, a `path` argument must be also be # provided.) + # @param [String] file_name Name of file specified for Ongoing resumable upload # @param [String] upload_id Unique Id of an Ongoing resumable upload # # @example @@ -1424,13 +1425,14 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.delete_ongoing_resumable_upload file,upload_id + # bucket.delete_ongoing_resumable_upload file,file_name,upload_id - def delete_ongoing_resumable_upload file, upload_id + def delete_ongoing_resumable_upload file, file_name, upload_id ensure_service! ensure_io_or_file_exists! file - service.delete_ongoing_resumable_upload name, file, upload_id + raise "Upload Id missing" unless upload_id + create_file file, file_name, upload_id: upload_id, delete_upload: true end ## # Retrieves a list of files matching the criteria. @@ -1823,7 +1825,8 @@ def create_file file, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, - upload_id: nil + upload_id: nil, + delete_upload: nil ensure_service! ensure_io_or_file_exists! file path ||= file.path if file.respond_to? :path @@ -1855,7 +1858,8 @@ def create_file file, if_metageneration_match: if_metageneration_match, if_metageneration_not_match: if_metageneration_not_match, user_project: user_project, - upload_id: upload_id + upload_id: upload_id, + delete_upload: delete_upload File.from_gapi gapi, service, user_project: user_project end alias upload_file create_file diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index c0578e4a8e6d..b968693df9e2 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -410,6 +410,7 @@ def insert_file bucket_name, if_metageneration_not_match: nil, user_project: nil, upload_id: nil, + delete_upload: nil, options: {} params = { cache_control: cache_control, @@ -434,7 +435,8 @@ def insert_file bucket_name, else options = key_options(key).merge options end - + options.merge! upload_id: upload_id if upload_id + options.merge! delete_upload: delete_upload if delete_upload && upload_id execute do service.insert_object bucket_name, file_obj, @@ -449,7 +451,6 @@ def insert_file bucket_name, if_metageneration_not_match: if_metageneration_not_match, kms_key_name: kms_key, user_project: user_project(user_project), - upload_id: upload_id, options: options end end @@ -698,12 +699,6 @@ def delete_file bucket_name, end end - def delete_ongoing_resumable_upload bucket_name, source, upload_id - execute do - service.delete_ongoing_resumable_upload bucket_name, source, upload_id - end - end - ## # Restore soft deleted bucket def restore_bucket bucket_name, diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 203e423467e5..b3ff87183deb 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1408,6 +1408,44 @@ end end + it "resstarts a resumable upload with upload_id" do + new_file_name = random_file_path + upload_id= "TEST_ID" + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0, upload_id: upload_id}) + + bucket.service.mocked_service = mock + bucket.create_file tmpfile, new_file_name, upload_id: upload_id + + mock.verify + end + end + + it "deletes a resumable upload with upload_id" do + new_file_name = random_file_path + upload_id= "TEST_ID" + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + + mock = Minitest::Mock.new + mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), + [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0, upload_id: upload_id, delete_upload: true}) + + bucket.service.mocked_service = mock + bucket.delete_ongoing_resumable_upload tmpfile, new_file_name, upload_id + + mock.verify + end + end + def create_file_gapi bucket=nil, name = nil Google::Apis::StorageV1::Object.from_json random_file_hash(bucket, name).to_json end diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index b1528e89c0c1..5d37f92feb26 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -374,7 +374,6 @@ def insert_object_args name: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil, - upload_id: nil, options: {} { name: name, @@ -388,7 +387,6 @@ def insert_object_args name: nil, if_metageneration_match: if_metageneration_match, if_metageneration_not_match: if_metageneration_not_match, user_project: user_project, - upload_id: upload_id, options: options } end From 756a6ae619c784a20ed62c60560aec4a7f10d6f6 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 21 Apr 2025 12:43:21 +0000 Subject: [PATCH 08/33] wip - implementation 2 --- .../lib/google/cloud/storage/bucket.rb | 32 ++++++++++++++++--- .../lib/google/cloud/storage/service.rb | 6 ++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 2b04891174b7..55587446a610 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -717,6 +717,30 @@ def default_kms_key= new_default_kms_key patch_gapi! :encryption end + ## + # Restart ongoing resumable upload + # @param [String, ::File] file Path of the file on the filesystem to + # upload. Can be an File object, or File-like object such as StringIO. + # (If the object does not have path, a `path` argument must be also be + # provided.) + # @param [String] upload_id Unique Id of an Ongoing resumable upload + # + # @example + # require "google/cloud/storage" + # + # storage = Google::Cloud::Storage.new + # + # bucket = storage.bucket "my-bucket" + # bucket.restart_ongoing_resumable_upload file,upload_id + + + def restart_ongoing_resumable_upload file, upload_id + ensure_service! + ensure_io_or_file_exists! file + raise "Upload Id missing" unless upload_id + service.restart_delete_ongoing_resumable_upload name, file, upload_id + end + ## # The period of time (in seconds) that files in the bucket must be # retained, and cannot be deleted, overwritten, or archived. @@ -1416,7 +1440,6 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # upload. Can be an File object, or File-like object such as StringIO. # (If the object does not have path, a `path` argument must be also be # provided.) - # @param [String] file_name Name of file specified for Ongoing resumable upload # @param [String] upload_id Unique Id of an Ongoing resumable upload # # @example @@ -1425,14 +1448,13 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.delete_ongoing_resumable_upload file,file_name,upload_id - + # bucket.delete_ongoing_resumable_upload file,upload_id - def delete_ongoing_resumable_upload file, file_name, upload_id + def delete_ongoing_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise "Upload Id missing" unless upload_id - create_file file, file_name, upload_id: upload_id, delete_upload: true + service.restart_delete_ongoing_resumable_upload name, file, upload_id, options: {delete_upload: true} end ## # Retrieves a list of files matching the criteria. diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index b968693df9e2..e15f537f14a8 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -699,6 +699,12 @@ def delete_file bucket_name, end end + def restart_delete_ongoing_resumable_upload bucket_name, source, upload_id, options: {} + execute do + service.restart_delete_ongoing_resumable_upload bucket_name, source, upload_id, options: options + end + end + ## # Restore soft deleted bucket def restore_bucket bucket_name, From 3dcc3cecf9cd2901f6d4aa821a96904744940a1c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 24 Apr 2025 11:03:05 +0000 Subject: [PATCH 09/33] changes working --- .../lib/google/cloud/storage/bucket.rb | 12 ++++++------ .../lib/google/cloud/storage/service.rb | 10 ++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 55587446a610..5e407db0931f 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -731,14 +731,14 @@ def default_kms_key= new_default_kms_key # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.restart_ongoing_resumable_upload file,upload_id + # bucket.restart_resumable_upload file,upload_id - def restart_ongoing_resumable_upload file, upload_id + def restart_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise "Upload Id missing" unless upload_id - service.restart_delete_ongoing_resumable_upload name, file, upload_id + service.restart_resumable_upload name, file, upload_id end ## @@ -1448,13 +1448,13 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.delete_ongoing_resumable_upload file,upload_id + # bucket.delete_resumable_upload file,upload_id - def delete_ongoing_resumable_upload file, upload_id + def delete_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise "Upload Id missing" unless upload_id - service.restart_delete_ongoing_resumable_upload name, file, upload_id, options: {delete_upload: true} + service.delete_resumable_upload name, file, upload_id, options: {delete_upload: true} end ## # Retrieves a list of files matching the criteria. diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index e15f537f14a8..cdbe0c88e978 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -699,9 +699,15 @@ def delete_file bucket_name, end end - def restart_delete_ongoing_resumable_upload bucket_name, source, upload_id, options: {} + def restart_resumable_upload bucket_name, source, upload_id, options: {} execute do - service.restart_delete_ongoing_resumable_upload bucket_name, source, upload_id, options: options + service.restart_resumable_upload bucket_name, source, upload_id, options: options + end + end + + def delete_resumable_upload bucket_name, source, upload_id, options: {} + execute do + service.delete_resumable_upload bucket_name, source, upload_id, options: options end end From 128a8ed61fa06f1b0107701523486d3c935216a7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 30 Apr 2025 11:05:57 +0000 Subject: [PATCH 10/33] adding test cases --- .../lib/google/cloud/storage/bucket.rb | 8 +++---- .../test/google/cloud/storage/bucket_test.rb | 22 +++++++++---------- google-cloud-storage/test/helper.rb | 12 ++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 5e407db0931f..a6bd1f401349 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -718,12 +718,12 @@ def default_kms_key= new_default_kms_key end ## - # Restart ongoing resumable upload + # Restart resumable upload # @param [String, ::File] file Path of the file on the filesystem to # upload. Can be an File object, or File-like object such as StringIO. # (If the object does not have path, a `path` argument must be also be # provided.) - # @param [String] upload_id Unique Id of an Ongoing resumable upload + # @param [String] upload_id Unique Id of an resumable upload # # @example # require "google/cloud/storage" @@ -1435,12 +1435,12 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil end ## - # Delete ongoing resumable upload + # Delete resumable upload # @param [String, ::File] file Path of the file on the filesystem to # upload. Can be an File object, or File-like object such as StringIO. # (If the object does not have path, a `path` argument must be also be # provided.) - # @param [String] upload_id Unique Id of an Ongoing resumable upload + # @param [String] upload_id Unique Id of an resumable upload # # @example # require "google/cloud/storage" diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index b3ff87183deb..d7b8ecac3f35 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1408,27 +1408,25 @@ end end - it "resstarts a resumable upload with upload_id" do + it "restarts a resumable upload with upload_id" do new_file_name = random_file_path upload_id= "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" tmpfile.rewind - mock = Minitest::Mock.new - mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0, upload_id: upload_id}) - + mock.expect :restart_resumable_upload, create_file_gapi(bucket.name, new_file_name), + [bucket.name, tmpfile, upload_id], + **restart_resumable_upload_args(options: {}) bucket.service.mocked_service = mock - bucket.create_file tmpfile, new_file_name, upload_id: upload_id + bucket.restart_resumable_upload tmpfile, upload_id mock.verify end end - it "deletes a resumable upload with upload_id" do - new_file_name = random_file_path + it "deletes a resumable upload with upload_id" do upload_id= "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| @@ -1436,11 +1434,11 @@ tmpfile.rewind mock = Minitest::Mock.new - mock.expect :insert_object, create_file_gapi(bucket.name, new_file_name), - [bucket.name, empty_file_gapi], **insert_object_args(name: new_file_name, upload_source: tmpfile, options: {retries: 0, upload_id: upload_id, delete_upload: true}) - + mock.expect :delete_resumable_upload, true, + [bucket.name, tmpfile, upload_id], + **delete_resumable_upload_args(options: {delete_upload: true}) bucket.service.mocked_service = mock - bucket.delete_ongoing_resumable_upload tmpfile, new_file_name, upload_id + bucket.delete_resumable_upload tmpfile, upload_id mock.verify end diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index 5d37f92feb26..f5518a4810fc 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -391,6 +391,18 @@ def insert_object_args name: nil, } end + def delete_resumable_upload_args options: {} + { + options: options + } + end + + def restart_resumable_upload_args options: {} + { + options: options + } + end + def get_object_args generation: nil, if_generation_match: nil, if_generation_not_match: nil, From c313da6e4e0611ef76b98c98b487384e24926b47 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 30 Apr 2025 11:21:32 +0000 Subject: [PATCH 11/33] fix typo --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index a6bd1f401349..252ae1b851a5 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1454,7 +1454,7 @@ def delete_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise "Upload Id missing" unless upload_id - service.delete_resumable_upload name, file, upload_id, options: {delete_upload: true} + service.delete_resumable_upload name, file, upload_id, options: { delete_upload: true } end ## # Retrieves a list of files matching the criteria. From 9b06029813c732f4c47cb45acd1682d077cffec4 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 30 Apr 2025 11:32:15 +0000 Subject: [PATCH 12/33] removing unwanted change --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 8 ++------ google-cloud-storage/lib/google/cloud/storage/service.rb | 4 ---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 252ae1b851a5..0c8bdf06556e 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1846,9 +1846,7 @@ def create_file file, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, - if_metageneration_not_match: nil, - upload_id: nil, - delete_upload: nil + if_metageneration_not_match: nil ensure_service! ensure_io_or_file_exists! file path ||= file.path if file.respond_to? :path @@ -1879,9 +1877,7 @@ def create_file file, if_generation_not_match: if_generation_not_match, if_metageneration_match: if_metageneration_match, if_metageneration_not_match: if_metageneration_not_match, - user_project: user_project, - upload_id: upload_id, - delete_upload: delete_upload + user_project: user_project File.from_gapi gapi, service, user_project: user_project end alias upload_file create_file diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index cdbe0c88e978..5f207b136c18 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -409,8 +409,6 @@ def insert_file bucket_name, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil, - upload_id: nil, - delete_upload: nil, options: {} params = { cache_control: cache_control, @@ -435,8 +433,6 @@ def insert_file bucket_name, else options = key_options(key).merge options end - options.merge! upload_id: upload_id if upload_id - options.merge! delete_upload: delete_upload if delete_upload && upload_id execute do service.insert_object bucket_name, file_obj, From 77068a5f2d2dbee2e1a55e9635cecdecc4d82739 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 30 Apr 2025 11:37:00 +0000 Subject: [PATCH 13/33] removing unwanted changes --- google-cloud-storage/lib/google/cloud/storage.rb | 1 + google-cloud-storage/lib/google/cloud/storage/bucket.rb | 1 - google-cloud-storage/lib/google/cloud/storage/service.rb | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage.rb b/google-cloud-storage/lib/google/cloud/storage.rb index ef98c3311087..cfc063f60be1 100644 --- a/google-cloud-storage/lib/google/cloud/storage.rb +++ b/google-cloud-storage/lib/google/cloud/storage.rb @@ -109,6 +109,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, multiplier ||= configure.multiplier upload_chunk_size ||= configure.upload_chunk_size universe_domain ||= configure.universe_domain + unless credentials.is_a? Google::Auth::Credentials credentials = Storage::Credentials.new credentials, scope: scope end diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 0c8bdf06556e..73083af12e97 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -733,7 +733,6 @@ def default_kms_key= new_default_kms_key # bucket = storage.bucket "my-bucket" # bucket.restart_resumable_upload file,upload_id - def restart_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index 5f207b136c18..b478e6699d00 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -433,6 +433,7 @@ def insert_file bucket_name, else options = key_options(key).merge options end + execute do service.insert_object bucket_name, file_obj, From b39dca7e4799e8d9e2bb2c248690dd61f09e2f50 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 7 May 2025 05:50:31 +0000 Subject: [PATCH 14/33] rewritting delete upload --- .../lib/google/cloud/storage/bucket.rb | 9 ++------- .../lib/google/cloud/storage/service.rb | 4 ++-- .../test/google/cloud/storage/bucket_test.rb | 20 +++++++------------ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 73083af12e97..1a03d44d0258 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1435,10 +1435,6 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil ## # Delete resumable upload - # @param [String, ::File] file Path of the file on the filesystem to - # upload. Can be an File object, or File-like object such as StringIO. - # (If the object does not have path, a `path` argument must be also be - # provided.) # @param [String] upload_id Unique Id of an resumable upload # # @example @@ -1449,11 +1445,10 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # bucket = storage.bucket "my-bucket" # bucket.delete_resumable_upload file,upload_id - def delete_resumable_upload file, upload_id + def delete_resumable_upload upload_id ensure_service! - ensure_io_or_file_exists! file raise "Upload Id missing" unless upload_id - service.delete_resumable_upload name, file, upload_id, options: { delete_upload: true } + service.delete_resumable_upload name, upload_id, options: { delete_upload: true } end ## # Retrieves a list of files matching the criteria. diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb index b478e6699d00..4d3fcaf07c09 100644 --- a/google-cloud-storage/lib/google/cloud/storage/service.rb +++ b/google-cloud-storage/lib/google/cloud/storage/service.rb @@ -702,9 +702,9 @@ def restart_resumable_upload bucket_name, source, upload_id, options: {} end end - def delete_resumable_upload bucket_name, source, upload_id, options: {} + def delete_resumable_upload bucket_name, upload_id, options: {} execute do - service.delete_resumable_upload bucket_name, source, upload_id, options: options + service.delete_resumable_upload bucket_name, upload_id, options: options end end diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index d7b8ecac3f35..b4d8500e7ce0 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1429,19 +1429,13 @@ it "deletes a resumable upload with upload_id" do upload_id= "TEST_ID" - Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world" - tmpfile.rewind - - mock = Minitest::Mock.new - mock.expect :delete_resumable_upload, true, - [bucket.name, tmpfile, upload_id], - **delete_resumable_upload_args(options: {delete_upload: true}) - bucket.service.mocked_service = mock - bucket.delete_resumable_upload tmpfile, upload_id - - mock.verify - end + mock = Minitest::Mock.new + mock.expect :delete_resumable_upload, true, + [bucket.name, upload_id], + **delete_resumable_upload_args(options: {delete_upload: true}) + bucket.service.mocked_service = mock + bucket.delete_resumable_upload upload_id + mock.verify end def create_file_gapi bucket=nil, name = nil From e136db8d271b7f963f4ddf08c2d772f32dca1b6e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 21 May 2025 17:29:19 +0530 Subject: [PATCH 15/33] Update google-cloud-storage/lib/google/cloud/storage/bucket.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 1a03d44d0258..6f51b2042df9 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -723,7 +723,7 @@ def default_kms_key= new_default_kms_key # upload. Can be an File object, or File-like object such as StringIO. # (If the object does not have path, a `path` argument must be also be # provided.) - # @param [String] upload_id Unique Id of an resumable upload + # @param [String] upload_id Unique Id of a resumable upload # # @example # require "google/cloud/storage" From 2e0294cf3da4f341aded1732a462e4d5e1c46886 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 11 Jun 2025 20:18:39 +0000 Subject: [PATCH 16/33] chnaging method params --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 6f51b2042df9..1959b249bd7a 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1448,7 +1448,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil def delete_resumable_upload upload_id ensure_service! raise "Upload Id missing" unless upload_id - service.delete_resumable_upload name, upload_id, options: { delete_upload: true } + service.delete_resumable_upload name, upload_id end ## # Retrieves a list of files matching the criteria. diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index b4d8500e7ce0..03cf1afc64de 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1432,7 +1432,7 @@ mock = Minitest::Mock.new mock.expect :delete_resumable_upload, true, [bucket.name, upload_id], - **delete_resumable_upload_args(options: {delete_upload: true}) + **delete_resumable_upload_args(options: {}) bucket.service.mocked_service = mock bucket.delete_resumable_upload upload_id mock.verify From 86378a6f522f46f82452b197dfc06fa92c2bb28a Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 08:31:03 +0000 Subject: [PATCH 17/33] addressing comments --- .../lib/google/cloud/storage/bucket.rb | 12 +++-- .../test/google/cloud/storage/bucket_test.rb | 51 +++++++++++++++---- google-cloud-storage/test/helper.rb | 8 +-- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 1959b249bd7a..07e8086fa9dd 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -725,6 +725,9 @@ def default_kms_key= new_default_kms_key # provided.) # @param [String] upload_id Unique Id of a resumable upload # + # @return [Hash(String => String)] + # A Hash of file object returned from server. + # # @example # require "google/cloud/storage" # @@ -736,7 +739,7 @@ def default_kms_key= new_default_kms_key def restart_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file - raise "Upload Id missing" unless upload_id + raise ArgumentError, "Upload Id missing" unless upload_id service.restart_resumable_upload name, file, upload_id end @@ -1437,19 +1440,22 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # Delete resumable upload # @param [String] upload_id Unique Id of an resumable upload # + # @return [Boolean] Returns `true` if the bucket was deleted. + # # @example # require "google/cloud/storage" # # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.delete_resumable_upload file,upload_id + # bucket.delete_resumable_upload upload_id def delete_resumable_upload upload_id ensure_service! - raise "Upload Id missing" unless upload_id + raise ArgumentError, "Upload Id missing" unless upload_id service.delete_resumable_upload name, upload_id end + ## # Retrieves a list of files matching the criteria. # diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 03cf1afc64de..d6104a227918 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1408,7 +1408,7 @@ end end - it "restarts a resumable upload with upload_id" do + it "restarts a resumable upload with upload_id" do new_file_name = random_file_path upload_id= "TEST_ID" @@ -1416,28 +1416,61 @@ tmpfile.write "Hello world" tmpfile.rewind mock = Minitest::Mock.new - mock.expect :restart_resumable_upload, create_file_gapi(bucket.name, new_file_name), + expected_return_value = create_file_gapi(bucket.name, new_file_name) + mock.expect :restart_resumable_upload, expected_return_value, [bucket.name, tmpfile, upload_id], - **restart_resumable_upload_args(options: {}) + **resumable_upload_args(options: {}) bucket.service.mocked_service = mock - bucket.restart_resumable_upload tmpfile, upload_id - + returned_value= bucket.restart_resumable_upload tmpfile, upload_id + assert_equal expected_return_value, returned_value mock.verify end end - it "deletes a resumable upload with upload_id" do + it "raises ArgumentError if upload_id is not provided to restart_resumable_upload" do + new_file_name = random_file_path upload_id= "TEST_ID" + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + mock = Minitest::Mock.new + mock.expect :restart_resumable_upload, create_file_gapi(bucket.name, new_file_name), + [bucket.name, tmpfile, upload_id], + **resumable_upload_args(options: {}) + bucket.service.mocked_service = mock + expect do + bucket.restart_resumable_upload tmpfile + end.must_raise ArgumentError + end + end + + it "deletes a resumable upload with upload_id" do + upload_id = "TEST_ID" + mock = Minitest::Mock.new - mock.expect :delete_resumable_upload, true, + expected_return_value = true + mock.expect :delete_resumable_upload, expected_return_value, [bucket.name, upload_id], - **delete_resumable_upload_args(options: {}) + **resumable_upload_args(options: {}) bucket.service.mocked_service = mock - bucket.delete_resumable_upload upload_id + returned_value = bucket.delete_resumable_upload upload_id + assert_equal expected_return_value, returned_value mock.verify end + it "Raises ArgumentError if upload_id is not provided to delete_resumable_upload" do + upload_id = "TEST_ID" + mock = Minitest::Mock.new + mock.expect :delete_resumable_upload, true, + [bucket.name, upload_id], + **resumable_upload_args(options: {}) + bucket.service.mocked_service = mock + expect do + bucket.delete_resumable_upload + end.must_raise ArgumentError + end + def create_file_gapi bucket=nil, name = nil Google::Apis::StorageV1::Object.from_json random_file_hash(bucket, name).to_json end diff --git a/google-cloud-storage/test/helper.rb b/google-cloud-storage/test/helper.rb index f5518a4810fc..09644b957b7a 100644 --- a/google-cloud-storage/test/helper.rb +++ b/google-cloud-storage/test/helper.rb @@ -391,13 +391,7 @@ def insert_object_args name: nil, } end - def delete_resumable_upload_args options: {} - { - options: options - } - end - - def restart_resumable_upload_args options: {} + def resumable_upload_args options: {} { options: options } From 2835d7988af6ecf81ff15bed2fb8f498cb0f66df Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 08:34:48 +0000 Subject: [PATCH 18/33] removing space --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index d6104a227918..8b8ed5d4a295 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1454,7 +1454,7 @@ [bucket.name, upload_id], **resumable_upload_args(options: {}) bucket.service.mocked_service = mock - returned_value = bucket.delete_resumable_upload upload_id + returned_value = bucket.delete_resumable_upload upload_id assert_equal expected_return_value, returned_value mock.verify end From d3b9da817597b9aab6c293775de538e890ed0e57 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 08:40:23 +0000 Subject: [PATCH 19/33] resolving syntax --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 8b8ed5d4a295..a492f1d649a2 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1410,7 +1410,7 @@ it "restarts a resumable upload with upload_id" do new_file_name = random_file_path - upload_id= "TEST_ID" + upload_id = "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" @@ -1429,7 +1429,7 @@ it "raises ArgumentError if upload_id is not provided to restart_resumable_upload" do new_file_name = random_file_path - upload_id= "TEST_ID" + upload_id = "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" From c9c92237ee3855842226084aa4cf8a1e71a001a7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 16:42:33 +0530 Subject: [PATCH 20/33] Update bucket.rb --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 07e8086fa9dd..ebe3362af49b 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1511,7 +1511,6 @@ def delete_resumable_upload upload_id # puts file.name # end # - def files prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil, match_glob: nil, include_folders_as_prefixes: nil, soft_deleted: nil From 61350b0ad7725534d059d81bd092b39754ee9270 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 13:09:42 +0000 Subject: [PATCH 21/33] adding returntype --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 9 +++++---- .../test/google/cloud/storage/bucket_test.rb | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index ebe3362af49b..ed6a2cbaf2b3 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -725,8 +725,8 @@ def default_kms_key= new_default_kms_key # provided.) # @param [String] upload_id Unique Id of a resumable upload # - # @return [Hash(String => String)] - # A Hash of file object returned from server. + # @return [Google::Cloud::Storage::File] + # The newly created File object. # # @example # require "google/cloud/storage" @@ -740,7 +740,8 @@ def restart_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise ArgumentError, "Upload Id missing" unless upload_id - service.restart_resumable_upload name, file, upload_id + # service.restart_resumable_upload name, file, upload_id + File.from_gapi service.restart_resumable_upload(name, file, upload_id), service end ## @@ -1440,7 +1441,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # Delete resumable upload # @param [String] upload_id Unique Id of an resumable upload # - # @return [Boolean] Returns `true` if the bucket was deleted. + # @return [Boolean] Returns `true` if the resumable upload was deleted. # # @example # require "google/cloud/storage" diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index a492f1d649a2..3fd27b48c984 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1459,7 +1459,7 @@ mock.verify end - it "Raises ArgumentError if upload_id is not provided to delete_resumable_upload" do + it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do upload_id = "TEST_ID" mock = Minitest::Mock.new mock.expect :delete_resumable_upload, true, From b1331c7939e14549d8e3b3d3fc4e1de207f65f50 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 13:18:48 +0000 Subject: [PATCH 22/33] adding returntype --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index ed6a2cbaf2b3..138941245639 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -725,8 +725,8 @@ def default_kms_key= new_default_kms_key # provided.) # @param [String] upload_id Unique Id of a resumable upload # - # @return [Google::Cloud::Storage::File] - # The newly created File object. + # @return [Google::Apis::StorageV1::Object] + # The newly created storage object. # # @example # require "google/cloud/storage" @@ -740,8 +740,7 @@ def restart_resumable_upload file, upload_id ensure_service! ensure_io_or_file_exists! file raise ArgumentError, "Upload Id missing" unless upload_id - # service.restart_resumable_upload name, file, upload_id - File.from_gapi service.restart_resumable_upload(name, file, upload_id), service + service.restart_resumable_upload name, file, upload_id end ## From 7e1a89fd3620c0291433b4246b02a53ea796f483 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 25 Aug 2025 14:05:00 +0000 Subject: [PATCH 23/33] modifying test --- .../lib/google/cloud/storage/bucket.rb | 6 ++---- .../test/google/cloud/storage/bucket_test.rb | 11 ----------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 138941245639..42a807a0a9fe 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -721,8 +721,6 @@ def default_kms_key= new_default_kms_key # Restart resumable upload # @param [String, ::File] file Path of the file on the filesystem to # upload. Can be an File object, or File-like object such as StringIO. - # (If the object does not have path, a `path` argument must be also be - # provided.) # @param [String] upload_id Unique Id of a resumable upload # # @return [Google::Apis::StorageV1::Object] @@ -734,7 +732,7 @@ def default_kms_key= new_default_kms_key # storage = Google::Cloud::Storage.new # # bucket = storage.bucket "my-bucket" - # bucket.restart_resumable_upload file,upload_id + # bucket.restart_resumable_upload file, upload_id def restart_resumable_upload file, upload_id ensure_service! @@ -1438,7 +1436,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil ## # Delete resumable upload - # @param [String] upload_id Unique Id of an resumable upload + # @param [String] upload_id Unique Id of a resumable upload # # @return [Boolean] Returns `true` if the resumable upload was deleted. # diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 3fd27b48c984..873d8b20547b 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1434,11 +1434,6 @@ Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" tmpfile.rewind - mock = Minitest::Mock.new - mock.expect :restart_resumable_upload, create_file_gapi(bucket.name, new_file_name), - [bucket.name, tmpfile, upload_id], - **resumable_upload_args(options: {}) - bucket.service.mocked_service = mock expect do bucket.restart_resumable_upload tmpfile end.must_raise ArgumentError @@ -1460,12 +1455,6 @@ end it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do - upload_id = "TEST_ID" - mock = Minitest::Mock.new - mock.expect :delete_resumable_upload, true, - [bucket.name, upload_id], - **resumable_upload_args(options: {}) - bucket.service.mocked_service = mock expect do bucket.delete_resumable_upload end.must_raise ArgumentError From 8d60e4c3e70893d771749692a99eade294fa83e4 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 26 Aug 2025 02:36:58 +0000 Subject: [PATCH 24/33] fixing rubocop issue in toys --- .toys/batch-review-legacy.rb | 4 ++-- .toys/batch-review.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.toys/batch-review-legacy.rb b/.toys/batch-review-legacy.rb index 8801147607e9..69a043a4e7ed 100644 --- a/.toys/batch-review-legacy.rb +++ b/.toys/batch-review-legacy.rb @@ -41,7 +41,7 @@ /\.release-please-manifest\.json$/, /\/CHANGELOG\.md$/, /\/version\.rb$/, - /\/snippets\/snippet_metadata_[\w\.]+\.json$/, + /\/snippets\/snippet_metadata_[\w.]+\.json$/, ], }, "releases-wrappers" => { @@ -62,7 +62,7 @@ /\.release-please-manifest\.json$/, /\/CHANGELOG\.md$/, /\/version\.rb$/, - /\/snippets\/snippet_metadata_[\w\.]+\.json$/, + /\/snippets\/snippet_metadata_[\w.]+\.json$/, ], }, }.freeze diff --git a/.toys/batch-review.rb b/.toys/batch-review.rb index b97d8ad5fc04..31edb28afba1 100644 --- a/.toys/batch-review.rb +++ b/.toys/batch-review.rb @@ -31,7 +31,7 @@ batch_reviewer.define_preset "releases", based_on: :basic_releases do |preset| preset.message << :pr_title_number preset.diff_expectations.expect name: "snippet metadata" do |expect| - expect.change_type(:changed).path_pattern(/\/snippets\/snippet_metadata_[\w\.]+\.json$/) + expect.change_type(:changed).path_pattern(/\/snippets\/snippet_metadata_[\w.]+\.json$/) end preset.diff_expectations.expect name: "repo metadata" do |expect| expect.change_type(:changed).path_pattern(/\/\.repo-metadata\.json$/) From c646691a199e48777151ffd4817243167ad93386 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 26 Aug 2025 03:00:03 +0000 Subject: [PATCH 25/33] update storage_v1 gem version --- google-cloud-storage/google-cloud-storage.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/google-cloud-storage.gemspec b/google-cloud-storage/google-cloud-storage.gemspec index 98f959552aee..c2d83f17d6c2 100644 --- a/google-cloud-storage/google-cloud-storage.gemspec +++ b/google-cloud-storage/google-cloud-storage.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| gem.add_dependency "google-cloud-core", "~> 1.6" gem.add_dependency "google-apis-core", ">= 0.18", "< 2" gem.add_dependency "google-apis-iamcredentials_v1", "~> 0.18" - gem.add_dependency "google-apis-storage_v1", ">= 0.42" + gem.add_dependency "google-apis-storage_v1", ">= 0.56" gem.add_dependency "googleauth", "~> 1.9" gem.add_dependency "digest-crc", "~> 0.4" gem.add_dependency "addressable", "~> 2.8" From 6f1fb62f9392907c4ce5b8da1d7e652db7021ad8 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 29 Aug 2025 06:06:53 +0000 Subject: [PATCH 26/33] updating test cases --- .../test/google/cloud/storage/bucket_test.rb | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 873d8b20547b..592f8536d2b6 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1427,19 +1427,37 @@ end end - it "raises ArgumentError if upload_id is not provided to restart_resumable_upload" do + it "raises ArgumentError if anyone or both arguments are not provided to restart_resumable_upload" do new_file_name = random_file_path upload_id = "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| tmpfile.write "Hello world" tmpfile.rewind - expect do - bucket.restart_resumable_upload tmpfile - end.must_raise ArgumentError + error = _ { bucket.restart_resumable_upload }.must_raise ArgumentError + assert_match "wrong number of arguments", error.message + + error = _ { bucket.restart_resumable_upload upload_id }.must_raise ArgumentError + assert_match "wrong number of arguments", error.message + + error = _ { bucket.restart_resumable_upload tmpfile }.must_raise ArgumentError + assert_match "wrong number of arguments", error.message + end + end + + it "raises ArgumentError if upload_id as nil is provided to restart_resumable_upload" do + new_file_name = random_file_path + upload_id = nil + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + error = _ { bucket.restart_resumable_upload tmpfile, upload_id }.must_raise ArgumentError + assert_match "Upload Id missing", error.message end end + it "deletes a resumable upload with upload_id" do upload_id = "TEST_ID" @@ -1455,9 +1473,27 @@ end it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do - expect do - bucket.delete_resumable_upload - end.must_raise ArgumentError + new_file_name = random_file_path + upload_id = "TEST_ID" + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError + assert_match "wrong number of arguments", error.message + end + end + + it "raises ArgumentError if upload_id as nil is provided to delete_resumable_upload" do + new_file_name = random_file_path + upload_id = nil + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + error = _ { bucket.delete_resumable_upload upload_id }.must_raise ArgumentError + assert_match "Upload Id missing", error.message + end end def create_file_gapi bucket=nil, name = nil From 90b87dee7c4d66d8e3cded8fa01c1986224e271b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Sun, 31 Aug 2025 16:37:13 +0000 Subject: [PATCH 27/33] updating documentation --- .../lib/google/cloud/storage/bucket.rb | 6 ++--- .../test/google/cloud/storage/bucket_test.rb | 22 ++++--------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 42a807a0a9fe..778d655f6f8f 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -723,8 +723,8 @@ def default_kms_key= new_default_kms_key # upload. Can be an File object, or File-like object such as StringIO. # @param [String] upload_id Unique Id of a resumable upload # - # @return [Google::Apis::StorageV1::Object] - # The newly created storage object. + # @return [Google::Apis::StorageV1::Object, Integer] + # The object metadata on success, or 0 request is not completed. # # @example # require "google/cloud/storage" @@ -1438,7 +1438,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # Delete resumable upload # @param [String] upload_id Unique Id of a resumable upload # - # @return [Boolean] Returns `true` if the resumable upload was deleted. + # @return [Boolean,nil] Returns `true` if the resumable upload was deleted, 'nil' if the request is not completed. # # @example # require "google/cloud/storage" diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index 592f8536d2b6..dc2180a8319c 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1428,7 +1428,6 @@ end it "raises ArgumentError if anyone or both arguments are not provided to restart_resumable_upload" do - new_file_name = random_file_path upload_id = "TEST_ID" Tempfile.open ["google-cloud", ".txt"] do |tmpfile| @@ -1446,7 +1445,6 @@ end it "raises ArgumentError if upload_id as nil is provided to restart_resumable_upload" do - new_file_name = random_file_path upload_id = nil Tempfile.open ["google-cloud", ".txt"] do |tmpfile| @@ -1473,27 +1471,15 @@ end it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do - new_file_name = random_file_path - upload_id = "TEST_ID" - Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world" - tmpfile.rewind - error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError - assert_match "wrong number of arguments", error.message - end + error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError + assert_match "wrong number of arguments", error.message end it "raises ArgumentError if upload_id as nil is provided to delete_resumable_upload" do - new_file_name = random_file_path upload_id = nil - - Tempfile.open ["google-cloud", ".txt"] do |tmpfile| - tmpfile.write "Hello world" - tmpfile.rewind - error = _ { bucket.delete_resumable_upload upload_id }.must_raise ArgumentError - assert_match "Upload Id missing", error.message - end + error = _ { bucket.delete_resumable_upload upload_id }.must_raise ArgumentError + assert_match "Upload Id missing", error.message end def create_file_gapi bucket=nil, name = nil From 9c627c85786ffa29803ee1961f0db890e3d53223 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Sun, 31 Aug 2025 16:45:19 +0000 Subject: [PATCH 28/33] fix rubocop issue --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 778d655f6f8f..3085a43fc7a2 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -1438,7 +1438,8 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # Delete resumable upload # @param [String] upload_id Unique Id of a resumable upload # - # @return [Boolean,nil] Returns `true` if the resumable upload was deleted, 'nil' if the request is not completed. + # @return [Boolean,nil] Returns `true` if the resumable upload was deleted, + # 'nil' if the request is not completed. # # @example # require "google/cloud/storage" From b4f9b69cf483494d31953d3670556e13c21c32de Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 1 Sep 2025 12:01:06 +0530 Subject: [PATCH 29/33] Update google-cloud-storage/lib/google/cloud/storage/bucket.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 3085a43fc7a2..956154c266a0 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -720,7 +720,7 @@ def default_kms_key= new_default_kms_key ## # Restart resumable upload # @param [String, ::File] file Path of the file on the filesystem to - # upload. Can be an File object, or File-like object such as StringIO. + # upload. Can be a File object, or File-like object such as StringIO. # @param [String] upload_id Unique Id of a resumable upload # # @return [Google::Apis::StorageV1::Object, Integer] From deee4022a8407abd69ef6d0ed81612ec21ac63fd Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 1 Sep 2025 12:01:15 +0530 Subject: [PATCH 30/33] Update google-cloud-storage/lib/google/cloud/storage/bucket.rb Co-authored-by: Neha Bajaj --- google-cloud-storage/lib/google/cloud/storage/bucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 956154c266a0..5f943bba4dc0 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -724,7 +724,7 @@ def default_kms_key= new_default_kms_key # @param [String] upload_id Unique Id of a resumable upload # # @return [Google::Apis::StorageV1::Object, Integer] - # The object metadata on success, or 0 request is not completed. + # The object metadata on success, or 0 if request is not completed. # # @example # require "google/cloud/storage" From 25c3b97b0612cd38e54bc6e6ec80ede78aca3870 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 1 Sep 2025 16:36:08 +0530 Subject: [PATCH 31/33] Update google-cloud-storage.gemspec --- google-cloud-storage/google-cloud-storage.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/google-cloud-storage.gemspec b/google-cloud-storage/google-cloud-storage.gemspec index c2d83f17d6c2..98f959552aee 100644 --- a/google-cloud-storage/google-cloud-storage.gemspec +++ b/google-cloud-storage/google-cloud-storage.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| gem.add_dependency "google-cloud-core", "~> 1.6" gem.add_dependency "google-apis-core", ">= 0.18", "< 2" gem.add_dependency "google-apis-iamcredentials_v1", "~> 0.18" - gem.add_dependency "google-apis-storage_v1", ">= 0.56" + 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" From 0b4cd362618b0582d2d77cfafbc99efff860d263 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 12 Sep 2025 11:15:32 +0000 Subject: [PATCH 32/33] add test case --- .../lib/google/cloud/storage/bucket.rb | 8 ++--- .../test/google/cloud/storage/bucket_test.rb | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/lib/google/cloud/storage/bucket.rb b/google-cloud-storage/lib/google/cloud/storage/bucket.rb index 5f943bba4dc0..885f729d4500 100644 --- a/google-cloud-storage/lib/google/cloud/storage/bucket.rb +++ b/google-cloud-storage/lib/google/cloud/storage/bucket.rb @@ -723,8 +723,8 @@ def default_kms_key= new_default_kms_key # upload. Can be a File object, or File-like object such as StringIO. # @param [String] upload_id Unique Id of a resumable upload # - # @return [Google::Apis::StorageV1::Object, Integer] - # The object metadata on success, or 0 if request is not completed. + # @return [Google::Apis::StorageV1::Object, Boolean] + # The object metadata on success, or 'false' request is not completed. # # @example # require "google/cloud/storage" @@ -1438,8 +1438,8 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil # Delete resumable upload # @param [String] upload_id Unique Id of a resumable upload # - # @return [Boolean,nil] Returns `true` if the resumable upload was deleted, - # 'nil' if the request is not completed. + # @return [Boolean] Returns `true` if the resumable upload was deleted, + # 'false' if the request is not completed. # # @example # require "google/cloud/storage" diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index dc2180a8319c..db974e8c6484 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1455,6 +1455,25 @@ end end + it "returns false if restart_resumable_upload is provided wrong upload_id" do + new_file_name = random_file_path + upload_id = "wrong_TEST_ID" + + Tempfile.open ["google-cloud", ".txt"] do |tmpfile| + tmpfile.write "Hello world" + tmpfile.rewind + mock = Minitest::Mock.new + expected_return_value = false + mock.expect :restart_resumable_upload, expected_return_value, + [bucket.name, tmpfile, upload_id], + **resumable_upload_args(options: {}) + bucket.service.mocked_service = mock + returned_value= bucket.restart_resumable_upload tmpfile, upload_id + assert_equal expected_return_value, returned_value + mock.verify + end + end + it "deletes a resumable upload with upload_id" do upload_id = "TEST_ID" @@ -1470,6 +1489,20 @@ mock.verify end + it "returns false if delete_resumable_upload is provided wrong upload_id" do + upload_id = "wrong_TEST_ID" + + mock = Minitest::Mock.new + expected_return_value = false + mock.expect :delete_resumable_upload, expected_return_value, + [bucket.name, upload_id], + **resumable_upload_args(options: {}) + bucket.service.mocked_service = mock + returned_value = bucket.delete_resumable_upload upload_id + assert_equal expected_return_value, returned_value + mock.verify + end + it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError From d14e180ed456348cafdbd423d2ff0080ed781d0e Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 12 Sep 2025 17:44:34 +0530 Subject: [PATCH 33/33] Update bucket_test.rb --- google-cloud-storage/test/google/cloud/storage/bucket_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb index db974e8c6484..cc45518f2903 100644 --- a/google-cloud-storage/test/google/cloud/storage/bucket_test.rb +++ b/google-cloud-storage/test/google/cloud/storage/bucket_test.rb @@ -1504,7 +1504,6 @@ end it "raises ArgumentError if upload_id is not provided to delete_resumable_upload" do - error = _ { bucket.delete_resumable_upload }.must_raise ArgumentError assert_match "wrong number of arguments", error.message end