incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r995823 - in /incubator/deltacloud/trunk: .gitignore client/lib/deltacloud.rb server/server.rb
Date Fri, 10 Sep 2010 15:19:35 GMT
Author: mfojtik
Date: Fri Sep 10 15:19:33 2010
New Revision: 995823

URL: http://svn.apache.org/viewvc?rev=995823&view=rev
Log:
Added validate_credentials? support to client and server

Modified:
    incubator/deltacloud/trunk/.gitignore
    incubator/deltacloud/trunk/client/lib/deltacloud.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/.gitignore?rev=995823&r1=995822&r2=995823&view=diff
==============================================================================
--- incubator/deltacloud/trunk/.gitignore (original)
+++ incubator/deltacloud/trunk/.gitignore Fri Sep 10 15:19:33 2010
@@ -1 +1 @@
-*.swp
+*.sw*

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=995823&r1=995822&r2=995823&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Fri Sep 10 15:19:33 2010
@@ -33,6 +33,22 @@ module DeltaCloud
     API.new(user_name, password, api_url, &block)
   end
 
+  # Check given credentials if their are valid against
+  # backend cloud provider
+  #
+  # @param [String, user_name] API user name
+  # @param [String, password] API password
+  # @param [String, user_name] API URL (eg. http://localhost:3001/api)
+  # @return [true|false]
+  def self.valid_credentials?(user_name, password, api_url)
+    api=API.new(user_name, password, api_url)
+    result = false
+    api.request(:get, '', :force_auth => '1') do |response|
+      result = true if response.code.eql?(200)
+    end
+    return result
+  end
+
   # Return a API driver for specified URL
   #
   # @param [String, url] API URL (eg. http://localhost:3001/api)

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=995823&r1=995822&r2=995823&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Fri Sep 10 15:19:33 2010
@@ -42,6 +42,9 @@ get '/' do redirect url_for('/api'); end
 
 get '/api\/?' do
     @version = 0.1
+    if params[:force_auth]
+      return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
+    end
     respond_to do |format|
         format.xml { haml :"api/show" }
         format.json do



Mime
View raw message