Skip to content

Commit

Permalink
Fix URL override not being used for API calls
Browse files Browse the repository at this point in the history
The openapi generated `ApiClient`/`Configuration` classes have a way to
to pass scheme, host, and base_path but `Configuration#server_settings`
is used unless `Configuration#server_index` is set to `nil`.
  • Loading branch information
agrare committed Dec 9, 2024
1 parent 997421c commit 2742924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 11 additions & 6 deletions app/models/manageiq/providers/cisco_intersight/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,22 @@ def verify_provider_connection(api_client)
def raw_connect(url, verify_ssl, key_id, key)
require "intersight_client"

uri = URI.parse(url || "https://intersight.com")
scheme = uri.scheme
host = "#{uri.host}:#{uri.port}"

verify_ssl = OpenSSL::SSL::VERIFY_PEER if verify_ssl.nil?
verify_ssl = verify_ssl == OpenSSL::SSL::VERIFY_PEER

IntersightClient::ApiClient.new(
IntersightClient::Configuration.new do |config|
config.scheme = scheme
config.host = host
if url && url != "https://intersight.com"
uri = URI.parse(url)
host = uri.host
host += ":#{uri.port}" if uri.port.present?

config.scheme = uri.scheme || "https"
config.host = host
config.base_path = uri.path if uri.path.present?
config.server_index = nil
end

config.verify_ssl = verify_ssl
config.api_key = key
config.api_key_id = key_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
context ".raw_connect" do
it "connects with key_id and secret key" do
expect(IntersightClient::Configuration).to receive(:new).and_yield(config_mock)
expect(config_mock).to receive(:scheme=).with("https")
expect(config_mock).to receive(:host=).with("intersight.com:443")
expect(config_mock).to receive(:verify_ssl=).with(true)
expect(config_mock).to receive(:api_key_id=).with("keyid")
expect(config_mock).to receive(:api_key=).with("secretkey")
Expand All @@ -26,8 +24,6 @@

it "defaults to url=https://intersight.com and verify_ssl=true" do
expect(IntersightClient::Configuration).to receive(:new).and_yield(config_mock)
expect(config_mock).to receive(:scheme=).with("https")
expect(config_mock).to receive(:host=).with("intersight.com:443")
expect(config_mock).to receive(:verify_ssl=).with(true)
expect(config_mock).to receive(:api_key_id=).with("keyid")
expect(config_mock).to receive(:api_key=).with("secretkey")
Expand Down Expand Up @@ -61,8 +57,6 @@

it "connects with key_id and secret key" do
expect(IntersightClient::Configuration).to receive(:new).and_yield(config_mock)
expect(config_mock).to receive(:scheme=).with("https")
expect(config_mock).to receive(:host=).with("intersight.com:443")
expect(config_mock).to receive(:verify_ssl=).with(true)
expect(config_mock).to receive(:api_key_id=).with("keyid")
expect(config_mock).to receive(:api_key=).with("secretkey")
Expand All @@ -83,6 +77,7 @@
expect(IntersightClient::Configuration).to receive(:new).and_yield(config_mock)
expect(config_mock).to receive(:scheme=).with("http")
expect(config_mock).to receive(:host=).with("intersight.localdomain:8080")
expect(config_mock).to receive(:server_index=).with(nil)
expect(config_mock).to receive(:verify_ssl=).with(false)
expect(config_mock).to receive(:api_key_id=).with("keyid")
expect(config_mock).to receive(:api_key=).with("secretkey")
Expand Down

0 comments on commit 2742924

Please sign in to comment.