class OpenStack::AuthV10

Public Class Methods

new(connection) click to toggle source
# File lib/openstack/connection.rb, line 313
def initialize(connection)
  hdrhash = { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey }
  begin
    server = Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new(connection.auth_host, connection.auth_port)
    if connection.auth_scheme == "https"
      server.use_ssl = true
      server.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    server.start
  rescue
    raise OpenStack::Exception::Connection, "Unable to connect to #{server}"
  end
  response = server.get(connection.auth_path, hdrhash)
  if (response.code =~ %r^20./)
    connection.authtoken = response["x-auth-token"]
    case connection.service_type
      when "compute"
        uri = URI.parse(response["x-server-management-url"])
      when "object-store"
        uri = URI.parse(response["x-storage-url"])
    end
    raise OpenStack::Exception::Authentication, "Unexpected Response from  #{connection.auth_host} - couldn't get service URLs: \"x-server-management-url\" is: #{response["x-server-management-url"]} and \"x-storage-url\" is: #{response["x-storage-url"]}"  if (uri.host.nil? || uri.host=="")
    connection.service_host = uri.host
    connection.service_path = uri.path
    connection.service_port = uri.port
    connection.service_scheme = uri.scheme
    connection.authok = true
  else
    connection.authok = false
    raise OpenStack::Exception::Authentication, "Authentication failed with response code #{response.code}"
  end
  server.finish
end