class Fog::Brightbox::Storage::AuthenticationRequest

Attributes

access_token[RW]
management_url[RW]
tenant[RW]
user[RW]

Public Class Methods

new(config) click to toggle source
# File lib/fog/brightbox/storage/authentication_request.rb, line 8
def initialize(config)
  @config = config
end

Public Instance Methods

authenticate() click to toggle source
# File lib/fog/brightbox/storage/authentication_request.rb, line 12
def authenticate
  response = authentication_request

  self.access_token = response.headers["X-Auth-Token"]
  self.management_url = response.headers["X-Server-Management-Url"] || response.headers["X-Storage-Url"]
  self
rescue Excon::Errors::Unauthorized => error
  raise Fog::Brightbox::Storage::AuthenticationRequired.slurp(error)
end

Private Instance Methods

auth_headers() click to toggle source
# File lib/fog/brightbox/storage/authentication_request.rb, line 36
def auth_headers
  if @config.user_credentials?
    {
      "X-Auth-User" => @config.username,
      "X-Auth-Key" => @config.password
    }
  else
    {
      "X-Auth-User" => @config.client_id,
      "X-Auth-Key" => @config.client_secret
    }
  end
end
authentication_request() click to toggle source
# File lib/fog/brightbox/storage/authentication_request.rb, line 24
def authentication_request
  authentication_url = URI.parse(@config.storage_url.to_s)
  connection = Fog::Core::Connection.new(authentication_url.to_s)
  request_settings = {
    :expects => [200, 204],
    :headers => auth_headers,
    :method => "GET",
    :path => "v1"
  }
  connection.request(request_settings)
end