incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r961982 - in /incubator/deltacloud/trunk/framework: app/controllers/ app/helpers/ app/views/credentials/ app/views/root/ config/ lib/drivers/
Date Thu, 08 Jul 2010 23:14:35 GMT
Author: lutter
Date: Thu Jul  8 23:14:34 2010
New Revision: 961982

URL: http://svn.apache.org/viewvc?rev=961982&view=rev
Log:
Move to pure HTTP auth for pass-through authorization.  Remove all sembelance of sessions.

Removed:
    incubator/deltacloud/trunk/framework/app/controllers/credentials_controller.rb
    incubator/deltacloud/trunk/framework/app/helpers/credentials_helper.rb
    incubator/deltacloud/trunk/framework/app/views/credentials/edit.html.erb
    incubator/deltacloud/trunk/framework/app/views/credentials/show.html.erb
Modified:
    incubator/deltacloud/trunk/framework/app/controllers/accounts_controller.rb
    incubator/deltacloud/trunk/framework/app/controllers/application_controller.rb
    incubator/deltacloud/trunk/framework/app/controllers/images_controller.rb
    incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb
    incubator/deltacloud/trunk/framework/app/views/root/index.html.erb
    incubator/deltacloud/trunk/framework/config/routes.rb
    incubator/deltacloud/trunk/framework/lib/drivers/ec2.rb

Modified: incubator/deltacloud/trunk/framework/app/controllers/accounts_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/controllers/accounts_controller.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/controllers/accounts_controller.rb (original)
+++ incubator/deltacloud/trunk/framework/app/controllers/accounts_controller.rb Thu Jul  8
23:14:34 2010
@@ -4,7 +4,6 @@ load 'drivers/ec2.rb'
 class AccountsController < ApplicationController
 
   include DriverHelper
-  include CredentialsHelper
 
   def index
     @accounts = driver.accounts( credentials )

Modified: incubator/deltacloud/trunk/framework/app/controllers/application_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/controllers/application_controller.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/controllers/application_controller.rb (original)
+++ incubator/deltacloud/trunk/framework/app/controllers/application_controller.rb Thu Jul
 8 23:14:34 2010
@@ -8,7 +8,14 @@ class ApplicationController < ActionCont
   # Scrub sensitive parameters from your log
   # filter_parameter_logging :password
 
-  before_filter do |controller|
-    controller.session[:credentials] ||= {}
+
+  def credentials
+    creds = {}
+    authenticate_with_http_basic do |name,password|
+      creds[:name]     = name
+      creds[:password] = password
+    end
+    creds
   end
+
 end

Modified: incubator/deltacloud/trunk/framework/app/controllers/images_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/controllers/images_controller.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/controllers/images_controller.rb (original)
+++ incubator/deltacloud/trunk/framework/app/controllers/images_controller.rb Thu Jul  8 23:14:34
2010
@@ -5,7 +5,17 @@ load 'drivers/ec2.rb'
 class ImagesController < ApplicationController
 
   include DriverHelper
-  include CredentialsHelper
+
+  around_filter :catch_auth
+
+  def catch_auth
+    begin
+      yield
+    rescue Drivers::AuthException => e
+      authenticate_or_request_with_http_basic() do |n,p|
+      end
+    end
+  end
 
   def index
     @images = driver.images( credentials, [ 'ami-015db968', 'ami-015dba68' ])

Modified: incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb (original)
+++ incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb Thu Jul 
8 23:14:34 2010
@@ -6,7 +6,6 @@ require 'ostruct'
 class InstancesController < ApplicationController
 
   include DriverHelper
-  include CredentialsHelper
 
   def index
     @instances = driver.instances( credentials )

Modified: incubator/deltacloud/trunk/framework/app/views/root/index.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/root/index.html.erb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/root/index.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/root/index.html.erb Thu Jul  8 23:14:34
2010
@@ -2,7 +2,6 @@
 <h1>&#x3B4;-cloud-framework</h1>
 
 <ul>
-  <li><%= link_to 'Credentials', credentials_url %></li>
   <li><%= link_to 'Images',      images_url %></li>
   <li><%= link_to 'Instances',   instances_url %></li>
 </ul>

Modified: incubator/deltacloud/trunk/framework/config/routes.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/config/routes.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/config/routes.rb (original)
+++ incubator/deltacloud/trunk/framework/config/routes.rb Thu Jul  8 23:14:34 2010
@@ -14,10 +14,6 @@ ActionController::Routing::Routes.draw d
 
   map.resources :accounts
 
-  #####
-
-  map.resource :credentials
-
 
   #####
 

Modified: incubator/deltacloud/trunk/framework/lib/drivers/ec2.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/lib/drivers/ec2.rb?rev=961982&r1=961981&r2=961982&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/lib/drivers/ec2.rb (original)
+++ incubator/deltacloud/trunk/framework/lib/drivers/ec2.rb Thu Jul  8 23:14:34 2010
@@ -1,21 +1,25 @@
 
 module Drivers
 
+  class AuthException < Exception
+  end
+
   class EC2
 
-    def credentials_definition()
-      return [ 
-        { 
-          :name=>:access_key,
-          :type=>:string,
-          :required=>true,
-        },
-        {
-          :name=>:secret_access_key,
-          :type=>:string,
-          :required=>true,
-        }
-      ]
+    def safely(&block) 
+      begin
+        block.call
+      rescue RightAws::AwsError => e
+        if ( e.include?( /SignatureDoesNotMatch/ ) )
+          raise AuthException.new
+        elsif ( e.include?( /InvalidClientTokenId/ ) )
+          raise AuthException.new
+        else
+          e.errors.each do |error|
+            puts "ERROR #{error.inspect}"
+          end
+        end
+      end
     end
 
     def images(credentials, *ids)
@@ -31,9 +35,11 @@ module Drivers
 
     def image(credentials, id)
       ec2 = new_client(credentials)
-      ec2_images = ec2.describe_images(id)
-      return nil if ec2_images.empty?
-      convert_image( ec2_images.first )
+      safely do
+        ec2_images = ec2.describe_images(id)
+        return nil if ec2_images.empty?
+        convert_image( ec2_images.first )
+      end
     end
 
     def instances(credentials, *ids)
@@ -109,7 +115,10 @@ module Drivers
     private
 
     def new_client(credentials)
-      RightAws::Ec2.new(credentials[:access_key], credentials[:secret_access_key], :cache=>false
)
+      if ( credentials[:name].nil? || credentials[:password].nil? || credentials[:name] ==
'' || credentials[:password] == '' ) 
+        raise AuthException.new
+      end
+      RightAws::Ec2.new(credentials[:name], credentials[:password], :cache=>false )
     end
 
     def convert_image(ec2_image)



Mime
View raw message