deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH] Adds 'valid_credentials?' method for digital_ocean driver - DTACLOUD-480
Date Tue, 26 Feb 2013 16:50:04 GMT
From: marios <marios@redhat.com>

https://issues.apache.org/jira/browse/DTACLOUD-480

Signed-off-by: marios <marios@redhat.com>
---
 .../drivers/digitalocean/digitalocean_driver.rb         | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb b/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
index 2868e93..7c6143f 100644
--- a/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
+++ b/server/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb
@@ -169,6 +169,10 @@ module Deltacloud
 
         exceptions do
 
+          on (/ERROR Unable to verify credentials.*/) do
+            status 401
+          end
+
           on(/InternalServerError/) do
             status 502
           end
@@ -183,6 +187,17 @@ module Deltacloud
 
         end
 
+        def valid_credentials?(credentials)
+          begin
+            hardware_profile_ids(credentials)
+          rescue  Deltacloud::Exceptions::AuthenticationFailure
+            return false
+          rescue => e
+            safely { raise e }
+          end
+          true
+        end
+
         private
 
         class Client
@@ -204,7 +219,7 @@ module Deltacloud
             json_result = JSON::parse(result)
             if json_result['status'] != 'OK'
               p result
-              error_message = json_result['error_message'] || json_result['status']
+              error_message = json_result['error_message'] || "#{json_result['status']} #{json_result['description']}"
               raise error_message
             end
             json_result
-- 
1.7.11.7


Mime
View raw message