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

Add urls for provider endpoints #18207

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 12 additions & 2 deletions app/models/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Endpoint < ApplicationRecord
after_create :endpoint_created
after_destroy :endpoint_destroyed

delegate :to_s, :to => :url, :allow_nil => true

def endpoint_created
resource.endpoint_created(role) if resource.respond_to?(:endpoint_created)
end
Expand Down Expand Up @@ -54,8 +52,20 @@ def ssl_cert_store
nil # use system defaults
end

def to_s
(url || generate_uri).to_s
end

private

def generate_uri
return unless resource.kind_of?(ExtManagementSystem)
host = hostname || ipaddress || resource.hostname
path = ["", resource.try(:api_version) || api_version, ""].compact.join("/")
query = {:verify_ssl => verify_ssl?, :security_protocol => security_protocol }.delete_blanks.to_query
URI::Generic.new(resource.emstype, nil, host, port, nil, path, nil, query, nil)
end

def resolve_verify_ssl_value(val)
case val
when true then OpenSSL::SSL::VERIFY_PEER
Expand Down
12 changes: 9 additions & 3 deletions spec/models/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,19 @@
end

context "to_s" do
it "returns the url if set" do
it "returns the url with url set" do
endpoint.url = 'https://www.foo.bar'
expect(endpoint.to_s).to eql('https://www.foo.bar')
end

it "returns a blank string if the url is not set" do
expect(endpoint.to_s).to eql('')
it "returns a blank string with no ems and no url" do
expect(endpoint.to_s).to eql("")
end

it "returns a custom url with vmware uri set" do
ems = FactoryGirl.create(:ems_vmware, :hostname => 'example.com', :port => 443, :api_version => 5.5)
endpoint = FactoryGirl.create(:endpoint, :resource => ems)
expect(endpoint.to_s).to eql("vmwarews://example.com:443/5.5/?verify_ssl=true")
end
end
end