Repository: googleapis/google-cloud-ruby (Ruby)

Issue:
Support setting custom endpoint/universe_domain when intialising through Service
#### Environment details

  - OS: Any
  - Ruby version: Any
  - Gem name and version: `google-cloud-storage` `>=1.49.0` 

#### Steps to reproduce

  1. Initialise Storage client using Google::Cloud::Storage::Service and set custom endpoint.
  2. The endpoint should ideally be custom endpoint but it's set to the default one.

#### Code example

```ruby
require "google/cloud/storage"
require "googleauth"

ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/keyfile"
ENV["GOOGLE_CLOUD_PROJECT"] = "<project_id>"

Google::Cloud::Storage.configure do |config|
  config.endpoint = "localhost:9000/"
end

# Dummy credentials
credentials = OpenStruct.new(client: OpenStruct.new(updater_proc: Proc.new {}))

# OR

# Actual credentials
credentials = Google::Auth::Credentials.new(ENV['GOOGLE_APPLICATION_CREDENTIALS'])

service = Google::Cloud::Storage::Service.new(ENV['GOOGLE_CLOUD_PROJECT'],credentials)

# Expected: service.service.root_url to be localhost:9000/
# Actual: service.service.root_url is storage.googleapis.com

```
Thanks!



Discussion:

Patch:
diff --git a/google-cloud-storage/lib/google/cloud/storage/service.rb b/google-cloud-storage/lib/google/cloud/storage/service.rb
index 867d52976b8a..f15ad5b0457c 100644
--- a/google-cloud-storage/lib/google/cloud/storage/service.rb
+++ b/google-cloud-storage/lib/google/cloud/storage/service.rb
@@ -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"
@@ -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
@@ -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


Test patch:
diff --git a/google-cloud-storage/test/google/cloud/storage/project_test.rb b/google-cloud-storage/test/google/cloud/storage/project_test.rb
index 753b9fa1f484..f80393677de6 100644
--- a/google-cloud-storage/test/google/cloud/storage/project_test.rb
+++ b/google-cloud-storage/test/google/cloud/storage/project_test.rb
@@ -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"
@@ -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,