Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL override not being used for API calls #126

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions app/models/manageiq/providers/cisco_intersight/manager_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ManageIQ::Providers::CiscoIntersight::ManagerMixin
extend ActiveSupport::Concern

DEFAULT_INTERSIGHT_URL = "https://intersight.com".freeze

def connect(options = {})
require 'intersight_client'
keyid = authentication_userid
Expand Down Expand Up @@ -73,7 +75,7 @@ def params_for_create
:id => "endpoints.default.url",
:name => "endpoints.default.url",
:label => _("Endpoint URL"),
:initialValue => "https://intersight.com",
:initialValue => DEFAULT_INTERSIGHT_URL,
:isRequired => true,
:validate => [{:type => "required"}]
},
Expand Down Expand Up @@ -142,17 +144,24 @@ 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
uri = URI.parse(url || DEFAULT_INTERSIGHT_URL)

if uri != URI.parse(DEFAULT_INTERSIGHT_URL)
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,15 +57,32 @@

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")

ems.connect
end

context "with a variation of the default url" do
let(:url) { "https://intersight.com:443/" }
let(:ems) do
FactoryBot.create(:ems_cisco_intersight_physical_infra, :auth).tap do |ems|
ems.default_endpoint.url = url
ems.default_endpoint.verify_ssl = OpenSSL::SSL::VERIFY_NONE
end
end

it "connects with the default server" do
expect(IntersightClient::Configuration).to receive(:new).and_yield(config_mock)
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")

ems.connect
end
end

context "with an alternate URL" do
let(:url) { "http://intersight.localdomain:8080" }
let(:ems) do
Expand All @@ -83,6 +96,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
Loading