You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/02/23 14:56:00 UTC

[PATCH core 4/7] CIMI: Added '/driver' route to CIMI client

From: Michal Fojtik <mf...@redhat.com>

This route will handle driver and provider change.
User is now able to select the DC driver which will be used
to Client<->CIMI server communication. Driver and provider
configuration will be stored in session object and overide
the default basic HTTP auth credentials.

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 clients/cimi/app.rb |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/clients/cimi/app.rb b/clients/cimi/app.rb
index a8c3459..510fd33 100644
--- a/clients/cimi/app.rb
+++ b/clients/cimi/app.rb
@@ -28,6 +28,13 @@ module CIMI::Frontend
     use CIMI::Frontend::VolumeConfiguration
     use CIMI::Frontend::VolumeImage
     use CIMI::Frontend::Volume
+    use Rack::Session::Cookie
+
+    helpers CIMI::Frontend::Helper
+
+    before do
+      @_flash, session[:_flash] = session[:_flash], nil if session[:_flash]
+    end
 
     configure do
       enable :logging
@@ -45,6 +52,28 @@ module CIMI::Frontend
     get '/cimi' do
       redirect '/cimi/cloudEntryPoint'
     end
+
+    get '/driver' do
+      unless params[:driver]
+        flash[:error] = "You need to choose driver"
+        redirect(back) && return
+      end
+      session[:provider] = param_if_not_nil(params, :provider)
+      session[:driver] = param_if_not_nil(params, :driver)
+      session[:username] = param_if_not_nil(params, :username)
+      session[:password] = param_if_not_nil(params, :password)
+      flash[:success] = "You're now using #{session[:driver].to_s.upcase}"
+      redirect back
+    end
+
+    private
+
+    def param_if_not_nil(params, param)
+      return false if params[param].nil?
+      return false if params[param].strip.empty?
+      return params[param].strip
+    end
+
   end
 
 end
-- 
1.7.9.1