Reprioritize list of references for base URL

Always look for base_url and then session data before
falling back to auth_service information from the config.
This commit is contained in:
Mark Maglana 2013-10-08 12:05:15 -07:00
parent b221208a2a
commit 94e072ef29
1 changed files with 8 additions and 6 deletions

View File

@ -18,14 +18,16 @@ module Aviator
def base_url
if session_data[:auth_service] && session_data[:auth_service][:host_uri]
"#{ session_data[:auth_service][:host_uri] }/v2.0"
elsif session_data[:base_url]
if session_data[:base_url]
session_data[:base_url]
else
service_spec = session_data[:access][:serviceCatalog].find { |s| s[:type] == service.to_s }
raise Aviator::Service::MissingServiceEndpointError.new(service.to_s, self.class) unless service_spec
elsif service_spec = session_data[:access][:serviceCatalog].find { |s| s[:type] == service.to_s }
service_spec[:endpoints][0]["#{ endpoint_type }URL".to_sym]
elsif session_data[:auth_service] && session_data[:auth_service][:host_uri] && session_data[:auth_service][:api_version]
"#{ session_data[:auth_service][:host_uri] }/v2.0"
elsif session_data[:auth_service] && session_data[:auth_service][:host_uri]
session_data[:auth_service][:host_uri]
else
raise Aviator::Service::MissingServiceEndpointError.new(service.to_s, self.class)
end
end