Class: CloudFiles::Authentication
- Inherits:
-
Object
- Object
- CloudFiles::Authentication
- Defined in:
- lib/cloudfiles/authentication.rb
Instance Method Summary collapse
-
#initialize(connection) ⇒ Authentication
constructor
Performs an authentication to the Cloud Files servers.
Constructor Details
#initialize(connection) ⇒ Authentication
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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cloudfiles/authentication.rb', line 12 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.cdnmgmtport = URI.parse(response["x-cdn-management-url"]).port connection.cdnmgmtscheme = URI.parse(response["x-cdn-management-url"]).scheme connection.storagehost = URI.parse(response["x-storage-url"]).host connection.storagepath = URI.parse(response["x-storage-url"]).path connection.storageport = URI.parse(response["x-storage-url"]).port connection.storagescheme = URI.parse(response["x-storage-url"]).scheme connection.authtoken = response["x-auth-token"] connection.authok = true else connection.authtoken = false raise AuthenticationException, "Authentication failed" end server.finish end |