Class: OpenStack::AuthV20
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #get_version_from_response(service, endpoint_type) ⇒ Object
-
#initialize(connection) ⇒ AuthV20
constructor
A new instance of AuthV20.
-
#parse_version_from_endpoint(endpoint) ⇒ Object
IN –> az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/46871569847393 OUT –> “1.1”.
Constructor Details
#initialize(connection) ⇒ AuthV20
Returns a new instance of AuthV20.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/openstack/connection.rb', line 375 def initialize(connection) tries = connection.retries time = 3 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 # use the ca_cert if were given one, and make sure we verify! if !connection.ca_cert.nil? server.ca_file = connection.ca_cert server.verify_mode = OpenSSL::SSL::VERIFY_PEER end # explicitly set the SSL version to use server.ssl_version = connection.ssl_version if !connection.ssl_version.nil? end server.start rescue puts "Can't connect to the server: #{tries} tries to reconnect" if connection.is_debug sleep time += 1 retry unless (tries -= 1) <= 0 raise OpenStack::Exception::Connection, "Unable to connect to #{server}" end @uri = String.new case connection.auth_method when "password" auth_data = JSON.generate({ "auth" => { "passwordCredentials" => { "username" => connection.authuser, "password" => connection.authkey }, connection.authtenant[:type] => connection.authtenant[:value]}}) when "rax-kskey" auth_data = JSON.generate({"auth" => {"RAX-KSKEY:apiKeyCredentials" => {"username" => connection.authuser, "apiKey" => connection.authkey}}}) when "key" auth_data = JSON.generate({"auth" => { "apiAccessKeyCredentials" => {"accessKey" => connection.authuser, "secretKey" => connection.authkey}, connection.authtenant[:type] => connection.authtenant[:value]}}) else raise Exception::InvalidArgument, "Unrecognized auth method #{connection.auth_method}" end response = server.post(connection.auth_path.chomp("/")+"/tokens", auth_data, {'Content-Type' => 'application/json'}) if (response.code =~ /^20./) resp_data=JSON.parse(response.body) connection.authtoken = resp_data['access']['token']['id'] implemented_services = resp_data["access"]["serviceCatalog"].inject([]){|res, current| res << current["type"] ;res} raise OpenStack::Exception::NotImplemented.new("The requested service: \"#{connection.service_type}\" is not present " + "in the returned service catalogue.", 501, "#{resp_data["access"]["serviceCatalog"]}") unless implemented_services.include?(connection.service_type) resp_data['access']['serviceCatalog'].each do |service| service["endpoints"].each do |endpoint| connection.regions_list[endpoint["region"]] ||= [] connection.regions_list[endpoint["region"]] << {:service=>service["type"], :versionId => endpoint["versionId"]} end if connection.service_name check_service_name = connection.service_name else check_service_name = service['name'] end if service['type'] == connection.service_type and service['name'] == check_service_name endpoints = service["endpoints"] if connection.region endpoints.each do |ep| if ep["region"] and ep["region"].upcase == connection.region.upcase @uri = URI.parse(ep[connection.endpoint_type]) end end else @uri = URI.parse(endpoints[0][connection.endpoint_type]) end if @uri == "" raise OpenStack::Exception::Authentication, "No API endpoint for region #{connection.region}" else if @version #already got one version of endpoints current_version = get_version_from_response(service,connection.endpoint_type) if @version.to_f > current_version.to_f next end end #grab version to check next time round for multi-version deployments @version = get_version_from_response(service,connection.endpoint_type) connection.service_host = @uri.host connection.service_path = @uri.path connection.service_port = @uri.port connection.service_scheme = @uri.scheme connection.authok = true end end end else connection.authtoken = false raise OpenStack::Exception::Authentication, "Authentication failed with response code #{response.code}" end server.finish if server.started? end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
373 374 375 |
# File 'lib/openstack/connection.rb', line 373 def uri @uri end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
374 375 376 |
# File 'lib/openstack/connection.rb', line 374 def version @version end |
Instance Method Details
#get_version_from_response(service, endpoint_type) ⇒ Object
470 471 472 |
# File 'lib/openstack/connection.rb', line 470 def get_version_from_response(service,endpoint_type) service["endpoints"].first["versionId"] || parse_version_from_endpoint(service["endpoints"].first[endpoint_type]) end |
#parse_version_from_endpoint(endpoint) ⇒ Object
IN –> az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/46871569847393 OUT –> “1.1”
476 477 478 |
# File 'lib/openstack/connection.rb', line 476 def parse_version_from_endpoint(endpoint) endpoint.match(/\/v(\d).(\d)/).to_s.sub("/v", "") end |