Skip to content

Commit

Permalink
fix(storage): Set configured univer_domain and endpoint when initiali…
Browse files Browse the repository at this point in the history
…zing through Service (#25665)
  • Loading branch information
bajajneha27 committed Apr 5, 2024
1 parent 28b3bd1 commit 8bcb121
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion google-cloud-storage/lib/google/cloud/storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

require "google/cloud/storage/version"
require "google/apis/storage_v1"
require "google/cloud/config"
require "digest"
require "mini_mime"
require "pathname"
Expand Down Expand Up @@ -49,6 +50,7 @@ def initialize project, credentials, retries: 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
host ||= Google::Cloud::Storage.configure.endpoint
@project = project
@credentials = credentials
@service = API::StorageService.new
Expand All @@ -73,7 +75,7 @@ def initialize project, credentials, retries: nil,
@service.request_options.upload_chunk_size = upload_chunk_size if upload_chunk_size
@service.authorization = @credentials.client if @credentials
@service.root_url = host if host
@service.universe_domain = universe_domain
@service.universe_domain = universe_domain || Google::Cloud::Storage.configure.universe_domain
begin
@service.verify_universe_domain!
rescue Google::Apis::UniverseDomainError => e
Expand Down
22 changes: 22 additions & 0 deletions google-cloud-storage/test/google/cloud/storage/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def creds.is_a? target
creds
end

after do
Google::Cloud.configure.reset!
end

it "defaults to the correct endpoint and universe domain" do
service = Google::Cloud::Storage::Service.new "my-project", default_credentials
_(service.universe_domain).must_equal "googleapis.com"
Expand Down Expand Up @@ -102,6 +106,24 @@ def creds.is_a? target
end.must_raise Google::Cloud::Error
end

it "supports setting a universe domain via configuration" do
Google::Cloud::Storage.configure do |config|
config.universe_domain = "mydomain4.com"
end
service = Google::Cloud::Storage::Service.new "my-project", default_credentials
_(service.universe_domain).must_equal "mydomain4.com"
_(service.service.root_url).must_equal "https://storage.mydomain4.com/"
end

it "supports setting an endpoint via configuration" do
Google::Cloud::Storage.configure do |config|
config.endpoint = "https://storage.mydomain5.com/"
end
service = Google::Cloud::Storage::Service.new "my-project", default_credentials
_(service.universe_domain).must_equal "googleapis.com"
_(service.service.root_url).must_equal "https://storage.mydomain5.com/"
end

it "adds custom headers to the request options" do
headers = {
"x-goog-1" => 1,
Expand Down

0 comments on commit 8bcb121

Please sign in to comment.