Sha256: 2506aea863d425b9190cc31ada405ab8bd43e7d78050508b8add43d72388f71d

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

module CloudFiles
  class Authentication
    # See COPYING for license information.
    # Copyright (c) 2009, Rackspace US, Inc.
    
    # Performs an authentication to the Cloud Files servers.  Opens a new HTTP connection to the API server,
    # sends the credentials, and looks for a successful authentication.  If it succeeds, it sets the cdmmgmthost,
    # cdmmgmtpath, storagehost, storagepath, authtoken, and authok variables on the connection.  If it fails, it raises
    # an AuthenticationException.
    #
    # Should probably never be called directly.
    def initialize(connection)
      path = '/auth'
      hdrhash = { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey }
      begin
        server = Net::HTTP.new('api.mosso.com',443)
        server.use_ssl = true
        server.verify_mode = OpenSSL::SSL::VERIFY_NONE
        server.start
      rescue
        raise ConnectionException, "Unable to connect to #{server}"
      end
      response = server.get(path,hdrhash)
      if (response.code == "204")
        connection.cdnmgmthost = URI.parse(response["x-cdn-management-url"]).host
        connection.cdnmgmtpath = URI.parse(response["x-cdn-management-url"]).path
        connection.storagehost = URI.parse(response["x-storage-url"]).host
        connection.storagepath = URI.parse(response["x-storage-url"]).path
        connection.authtoken = response["x-auth-token"]
        connection.authok = true
      else
        connection.authtoken = false
        raise AuthenticationException, "Authentication failed"
      end
      server.finish
    end
  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
briancollins-cloudfiles-1.3.0.1 lib/cloudfiles/authentication.rb
jmstacey-ruby-cloudfiles-1.3.2 lib/cloudfiles/authentication.rb
jmstacey-ruby-cloudfiles-1.3.3 lib/cloudfiles/authentication.rb
rackspace-cloudfiles-1.3.0.2 lib/cloudfiles/authentication.rb
rackspace-cloudfiles-1.3.0.3 lib/cloudfiles/authentication.rb
rackspace-cloudfiles-1.3.0.5 lib/cloudfiles/authentication.rb
rackspace-cloudfiles-1.3.0.6 lib/cloudfiles/authentication.rb
rackspace-cloudfiles-1.3.0.7 lib/cloudfiles/authentication.rb
tikhon-cloudfiles-1.3.0 lib/cloudfiles/authentication.rb