[PATCH aggregator] Added validation for Cloud Account Login Credentials
by Martyn Taylor
From: martyntaylor <mtaylor(a)redhat.com>
---
src/app/controllers/provider_controller.rb | 18 ++++++++++++++++++
src/app/models/cloud_account.rb | 19 ++++++++++++++++++-
src/features/step_definitions/pool_steps.rb | 2 +-
.../controllers/cloud_accounts_controller_spec.rb | 9 +++++++--
src/spec/factories/cloud_account.rb | 4 ++--
src/spec/models/cloud_account_spec.rb | 16 ++++++++++++++++
src/spec/models/instance_spec.rb | 12 +++++++-----
src/spec/spec_helper.rb | 1 +
8 files changed, 70 insertions(+), 11 deletions(-)
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb
index 7a4cefc..4955979 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -67,4 +67,22 @@ class ProviderController < ApplicationController
require_privilege(Privilege::PROVIDER_VIEW, @provider)
end
+ def new_account
+ @provider = Provider.find(params[:id])
+ require_privilege(Privilege::ACCOUNT_MODIFY, @provider)
+ end
+
+ def create_account
+ require_privilege(Privilege::ACCOUNT_MODIFY)
+ @acct = CloudAccount.find_or_create(params[:cloud_account])
+ @provider = Provider.find(params[:cloud_account][:provider_id])
+ if @acct.save
+ @provider.cloud_accounts << @acct
+ redirect_to :action => 'accounts', :id => @provider.id
+ else
+ flash[:notice] = @acct.errors.full_messages[0]
+ redirect_to :action => 'new_account', :id => @provider.id
+ end
+ end
+
end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 9b8458d..aaf980e 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -1,4 +1,4 @@
-#
+ #
# Copyright (C) 2009 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
@@ -127,4 +127,21 @@ class CloudAccount < ActiveRecord::Base
end
end
+ protected
+ def validate
+ errors.add_to_base("Login Credentials are Invalid for this Provider") unless valid_credentials?
+ end
+
+ private
+ def valid_credentials?
+ begin
+ deltacloud = DeltaCloud.new(username, password, provider.url)
+ #TODO This should be replaced by a DeltaCloud.test_credentials type method once/if it is implemented in the API
+ deltacloud.instances
+ rescue Exception => e
+ return false
+ end
+ return true
+ end
+
end
diff --git a/src/features/step_definitions/pool_steps.rb b/src/features/step_definitions/pool_steps.rb
index bd764ae..3d97da6 100644
--- a/src/features/step_definitions/pool_steps.rb
+++ b/src/features/step_definitions/pool_steps.rb
@@ -15,7 +15,7 @@ Given /^the Pool has the following Hardware Profiles:$/ do |table|
end
Given /^the Pool has the following Realms named "([^\"]*)"$/ do |names|
- @cloud_account = Factory :cloud_account
+ @cloud_account = Factory :mock_cloud_account
@provider = @cloud_account.provider
names.split(", ").each do |name|
diff --git a/src/spec/controllers/cloud_accounts_controller_spec.rb b/src/spec/controllers/cloud_accounts_controller_spec.rb
index d3e0f18..7a82a7a 100644
--- a/src/spec/controllers/cloud_accounts_controller_spec.rb
+++ b/src/spec/controllers/cloud_accounts_controller_spec.rb
@@ -23,9 +23,14 @@ describe CloudAccountsController do
it "should allow users with account modify permission to update a cloud account" do
UserSession.create(@admin)
- post :update, :cloud_account => { :id => @cloud_account.id, :password => 'foobar' }
+
+ @cloud_account.password = "foobar"
+ @cloud_account.stub!(:valid_credentials).and_return(true)
+ @cloud_account.save
+
+ post :update, :cloud_account => { :id => @cloud_account.id, :password => 'mockpassword' }
response.should redirect_to("http://test.host/provider/accounts/#{@provider.id}")
- CloudAccount.find((a)cloud_account.id).password.should == "foobar"
+ CloudAccount.find((a)cloud_account.id).password.should == "mockpassword"
end
it "should allow users with account modify permission to delete a cloud account" do
diff --git a/src/spec/factories/cloud_account.rb b/src/spec/factories/cloud_account.rb
index f494b52..b623b43 100644
--- a/src/spec/factories/cloud_account.rb
+++ b/src/spec/factories/cloud_account.rb
@@ -5,7 +5,7 @@ Factory.define :cloud_account do |f|
end
Factory.define :mock_cloud_account, :parent => :cloud_account do |f|
- f.sequence(:username) { |n| "testMockUser#(n)" }
- f.password "testMockPassword"
+ f.username "mockuser"
+ f.password "mockpassword"
f.provider { |p| p.association(:mock_provider) }
end
diff --git a/src/spec/models/cloud_account_spec.rb b/src/spec/models/cloud_account_spec.rb
index 0afe5a3..89fdf27 100644
--- a/src/spec/models/cloud_account_spec.rb
+++ b/src/spec/models/cloud_account_spec.rb
@@ -18,4 +18,20 @@ describe CloudAccount do
@cloud_account.destroy
CloudAccount.find(:first, :conditions => ['id = ?', @cloud_account.id]).should be_nil
end
+
+ it "should check the validitiy of the cloud account login credentials" do
+ mock_provider = Factory :mock_provider
+
+ invalid_cloud_account = Factory.build(:cloud_account, :username => "wrong_username", :password => "wrong_password", :provider => mock_provider)
+ invalid_cloud_account.should_not be_valid
+
+ valid_cloud_account = Factory.build(:mock_cloud_account, :provider => mock_provider)
+ valid_cloud_account.should be_valid
+ end
+
+ it "should fail to create a cloud account if the provider credentials are invalid" do
+ cloud_account = Factory.build(:mock_cloud_account, :password => "wrong_password")
+ cloud_account.save.should == false
+ end
+
end
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 84cd234..afdc0e0 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -90,12 +90,14 @@ describe Instance do
provider = Factory.build(:mock_provider2)
provider.stub!(:connect).and_return(mock('DeltaCloud'))
provider.save!
- cloud_account = CloudAccount.new(:provider_id => provider.id,
- :username => 'john doe',
- :password => 'asdf')
+
+ cloud_account = Factory.build(:cloud_account, :provider => provider,
+ :username => 'john doe',
+ :password => 'asdf')
+ cloud_account.stub!(:valid_credentials?).and_return(true)
cloud_account.save!
- @instance = Factory.create(:instance,
- :cloud_account_id => cloud_account.id)
+
+ @instance = Factory.create(:instance, :cloud_account => cloud_account)
@instance.front_end_realm.should eql('mock2:john doe')
realm = Factory.create(:realm, :name => 'a realm',
diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb
index 5181389..3323348 100644
--- a/src/spec/spec_helper.rb
+++ b/src/spec/spec_helper.rb
@@ -21,6 +21,7 @@ Spec::Runner.configure do |config|
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+
# == Fixtures
#
# You can declare fixtures for each example_group like this:
--
1.6.6.1
14 years, 1 month
[PATCH 1/2] First round of 'remove pool-account association' changes.
by Scott Seago
This removes the pool-account model association and related view/controller logic.
You will need to rebuild your database after applying this patch. In order to create instances, you will need the follow-on patch that handles the required changes for import/mapping of images and hardware profiles, since these will no longer be pool-specific.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/controllers/cloud_accounts_controller.rb | 27 ---------------
src/app/controllers/pool_controller.rb | 29 ----------------
src/app/models/cloud_account.rb | 3 +-
src/app/models/pool.rb | 19 ++++++++--
src/app/models/pool_account.rb | 29 ----------------
src/app/models/privilege.rb | 16 ++-------
src/app/models/provider.rb | 2 +-
src/app/models/quota.rb | 2 +-
src/app/services/registration_service.rb | 2 +-
src/app/views/pool/accounts.html.erb | 30 ----------------
src/app/views/pool/accounts_for_pool.html.erb | 36 --------------------
src/app/views/pool/show.html.erb | 1 -
.../20090801045212_create_cloud_accounts.rb | 1 +
src/db/migrate/20090803141507_create_pools.rb | 1 -
src/db/migrate/20091008153046_create_privileges.rb | 2 +-
src/db/migrate/20091008153058_create_roles.rb | 22 +-----------
.../migrate/20091215182906_create_pool_accounts.rb | 36 --------------------
src/spec/controllers/pool_controller_spec.rb | 9 -----
src/spec/controllers/users_controller_spec.rb | 2 +-
src/spec/fixtures/roles.yml | 16 ++------
src/test/fixtures/roles.yml | 10 ++----
21 files changed, 33 insertions(+), 262 deletions(-)
delete mode 100644 src/app/models/pool_account.rb
delete mode 100644 src/app/views/pool/accounts.html.erb
delete mode 100644 src/app/views/pool/accounts_for_pool.html.erb
delete mode 100644 src/db/migrate/20091215182906_create_pool_accounts.rb
diff --git a/src/app/controllers/cloud_accounts_controller.rb b/src/app/controllers/cloud_accounts_controller.rb
index 05e024e..ea0a34a 100644
--- a/src/app/controllers/cloud_accounts_controller.rb
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -31,14 +31,6 @@ class CloudAccountsController < ApplicationController
}
end
- def new_from_pool
- @pool = Pool.find(params[:pool_id])
- require_privilege(Privilege::ACCOUNT_ADD,@pool)
- @cloud_account = CloudAccount.new
- @providers = Provider.all
- end
-
-
def create
@cloud_account = CloudAccount.new(params[:cloud_account])
@provider = Provider.find(params[:provider][:id])
@@ -47,25 +39,6 @@ class CloudAccountsController < ApplicationController
@cloud_account.save!
end
- def create_from_pool
- @pool = Pool.find(params[:pool][:id])
- require_privilege(Privilege::ACCOUNT_ADD,@pool)
- Pool.transaction do
- @cloud_account = CloudAccount.new(params[:cloud_account])
- @provider = Provider.find(params[:provider][:id])
- @cloud_account.provider = @provider
- @cloud_account.save!
- @pool.cloud_accounts << @cloud_account unless @pool.cloud_accounts.map{|x| x.id}.include?((a)cloud_account.id)
- @pool.save!
- @pool.populate_realms_and_images([@cloud_account])
- perm = Permission.new(:user => @current_user,
- :role => Role.find_by_name("Account Administrator"),
- :permission_object => @cloud_account)
- perm.save!
- end
- redirect_to :controller => "pool", :action => 'show', :id => @pool.id
- end
-
def edit
@cloud_account = CloudAccount.find(params[:id])
@provider = @cloud_account.provider
diff --git a/src/app/controllers/pool_controller.rb b/src/app/controllers/pool_controller.rb
index cf751e0..2ae0988 100644
--- a/src/app/controllers/pool_controller.rb
+++ b/src/app/controllers/pool_controller.rb
@@ -44,11 +44,6 @@ class PoolController < ApplicationController
require_privilege(Privilege::POOL_VIEW, @pool)
end
- def accounts
- @pool = Pool.find(params[:id])
- require_privilege(Privilege::ACCOUNT_VIEW,@pool)
- end
-
def realms
@pool = Pool.find(params[:id])
@realm_names = @pool.realms
@@ -58,7 +53,6 @@ class PoolController < ApplicationController
def new
require_privilege(Privilege::POOL_MODIFY)
@pool = Pool.new
- @account = CloudAccount.new
end
def create
@@ -89,27 +83,4 @@ class PoolController < ApplicationController
require_privilege(Privilege::POOL_VIEW, @pool)
end
- def accounts_for_pool
- @pool = Pool.find(params[:pool_id])
- require_privilege(Privilege::ACCOUNT_VIEW,@pool)
- @cloud_accounts = []
- all_accounts = CloudAccount.list_for_user(@current_user, Privilege::ACCOUNT_ADD)
- all_accounts.each {|account|
- @cloud_accounts << account unless @pool.cloud_accounts.map{|x| x.id}.include?(account.id)
- }
- end
-
- def add_account
- @pool = Pool.find(params[:pool])
- @cloud_account = CloudAccount.find(params[:cloud_account])
- require_privilege(Privilege::ACCOUNT_ADD,@pool)
- require_privilege(Privilege::ACCOUNT_ADD,@cloud_account)
- Pool.transaction do
- @pool.cloud_accounts << @cloud_account unless @pool.cloud_accounts.map{|x| x.id}.include?((a)cloud_account.id)
- @pool.save!
- @pool.populate_realms_and_images([@cloud_account])
- end
- redirect_to :action => 'show', :id => @pool.id
- end
-
end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 1d6b3e9..f3dc317 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -22,8 +22,7 @@
class CloudAccount < ActiveRecord::Base
include PermissionedObject
belongs_to :provider
- has_many :pool_accounts, :dependent => :destroy
- has_many :pools, :through => :pool_accounts
+ belongs_to :quota
has_many :instances
# what form does the account quota take?
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index c97e03f..5b89a6b 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -21,10 +21,9 @@
class Pool < ActiveRecord::Base
include PermissionedObject
- has_many :pool_accounts, :dependent => :destroy
- has_many :cloud_accounts, :through => :pool_accounts
has_many :instances, :dependent => :destroy
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
+ belongs_to :quota
has_many :images, :dependent => :destroy
has_many :hardware_profiles, :dependent => :destroy
@@ -40,9 +39,20 @@ class Pool < ActiveRecord::Base
:include => [:role],
:order => "permissions.id ASC"
+ def cloud_accounts
+ accounts = []
+ instances.each do |instance|
+ if instance.cloud_account and !accounts.include?(instance.cloud_account)
+ accounts << instance.cloud_account
+ end
+ end
+ end
+
+ #FIXME: do we still allow explicit cloud/account choice via realm selection?
+ #FIXME: How is account list for realm defined without explicit pool-account relationship?
def realms
realm_list = []
- cloud_accounts.each do |cloud_account|
+ CloudAccount.all.each do |cloud_account|
prefix = cloud_account.account_prefix_for_realm
realm_list << prefix
cloud_account.provider.realms.each do |realm|
@@ -54,7 +64,8 @@ class Pool < ActiveRecord::Base
end
# FIXME: for already-mapped accounts, update rather than add new
- def populate_realms_and_images(accounts=cloud_accounts)
+ # FIXME: this needs to be revised to handle the removal of the account-pool association
+ def populate_realms_and_images(accounts=CloudAccount.all)
accounts.each do |cloud_account|
client = cloud_account.connect
realms = client.realms
diff --git a/src/app/models/pool_account.rb b/src/app/models/pool_account.rb
deleted file mode 100644
index 1bb5429..0000000
--- a/src/app/models/pool_account.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2010 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-class PoolAccount < ActiveRecord::Base
- belongs_to :cloud_account
- belongs_to :pool
- belongs_to :quota
-
- validates_presence_of :cloud_account_id
- validates_presence_of :pool_id
-
-end
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
index 9e085c4..0117c5c 100644
--- a/src/app/models/privilege.rb
+++ b/src/app/models/privilege.rb
@@ -43,26 +43,16 @@ class Privilege < ActiveRecord::Base
STATS_VIEW = "stats_view" # can view monitoring data for
# instances
- # to create(i.e. import) an account on a provider (but not added to
- # a pool) needs ACCOUNT_MODIFY on the provider.
- # to add a new provider account (i.e. import) to a pool needs
- # ACCOUNT_ADD on the pool
- # to add an existing provider account to a pool needs ACCOUNT_ADD
- # on the pool _and_ ACCOUNT_ADD on the account.
+ # to create(i.e. import) an account on a provider needs ACCOUNT_MODIFY on the
+ # provider.
ACCOUNT_MODIFY = "account_modify" # can create or modify cloud accounts
ACCOUNT_VIEW = "account_view" # can view cloud accounts
- ACCOUNT_ADD = "account_add" # can add an account to a pool
- # pool privileges normally checked at the provider level
- # (and at the account level for choosing which accounts are visible on the
- # new pool form), although
- # pool-specific overrides could be a future enhancement.
POOL_MODIFY = "pool_modify" # can create or modify a pool
POOL_VIEW = "pool_view" # can view a pool
# quota privileges normally checked at the pool or account level,
# depending on which quota level we're dealing with
- # (account level for cloud-imposed quota, pool level for aggregator quota)
QUOTA_MODIFY = "quota_modify" # can create or modify a quota
QUOTA_VIEW = "quota_view" # can view a quota
@@ -81,7 +71,7 @@ class Privilege < ActiveRecord::Base
FULL_PRIVILEGE_LIST = [PERM_SET, PERM_VIEW,
INSTANCE_MODIFY, INSTANCE_CONTROL, INSTANCE_VIEW,
STATS_VIEW,
- ACCOUNT_MODIFY, ACCOUNT_ADD, ACCOUNT_VIEW,
+ ACCOUNT_MODIFY, ACCOUNT_VIEW,
POOL_MODIFY, POOL_VIEW,
QUOTA_MODIFY, QUOTA_VIEW,
PROVIDER_MODIFY, PROVIDER_VIEW,
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index e45b8cc..4e4e3b7 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -66,7 +66,7 @@ class Provider < ActiveRecord::Base
end
def pools
- cloud_accounts.collect {|account| account.pools}.flatten
+ cloud_accounts.collect {|account| account.pools}.flatten.uniq
end
# TODO: implement or remove - this is meant to contain a hash of
diff --git a/src/app/models/quota.rb b/src/app/models/quota.rb
index 21205b5..23f9aee 100644
--- a/src/app/models/quota.rb
+++ b/src/app/models/quota.rb
@@ -21,5 +21,5 @@
class Quota < ActiveRecord::Base
has_one :pool
- has_one :pool_account
+ has_one :cloud_account
end
diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb
index e414c6a..b2de097 100644
--- a/src/app/services/registration_service.rb
+++ b/src/app/services/registration_service.rb
@@ -11,7 +11,7 @@ class RegistrationService
@user.save!
@pool = Pool.create!({ :name => @user.login, :owner => @user})
Permission.create!({:user => @user,
- :role => Role.find_by_name("Self-service Pool User"),
+ :role => Role.find_by_name("Instance Creator and User"),
:permission_object => @pool})
end
rescue
diff --git a/src/app/views/pool/accounts.html.erb b/src/app/views/pool/accounts.html.erb
deleted file mode 100644
index 96c4e2d..0000000
--- a/src/app/views/pool/accounts.html.erb
+++ /dev/null
@@ -1,30 +0,0 @@
-<% if @pool.cloud_accounts.size == 0 %>
-<h1>There are no accounts to display</h1>
-<% else %>
- <table>
- <thead>
- <tr>
- <th scope="col">Provider</th>
- <th scope="col">Username</th>
- <th scope="col">Actions</th>
- </tr>
- </thead>
- <tbody>
- <%(a)pool.cloud_accounts.each {|account| %>
- <tr>
- <td><%= account.provider.name %></td>
- <td><%= account.username %></td>
- <td>
- <%= link_to "User access",
- {:controller => "permissions",
- :action => "list",
- :cloud_account_id => account.id},
- :class=>"actionlink" if has_view_perms?(account) %>
- </td>
- </tr>
- <% } %>
- </tbody>
- </table>
-<% end %>
-<%= link_to "View/Add Existing Cloud Accounts", {:controller => "pool",:action => "accounts_for_pool", :pool_id => @pool}, :class=>"actionlink" %>
-<%= link_to "Add a New Cloud Account", {:controller => "cloud_accounts",:action => "new_from_pool", :pool_id => @pool}, :class=>"actionlink" %><br/>
diff --git a/src/app/views/pool/accounts_for_pool.html.erb b/src/app/views/pool/accounts_for_pool.html.erb
deleted file mode 100644
index fc4e5cb..0000000
--- a/src/app/views/pool/accounts_for_pool.html.erb
+++ /dev/null
@@ -1,36 +0,0 @@
-<% if @pool.cloud_accounts.size > 0 %>
-<h1>These Cloud Accounts are already attached to this pool</h1>
-<table>
-<thead>
-<tr>
-<th scope="col">Provider Name</th>
-<th scope="col">Cloud Account User Name</th>
-</tr>
-<% @pool.cloud_accounts.each {|a| %>
-<tr>
-<td><%= a.provider.name %></td>
-<td><%= a.username %></td>
-</tr>
-<% } %>
-</table>
-<% end %>
-
-<% if @cloud_accounts.size == 0 %>
-<h1>There are no existing Cloud Accounts available to add</h1>
-<% else %>
-<h1>These Cloud Accounts are available to add</h1>
-<table>
-<thead>
-<tr>
-<th scope="col">Provider Name</th>
-<th scope="col">Cloud Account User Name</th>
-</tr>
-<% @cloud_accounts.each {|a| %>
-<tr>
-<td><%= a.provider.name %></td>
-<td><%= a.username %> <%= link_to "Add this account", {:controller=> "pool",
- :action => "add_account", :pool => @pool, :cloud_account => a}, :class => "actionlink" %></td>
-</tr>
-<% } %>
-</table>
-<% end %>
diff --git a/src/app/views/pool/show.html.erb b/src/app/views/pool/show.html.erb
index 015f13b..ef637f1 100644
--- a/src/app/views/pool/show.html.erb
+++ b/src/app/views/pool/show.html.erb
@@ -36,7 +36,6 @@
</table>
<% end %>
<%= link_to "Add a new instance", {:controller => "instance", :action => "new", :id => @pool}, :class=>"actionlink"%>
-<%= link_to "Back end Accounts", {:action => "accounts", :id => @pool.id}, :class=>"actionlink"%>
<%= link_to "User access", {:controller => "permissions", :action => "list", :pool_id => @pool.id}, :class=>"actionlink" if has_view_perms? %>
<%= link_to "Hardware Profiles", {:action => "hardware_profiles", :id => @pool.id}, :class=>"actionlink"%>
<%=link_to "View Images", {:controller => "pool", :action => "images", :id => @pool}, :class => "actionlink" %>
diff --git a/src/db/migrate/20090801045212_create_cloud_accounts.rb b/src/db/migrate/20090801045212_create_cloud_accounts.rb
index 933ef0e..316de87 100644
--- a/src/db/migrate/20090801045212_create_cloud_accounts.rb
+++ b/src/db/migrate/20090801045212_create_cloud_accounts.rb
@@ -25,6 +25,7 @@ class CreateCloudAccounts < ActiveRecord::Migration
t.string :username, :null => false
t.string :password, :null => false
t.integer :provider_id, :null => false
+ t.integer :quota_id
t.integer :lock_version, :default => 0
t.timestamps
end
diff --git a/src/db/migrate/20090803141507_create_pools.rb b/src/db/migrate/20090803141507_create_pools.rb
index 5552869..f35021a 100644
--- a/src/db/migrate/20090803141507_create_pools.rb
+++ b/src/db/migrate/20090803141507_create_pools.rb
@@ -33,7 +33,6 @@ class CreatePools < ActiveRecord::Migration
end
def self.down
- drop_table :cloud_accounts_pools
drop_table :pools
end
end
diff --git a/src/db/migrate/20091008153046_create_privileges.rb b/src/db/migrate/20091008153046_create_privileges.rb
index 12d94c6..74932b0 100644
--- a/src/db/migrate/20091008153046_create_privileges.rb
+++ b/src/db/migrate/20091008153046_create_privileges.rb
@@ -30,7 +30,7 @@ class CreatePrivileges < ActiveRecord::Migration
privileges = ["set_perms", "view_perms",
"instance_modify", "instance_control", "instance_view",
"stats_view",
- "account_modify", "account_add", "account_view",
+ "account_modify", "account_view",
"pool_modify", "pool_view",
"quota_modify", "quota_view",
"provider_modify", "provider_view",
diff --git a/src/db/migrate/20091008153058_create_roles.rb b/src/db/migrate/20091008153058_create_roles.rb
index 5234c90..74cf519 100644
--- a/src/db/migrate/20091008153058_create_roles.rb
+++ b/src/db/migrate/20091008153058_create_roles.rb
@@ -53,18 +53,6 @@ class CreateRoles < ActiveRecord::Migration
"quota_view",
"set_perms",
"view_perms"]},
- "Self-service Pool User" =>
- {:role_scope => "Pool",
- :privileges => ["instance_control",
- "instance_view",
- "pool_view",
- "stats_view",
- "instance_modify",
- "quota_view",
- "set_perms",
- "view_perms",
- "account_view",
- "account_add"]},
"Pool Creator" =>
{:role_scope => "Provider",
:privileges => ["provider_view",
@@ -78,9 +66,6 @@ class CreateRoles < ActiveRecord::Migration
"pool_view",
"quota_view",
"quota_modify",
- "account_view",
- "account_add",
- "account_modify",
"set_perms",
"view_perms"]},
"Provider Administrator" =>
@@ -93,13 +78,9 @@ class CreateRoles < ActiveRecord::Migration
{:role_scope => "CloudAccount",
:privileges => ["set_perms",
"view_perms",
+ "stats_view",
"account_view",
- "account_add",
"account_modify"]},
- "Account User" =>
- {:role_scope => "CloudAccount",
- :privileges => ["account_view",
- "account_add"]},
"Account Viewer" =>
{:role_scope => "CloudAccount",
:privileges => ["account_view"]},
@@ -112,7 +93,6 @@ class CreateRoles < ActiveRecord::Migration
:privileges => ["provider_modify",
"provider_view",
"account_modify",
- "account_add",
"account_view",
"user_modify",
"user_view",
diff --git a/src/db/migrate/20091215182906_create_pool_accounts.rb b/src/db/migrate/20091215182906_create_pool_accounts.rb
deleted file mode 100644
index aa71c09..0000000
--- a/src/db/migrate/20091215182906_create_pool_accounts.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class CreatePoolAccounts < ActiveRecord::Migration
- def self.up
- create_table :pool_accounts do |t|
- t.integer :cloud_account_id, :null => false
- t.integer :pool_id, :null => false
- t.integer :quota_id
- t.integer :lock_version, :default => 0
- t.timestamps
- end
- end
-
- def self.down
- drop_table :pool_accounts
- end
-end
diff --git a/src/spec/controllers/pool_controller_spec.rb b/src/spec/controllers/pool_controller_spec.rb
index 7917ed3..3daed93 100644
--- a/src/spec/controllers/pool_controller_spec.rb
+++ b/src/spec/controllers/pool_controller_spec.rb
@@ -39,15 +39,6 @@ describe PoolController do
response.should render_template("hardware_profiles")
end
- it "should get cloud accounts" do
- @pool = Factory :tpool
- UserSession.create(@admin)
- get :accounts, :id => @pool.id
- response.should be_success
- response.should render_template("accounts")
- @pool.should_not == nil
- end
-
it "should provide ui to view realms" do
UserSession.create(@admin)
pool = Factory :tpool
diff --git a/src/spec/controllers/users_controller_spec.rb b/src/spec/controllers/users_controller_spec.rb
index 1189294..231a533 100644
--- a/src/spec/controllers/users_controller_spec.rb
+++ b/src/spec/controllers/users_controller_spec.rb
@@ -35,7 +35,7 @@ describe UsersController do
p.name.should == "tuser2"
p.permissions.size.should == 1
p.permissions.any? {
- |perm| perm.role.name.eql?('Self-service Pool User')
+ |perm| perm.role.name.eql?('Instance Creator and User')
}.should be_true
id = User.find(:first, :conditions => ['login = ?', "tuser2"]).id
response.should redirect_to("http://test.host/users/show/#{id}")
diff --git a/src/spec/fixtures/roles.yml b/src/spec/fixtures/roles.yml
index 5c72efb..9a4c550 100644
--- a/src/spec/fixtures/roles.yml
+++ b/src/spec/fixtures/roles.yml
@@ -17,10 +17,6 @@ instance_creator_and_user:
name: Instance Creator and User
scope: Pool
privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms
-self_service_pool_user:
- name: Self-service Pool User
- scope: Pool
- privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_add
pool_creator:
name: Pool Creator
scope: Provider
@@ -28,19 +24,15 @@ pool_creator:
pool_administrator:
name: Pool Administrator
scope: Provider
- privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_add, account_view, stats_view, set_perms, view_perms
+ privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, stats_view, set_perms, view_perms
provider_administrator:
name: Provider Administrator
scope: Provider
- privileges: provider_modify, provider_view, account_modify, account_view
+ privileges: provider_modify, provider_view, account_modify, account_view, stats_view
account_administrator:
name: Account Administrator
scope: CloudAccount
- privileges: account_modify, account_view, stats_view, set_perms, view_perms, account_add
-account_user:
- name: Account User
- scope: CloudAccount
- privileges: account_view, account_add
+ privileges: account_modify, account_view, stats_view, set_perms, view_perms
account_viewer:
name: Account Viewer
scope: CloudAccount
@@ -52,4 +44,4 @@ provider_creator:
administrator:
name: Administrator
scope: BasePermissionObject
- privileges: provider_modify, provider_view, account_modify, account_add, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view
+ privileges: provider_modify, provider_view, account_modify, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view
diff --git a/src/test/fixtures/roles.yml b/src/test/fixtures/roles.yml
index 5ec515b..99df4b7 100644
--- a/src/test/fixtures/roles.yml
+++ b/src/test/fixtures/roles.yml
@@ -17,10 +17,6 @@ instance_creator_and_user:
name: Instance Creator and User
scope: Pool
privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms
-self_service_pool_user:
- name: Self-service Pool User
- scope: Pool
- privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_modify
pool_creator:
name: Pool Creator
scope: Provider
@@ -28,19 +24,19 @@ pool_creator:
pool_administrator:
name: Pool Administrator
scope: Provider
- privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_view, stats_view, set_perms, view_perms
+ privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, stats_view, set_perms, view_perms
account_administrator:
name: Account Administrator
scope: CloudAccount
privileges: account_modify, account_view, stats_view, set_perms, view_perms
-account_user:
+account_viewer:
name: Account User
scope: CloudAccount
privileges: account_view
provider_administrator:
name: Provider Administrator
scope: BasePermissionObject
- privileges: provider_modify, provider_view, stats_view
+ privileges: provider_modify, provider_view, account_modify, account_view, stats_view
site_administrator:
name: Site Administrator
scope: BasePermissionObject
--
1.6.2.5
14 years, 1 month
[PATCH] Added Validation for Login Credentials on Cloud Account
by Martyn Taylor
From: martyntaylor <mtaylor(a)redhat.com>
---
src/app/controllers/provider_controller.rb | 11 ++++++++---
src/app/models/cloud_account.rb | 17 +++++++++++++++++
src/features/step_definitions/pool_steps.rb | 2 +-
.../controllers/cloud_accounts_controller_spec.rb | 11 +++++++++--
src/spec/factories/cloud_account.rb | 4 ++--
src/spec/models/cloud_account_spec.rb | 11 +++++++++++
6 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb
index 23b5ba0..092054c 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -76,8 +76,13 @@ class ProviderController < ApplicationController
require_privilege(Privilege::ACCOUNT_MODIFY)
@acct = CloudAccount.find_or_create(params[:cloud_account])
@provider = Provider.find(params[:cloud_account][:provider_id])
- @provider.cloud_accounts << @acct
- redirect_to :action => 'accounts', :id => @provider.id
+ if @acct.save
+ @provider.cloud_accounts << @acct
+ redirect_to :action => 'accounts', :id => @provider.id
+ else
+ flash[:notice] = @acct.errors.full_messages[0]
+ redirect_to :action => 'new_account', :id => @provider.id
+ end
end
-end
+end
\ No newline at end of file
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 1d6b3e9..29677c1 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -67,4 +67,21 @@ class CloudAccount < ActiveRecord::Base
def name
username
end
+
+ protected
+ def validate
+ errors.add_to_base("Login Credentials are Invalid for this Provider") unless valid_credentials?
+ end
+
+ private
+ def valid_credentials?
+ begin
+ deltacloud = DeltaCloud.new(username, password, provider.url)
+ #TODO This should be replaced by a DeltaCloud.test_credentials type method once/if it is implemented in the API
+ deltacloud.instances
+ rescue Exception => e
+ return false
+ end
+ return true
+ end
end
diff --git a/src/features/step_definitions/pool_steps.rb b/src/features/step_definitions/pool_steps.rb
index bd764ae..3d97da6 100644
--- a/src/features/step_definitions/pool_steps.rb
+++ b/src/features/step_definitions/pool_steps.rb
@@ -15,7 +15,7 @@ Given /^the Pool has the following Hardware Profiles:$/ do |table|
end
Given /^the Pool has the following Realms named "([^\"]*)"$/ do |names|
- @cloud_account = Factory :cloud_account
+ @cloud_account = Factory :mock_cloud_account
@provider = @cloud_account.provider
names.split(", ").each do |name|
diff --git a/src/spec/controllers/cloud_accounts_controller_spec.rb b/src/spec/controllers/cloud_accounts_controller_spec.rb
index f1d4a0d..c5e520e 100644
--- a/src/spec/controllers/cloud_accounts_controller_spec.rb
+++ b/src/spec/controllers/cloud_accounts_controller_spec.rb
@@ -23,9 +23,9 @@ describe CloudAccountsController do
it "should allow users with account modify permission to update a cloud account" do
UserSession.create(@admin)
- post :update, :cloud_account => { :id => @cloud_account.id, :password => 'foobar' }
+ post :update, :cloud_account => { :id => @cloud_account.id, :password => 'mockpassword' }
response.should redirect_to("http://test.host/provider/accounts/#{@provider.id}")
- CloudAccount.find((a)cloud_account.id).password.should == "foobar"
+ CloudAccount.find((a)cloud_account.id).password.should == "mockpassword"
end
it "should allow users with account modify permission to delete a cloud account" do
@@ -48,4 +48,11 @@ describe CloudAccountsController do
response.should_not be_success
end
+ it "should fail to create a cloud account if the provider credentials are invalid" do
+ cloud_account = Factory.build(:mock_cloud_account)
+ cloud_account.stub!(:valid_credentials?).and_return(false)
+ cloud_account.save.should == false
+ end
+
+
end
diff --git a/src/spec/factories/cloud_account.rb b/src/spec/factories/cloud_account.rb
index f494b52..b623b43 100644
--- a/src/spec/factories/cloud_account.rb
+++ b/src/spec/factories/cloud_account.rb
@@ -5,7 +5,7 @@ Factory.define :cloud_account do |f|
end
Factory.define :mock_cloud_account, :parent => :cloud_account do |f|
- f.sequence(:username) { |n| "testMockUser#(n)" }
- f.password "testMockPassword"
+ f.username "mockuser"
+ f.password "mockpassword"
f.provider { |p| p.association(:mock_provider) }
end
diff --git a/src/spec/models/cloud_account_spec.rb b/src/spec/models/cloud_account_spec.rb
index 0afe5a3..ded33c2 100644
--- a/src/spec/models/cloud_account_spec.rb
+++ b/src/spec/models/cloud_account_spec.rb
@@ -18,4 +18,15 @@ describe CloudAccount do
@cloud_account.destroy
CloudAccount.find(:first, :conditions => ['id = ?', @cloud_account.id]).should be_nil
end
+
+ it "should check the validitiy of the cloud account login credentials" do
+ mock_provider = Factory :mock_provider
+
+ invalid_cloud_account = Factory.build(:cloud_account, :username => "wrong_username", :password => "wrong_password", :provider => mock_provider)
+ invalid_cloud_account.should_not be_valid
+
+ valid_cloud_account = Factory.build(:mock_cloud_account, :provider => mock_provider)
+ valid_cloud_account.should be_valid
+ end
+
end
--
1.6.6.1
14 years, 1 month
[PATCH] Fix up EC2 hardware profiles.
by Chris Lalancette
The hardware profiles listed in the EC2 driver were
needlessly different from the actual hardware profiles
that EC2 supports. In particular, they were using -
instead of . for name separators. Fix this, and also
add the m2.4xlarge hardware profile type.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 71 ++++++++++++----------
1 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 492a059..20f9365 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -26,53 +26,60 @@ class EC2Driver < Deltacloud::BaseDriver
feature :instances, :user_data
- define_hardware_profile('m1-small') do
- cpu 1
- memory 1.7 * 1024
- storage 160
- architecture 'i386'
+ define_hardware_profile('m1.small') do
+ cpu 1
+ memory 1.7 * 1024
+ storage 160
+ architecture 'i386'
end
- define_hardware_profile('m1-large') do
+ define_hardware_profile('m1.large') do
cpu 4
- memory 7.5 * 1024
- storage 850
- architecture 'x86_64'
+ memory 7.5 * 1024
+ storage 850
+ architecture 'x86_64'
end
- define_hardware_profile('m1-xlarge') do
+ define_hardware_profile('m1.xlarge') do
cpu 8
- memory 15 * 1024
- storage 1690
- architecture 'x86_64'
+ memory 15 * 1024
+ storage 1690
+ architecture 'x86_64'
end
- define_hardware_profile('c1-medium') do
+ define_hardware_profile('c1.medium') do
cpu 5
- memory 1.7 * 1024
- storage 350
- architecture 'i386'
+ memory 1.7 * 1024
+ storage 350
+ architecture 'i386'
end
- define_hardware_profile('c1-xlarge') do
- cpu 20
- memory 7 * 1024
- storage 1690
- architecture 'x86_64'
+ define_hardware_profile('c1.xlarge') do
+ cpu 20
+ memory 7 * 1024
+ storage 1690
+ architecture 'x86_64'
end
- define_hardware_profile('m2-xlarge') do
- cpu 6.5
- memory 17.1 * 1024
- storage 420
- architecture 'x86_64'
+ define_hardware_profile('m2.xlarge') do
+ cpu 6.5
+ memory 17.1 * 1024
+ storage 420
+ architecture 'x86_64'
end
- define_hardware_profile('m2-2xlarge') do
- cpu 13
- memory 34.2 * 1024
- storage 850
- architecture 'x86_64'
+ define_hardware_profile('m2.2xlarge') do
+ cpu 13
+ memory 34.2 * 1024
+ storage 850
+ architecture 'x86_64'
+ end
+
+ define_hardware_profile('m2.4xlarge') do
+ cpu 26
+ memory 68.4 * 1024
+ storage 1690
+ architecture 'x86_64'
end
define_instance_states do
--
1.6.6.1
14 years, 1 month
Repo clone script
by Martyn Taylor
Guys,
I've made some modifications to the script I sent round yesterday. Mainly from Jays Suggestions:
1. Now "Should" work on all versions of GIT (altho its not tested, please let me know)
2. As default will checkout all repos (aggregator, core and docs)
3. Can checkout multiple repos by adding -a -c -d etc...
Unfortunately tho, it is still a bash script and not ruby ;-) - sorry Jay
Still, same applies as before, all the hooks are activated as default, to unactivate (if there is such as word) a hook, set it as false at the top of the script. e.g. APPLY_PATCH=false
Regarding the .git/config files, I could add the ability to copy the config files from somewhere on your local box into the .git directory, and tell git to ignore it.
Or another idea might be to change the config files in the repo, so they're already setup when we check it out. "Not quite sure if this is suitable tho?"
Any problems let me know
Cheers
Martyn
14 years, 1 month
Re: [deltacloud-devel] [PATCH core 1/2] Added authentication features to EC2 and GoGrid drivers
by Michal Fojtik
On 12/05/10 16:37 -0700, David Lutterkort wrote:
>On Wed, 2010-05-12 at 14:26 +0200, mfojtik(a)redhat.com wrote:
>> ---
>> server/lib/deltacloud/base_driver/features.rb | 15 +++++++++++++++
>> server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 8 +++++++-
>> server/views/instances/new.html.haml | 12 +++++++++---
>> server/views/instances/show.html.haml | 5 +++++
>> server/views/instances/show.xml.haml | 3 +++
>> 5 files changed, 39 insertions(+), 4 deletions(-)
>
>You still have a bunch of authentification's in the code - to save
>people some typing, 'authn' is a widely used abbreviation for
>authentication. How about a s/authenti(fi)?cation/authn/ in those
>files ?
Yes, that's probably good idea ;-) I renamed those and pushed this patch
into master.
+ I added a 'login' element which surrounds instance credentials.
-- Michal
--
--------------------------------------------------------
Michal Fojtik, mfojtik(a)redhat.com, +420 532 294 4307
Ruby / Ruby On Rails Developer
Deltacloud API: http://deltacloud.org
--------------------------------------------------------
14 years, 1 month
Terremark vcloud express driver v0.2 - minor fixes
by marios@redhat.com
Latest version of terremark vcloud express driver - incorporates edits suggested by Lutter. This driver relies on latest fog gem (v.0.0.93 at time of writing). Unfortunately and as experienced over the last couple weeks fog is still prone to (major) changes so I will keep an eye on this to make sure nothing breaks. David/Michal can you please ack and push this as I don't have privileges for that (or not if there are problems... ;) )
--marios
14 years, 1 month
First draft: Adding network_services model to core API
by marios@redhat.com
This is a first draught of a "network_services" model for core API. A network service allows you to connect to a running instance; this will mean different things for different clouds... in ec2 this means setting up the firewall/security group to allow connections from a IP/range to a specific port, in terremark this means creating a new "node service".
At present a network service has a public IP address, public port, private IP address and port (of the instance) and a protocol (e.g. tcp/udp). The first patch is the terremark driver and the second adds the network_service as well as required haml and relevant bits of base_driver, server etc so you can see how this model works in the terremark case.
Please reply with any thoughts about how this model works/not for a given cloud so we can reformulate the model as appropriate.
--marios
14 years, 1 month