Sha256: 5de4693b67875e674e09a4b0ecc64c3012620e96d9fd3fb11d867aa7eca98efe

Contents?: true

Size: 1.43 KB

Versions: 21

Compression:

Stored size: 1.43 KB

Contents

module Fog
  module Brightbox
    class Storage
      class AuthenticationRequest
        attr_accessor :access_token, :management_url
        attr_accessor :user, :tenant

        def initialize(config)
          @config = config
        end

        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

        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

        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
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
fog-brightbox-1.10.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.9.1 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.9.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.8.2 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.8.1 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.8.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.7.3 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.7.2 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.7.1 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.7.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.6.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.5.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.5.0.rc1 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.4.2 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.4.1 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.4.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.3.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.2.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.1.0 lib/fog/brightbox/storage/authentication_request.rb
fog-brightbox-1.0.0 lib/fog/brightbox/storage/authentication_request.rb