@@ -56,15 +56,34 @@ def update_ems_button_save
56
56
end
57
57
58
58
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 )
60
66
@in_a_form = true
67
+ verify_ems . authentication_check ( params [ :cred_type ] , :save => false , :database => params [ :metrics_database_name ] )
68
+ end
61
69
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
63
81
82
+ def render_validation_result ( result , details )
64
83
if result
65
84
add_flash ( _ ( "Credential validation was successful" ) )
66
85
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 )
68
87
end
69
88
70
89
render :json => { :message => @flash_array . last ( 1 ) [ 0 ] [ :message ] , :level => @flash_array . last ( 1 ) [ 0 ] [ :level ] }
@@ -75,12 +94,14 @@ def create
75
94
76
95
case params [ :button ]
77
96
when "add" then create_ems_button_add
78
- when "validate" then update_ems_button_validate
97
+ when "validate" then create_ems_button_validate
79
98
when "cancel" then create_ems_button_cancel
80
99
end
81
100
end
82
101
83
- def queue_authentication_check ( ems_type )
102
+ def queue_authentication_check
103
+ ems_type = model . model_from_emstype ( params [ :emstype ] )
104
+
84
105
task_opts = {
85
106
:action => "Validate EMS Provider Credentials" ,
86
107
:userid => session [ :userid ]
@@ -108,17 +129,19 @@ def queue_authentication_check(ems_type)
108
129
end
109
130
110
131
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" } ]
122
145
end
123
146
end
124
147
0 commit comments