@@ -336,6 +336,20 @@ def fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_p
336336 return PagedResults . new ( self , max : max , items : items , cache : cache , response_page_token : response_page_token , &block )
337337 end
338338
339+ # Verify that the universe domain setting matches the universe domain
340+ # in the credentials, if present.
341+ #
342+ # @raise [Google::Apis::UniverseDomainError] if there is a mismatch
343+ def verify_universe_domain!
344+ auth = authorization
345+ auth_universe_domain = auth . universe_domain if auth . respond_to? :universe_domain
346+ if auth_universe_domain && auth_universe_domain != universe_domain
347+ raise UniverseDomainError ,
348+ "Universe domain is #{ universe_domain } but credentials are in #{ auth_universe_domain } "
349+ end
350+ true
351+ end
352+
339353 protected
340354
341355 # Create a new upload command.
@@ -348,6 +362,7 @@ def fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_p
348362 # Request-specific options
349363 # @return [Google::Apis::Core::UploadCommand]
350364 def make_upload_command ( method , path , options )
365+ verify_universe_domain!
351366 template = Addressable ::Template . new ( root_url + upload_path + path )
352367 if batch?
353368 command = MultipartUploadCommand . new ( method , template , client_version : client_version )
@@ -372,6 +387,7 @@ def make_upload_command(method, path, options)
372387 # Request-specific options
373388 # @return [Google::Apis::Core::StorageUploadCommand]
374389 def make_storage_upload_command ( method , path , options )
390+ verify_universe_domain!
375391 template = Addressable ::Template . new ( root_url + upload_path + path )
376392 command = StorageUploadCommand . new ( method , template , client_version : client_version )
377393 command . options = request_options . merge ( options )
@@ -389,6 +405,7 @@ def make_storage_upload_command(method, path, options)
389405 # Request-specific options
390406 # @return [Google::Apis::Core::DownloadCommand]
391407 def make_download_command ( method , path , options )
408+ verify_universe_domain!
392409 template = Addressable ::Template . new ( root_url + base_path + path )
393410 command = DownloadCommand . new ( method , template , client_version : client_version )
394411 command . options = request_options . merge ( options )
@@ -408,6 +425,7 @@ def make_download_command(method, path, options)
408425 # Request-specific options
409426 # @return [Google::Apis::Core::StorageDownloadCommand]
410427 def make_storage_download_command ( method , path , options )
428+ verify_universe_domain!
411429 template = Addressable ::Template . new ( root_url + base_path + path )
412430 command = StorageDownloadCommand . new ( method , template , client_version : client_version )
413431 command . options = request_options . merge ( options )
@@ -426,6 +444,7 @@ def make_storage_download_command(method, path, options)
426444 # Request-specific options
427445 # @return [Google::Apis::Core::DownloadCommand]
428446 def make_simple_command ( method , path , options )
447+ verify_universe_domain!
429448 full_path =
430449 if path . start_with? "/"
431450 path [ 1 ..-1 ]
0 commit comments