Skip to content

Commit

Permalink
Add urls for provider endpoints
Browse files Browse the repository at this point in the history
This is just for completeness and probably won't be used by
provider code.
  • Loading branch information
kbrock committed Nov 15, 2018
1 parent ed18040 commit 5a9b49a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
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

0 comments on commit 5a9b49a

Please sign in to comment.