From 15c861d8c01348741a6e0b4a5ec28ca9a776157a Mon Sep 17 00:00:00 2001 From: Nick Dower Date: Tue, 20 Feb 2024 16:47:13 +0100 Subject: [PATCH 1/2] fix(core): allow BaseService#root_url to be an Addressable::URI Follow up to #17131. Addresses #17894. --- google-apis-core/lib/google/apis/core/base_service.rb | 9 ++++++--- .../spec/google/apis/core/service_spec.rb | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 416a7d449f8..cfb6b7cab22 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -119,18 +119,21 @@ def universe_domain= new_ud end # Root URL (host/port) for the API - # @return [Addressable::URI] + # @return [Addressable::URI, String] attr_reader :root_url # Set the root URL. # If the given url includes a universe domain substitution, it is # resolved in the current universe domain # - # @param url_or_template [String] The URL, which can include a universe domain substitution + # @param url_or_template [Addressable::URI, String] The URL, which can include a universe domain substitution def root_url= url_or_template - if url_or_template.include? ENDPOINT_SUBSTITUTION + if url_or_template.is_a?(String) && url_or_template.include?(ENDPOINT_SUBSTITUTION) @root_url_template = url_or_template @root_url = url_or_template.gsub ENDPOINT_SUBSTITUTION, universe_domain + elsif url_or_template.is_a?(Addressable::URI) && url_or_template.to_s.include?(ENDPOINT_SUBSTITUTION) + @root_url_template = url_or_template.to_s + @root_url = Addressable::URI.parse(url_or_template.to_s.gsub(ENDPOINT_SUBSTITUTION, universe_domain)) else @root_url_template = nil @root_url = url_or_template diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index 7650c85c36e..c89ffd475b6 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -533,12 +533,23 @@ expect(service_ud.root_url).to eql "https://endpoint1.mydomain5.com/" end + it "should support setting root url to Addressable::URI" do + service_ud.root_url = Addressable::URI.parse("https://endpoint1.mydomain5.com/") + expect(service_ud.root_url).to be_a(Addressable::URI) + end + it "should support setting root url to a dynamic value" do service.universe_domain = "mydomain6.com" service.root_url = "https://endpoint2.$UNIVERSE_DOMAIN$/" expect(service.root_url).to eql "https://endpoint2.mydomain6.com/" end + it "should support setting root url to a dynamic Addressable::URI" do + service.universe_domain = "mydomain6.com" + service.root_url = Addressable::URI.parse("https://endpoint2.$UNIVERSE_DOMAIN$/") + expect(service.root_url).to eql Addressable::URI.parse("https://endpoint2.mydomain6.com/") + end + describe "#verify_universe_domain!" do it "should skip universe domain verification if credentials do not have them" do service_ud.authorization = "I have no universe domain" From e8e28c289c9a7818475cb620908948e0506565b5 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Fri, 23 Feb 2024 20:54:47 +0000 Subject: [PATCH 2/2] fix(core): Remove support for Addressable::URI with an endpoint substitution --- google-apis-core/lib/google/apis/core/base_service.rb | 3 --- google-apis-core/spec/google/apis/core/service_spec.rb | 6 ------ 2 files changed, 9 deletions(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index cfb6b7cab22..22ee6553ce4 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -131,9 +131,6 @@ def root_url= url_or_template if url_or_template.is_a?(String) && url_or_template.include?(ENDPOINT_SUBSTITUTION) @root_url_template = url_or_template @root_url = url_or_template.gsub ENDPOINT_SUBSTITUTION, universe_domain - elsif url_or_template.is_a?(Addressable::URI) && url_or_template.to_s.include?(ENDPOINT_SUBSTITUTION) - @root_url_template = url_or_template.to_s - @root_url = Addressable::URI.parse(url_or_template.to_s.gsub(ENDPOINT_SUBSTITUTION, universe_domain)) else @root_url_template = nil @root_url = url_or_template diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index c89ffd475b6..53167a12700 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -544,12 +544,6 @@ expect(service.root_url).to eql "https://endpoint2.mydomain6.com/" end - it "should support setting root url to a dynamic Addressable::URI" do - service.universe_domain = "mydomain6.com" - service.root_url = Addressable::URI.parse("https://endpoint2.$UNIVERSE_DOMAIN$/") - expect(service.root_url).to eql Addressable::URI.parse("https://endpoint2.mydomain6.com/") - end - describe "#verify_universe_domain!" do it "should skip universe domain verification if credentials do not have them" do service_ud.authorization = "I have no universe domain"