Skip to content

Commit 176c8ca

Browse files
author
Jillian Tullo
committed
wip
1 parent c93c91b commit 176c8ca

File tree

2 files changed

+68
-29
lines changed

2 files changed

+68
-29
lines changed

app/controllers/mixins/ems_common_angular.rb

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,34 @@ def update_ems_button_save
5656
end
5757

5858
def update_ems_button_validate
59-
ems_type = model.model_from_emstype(params[:emstype])
59+
result, details = realtime_authentication_check
60+
render_validation_result(result, details)
61+
end
62+
63+
def realtime_authentication_check(verify_ems = nil)
64+
verify_ems ||= find_record_with_rbac(model, params[:id])
65+
set_ems_record_vars(verify_ems, :validate)
6066
@in_a_form = true
67+
verify_ems.authentication_check(params[:cred_type], :save => false, :database => params[:metrics_database_name])
68+
end
6169

62-
result, error = queue_authentication_check(ems_type)
70+
def create_ems_button_validate
71+
@in_a_form = true
72+
# TODO: queue authentication checks for all providers, not just cloud
73+
result, details = if params[:controller] == "ems_cloud"
74+
queue_authentication_check
75+
else
76+
ems = model.model_from_emstype(params[:emstype]).new
77+
realtime_authentication_check(ems)
78+
end
79+
render_validation_result(result, details)
80+
end
6381

82+
def render_validation_result(result, details)
6483
if result
6584
add_flash(_("Credential validation was successful"))
6685
else
67-
add_flash(_("Credential validation was not successful: %{details}") % {:details => error}, :error)
86+
add_flash(_("Credential validation was not successful: %{details}") % {:details => details}, :error)
6887
end
6988

7089
render :json => {:message => @flash_array.last(1)[0][:message], :level => @flash_array.last(1)[0][:level]}
@@ -75,12 +94,14 @@ def create
7594

7695
case params[:button]
7796
when "add" then create_ems_button_add
78-
when "validate" then update_ems_button_validate
97+
when "validate" then create_ems_button_validate
7998
when "cancel" then create_ems_button_cancel
8099
end
81100
end
82101

83-
def queue_authentication_check(ems_type)
102+
def queue_authentication_check
103+
ems_type = model.model_from_emstype(params[:emstype])
104+
84105
task_opts = {
85106
:action => "Validate EMS Provider Credentials",
86107
:userid => session[:userid]
@@ -108,17 +129,19 @@ def queue_authentication_check(ems_type)
108129
end
109130

110131
def get_task_args(ems)
111-
if ems == ManageIQ::Providers::Openstack::CloudManager
112-
auth_url = ems.class.auth_url(params[:default_hostname], params[:default_api_port])
113-
[params[:default_userid], params[:default_password], auth_url]
114-
elsif ems == ManageIQ::Providers::Amazon::CloudManager
115-
[params[:default_userid], params[:default_password], :EC2, params[:provider_region], true]
116-
elsif ems == ManageIQ::Providers::Azure::CloudManager
117-
[params[:default_userid], params[:default_password], params[:azure_tenant_id], params[:subscription], params[:proxy_uri], params[:provider_region]]
118-
elsif ems == ManageIQ::Providers::Vmware::CloudManager
119-
[params[:default_hostname], params[:default_api_port], params[:default_userid], params[:default_password], true]
120-
elsif ems == ManageIQ::Providers::Google::CloudManager
121-
[params[:project], params[:service_account], {:service => "compute"}]
132+
user, password = params[:default_userid], MiqPassword.encrypt(params[:default_password])
133+
case
134+
when ems == ManageIQ::Providers::Openstack::CloudManager
135+
auth_url = ems.auth_url(params[:default_hostname], params[:default_api_port])
136+
[user, password, auth_url]
137+
when ems == ManageIQ::Providers::Amazon::CloudManager
138+
[user, password, :EC2, params[:provider_region], nil, true]
139+
when ems == ManageIQ::Providers::Azure::CloudManager
140+
[user, password, params[:azure_tenant_id], params[:subscription], params[:proxy_uri], params[:provider_region]]
141+
when ems == ManageIQ::Providers::Vmware::CloudManager
142+
[params[:default_hostname], params[:default_api_port], user, password, true]
143+
when ems == ManageIQ::Providers::Google::CloudManager
144+
[params[:project], params[:service_account], {:service => "compute"}]
122145
end
123146
end
124147

spec/controllers/ems_cloud_controller_spec.rb

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,28 +290,44 @@
290290

291291
context "#update_ems_button_validate" do
292292
let(:mocked_ems) { double(ManageIQ::Providers::Openstack::CloudManager, :id => 1) }
293-
it "calls authentication_check with save = false if validation is done for an existing record" do
293+
294+
it "calls authentication_check with save = false" do
294295
allow(controller).to receive(:set_ems_record_vars)
295296
allow(controller).to receive(:render)
296-
controller.instance_variable_set(:@_params,
297-
:button => "validate",
298-
:id => mocked_ems.id,
299-
:cred_type => "default")
297+
allow(controller).to receive(:find_record_with_rbac).and_return(mocked_ems)
298+
controller.instance_variable_set(:@_params, :button => "validate", :id => mocked_ems.id, :cred_type => "default")
299+
300300
expect(mocked_ems).to receive(:authentication_check).with("default", hash_including(:save => false))
301-
controller.send(:update_ems_button_validate, mocked_ems)
301+
controller.send(:update_ems_button_validate)
302302
end
303+
end
304+
305+
context "#create_ems_button_validate" do
306+
let(:mocked_infra_class) { ManageIQ::Providers::Redhat::InfraManager }
307+
let(:mocked_infra) { double(ManageIQ::Providers::Redhat::InfraManager) }
308+
309+
it "queues the authentication type if it is a cloud provider" do
310+
allow(controller).to receive(:render)
311+
allow(ExtManagementSystem).to receive(:model_from_emstype)
312+
controller.instance_variable_set(:@_params, :controller => "ems_cloud")
303313

304-
it "calls authentication_check with save = false if validation is done for a new record" do
314+
expect(MiqTask).to receive(:generic_action_with_callback)
315+
expect(MiqTask).to receive(:wait_for_taskid)
316+
controller.send(:create_ems_button_validate)
317+
end
318+
319+
it "does not queue the authentication check if it is not a cloud provider" do
305320
allow(controller).to receive(:set_ems_record_vars)
306321
allow(controller).to receive(:render)
307-
controller.instance_variable_set(:@_params,
308-
:button => "validate",
309-
:default_password => "[FILTERED]",
310-
:cred_type => "default")
311-
expect(mocked_ems).to receive(:authentication_check).with("default", hash_including(:save => false))
312-
controller.send(:update_ems_button_validate, mocked_ems)
322+
allow(ExtManagementSystem).to receive(:model_from_emstype).and_return(mocked_infra_class)
323+
allow(mocked_infra_class).to receive(:new).and_return(mocked_infra)
324+
controller.instance_variable_set(:@_params, :controller => "ems_infra", :cred_type => "default")
325+
326+
expect(mocked_infra).to receive(:authentication_check).with("default", hash_including(:save => false))
327+
controller.send(:create_ems_button_validate)
313328
end
314329
end
330+
315331
describe "#test_toolbars" do
316332
before do
317333
allow(controller).to receive(:check_privileges).and_return(true)

0 commit comments

Comments
 (0)