-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathconfiguration_script_sources_controller.rb
More file actions
51 lines (44 loc) · 2 KB
/
configuration_script_sources_controller.rb
File metadata and controls
51 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Api
class ConfigurationScriptSourcesController < BaseController
include Subcollections::ConfigurationScriptPayloads
def edit_resource(type, id, data)
api_resource(type, id, "Updating") do |config_script_src|
ensure_respond_to(type, config_script_src, :update, :update_in_provider_queue)
{:task_id => config_script_src.update_in_provider_queue(data.deep_symbolize_keys)}
end
end
def delete_resource_main_action(type, config_script_src, _data)
ensure_respond_to(type, config_script_src, :delete, :delete_in_provider_queue)
{:task_id => config_script_src.delete_in_provider_queue}
end
def create_resource(type, _id, data)
manager_id = parse_id(data.delete('manager_resource'), :providers) || data['ems_id']
# Since we are passing a custom hash to create_ems_resource (instead of data variable)
# we need to manually remove it from data.
data.delete('id')
# Handle manual scm_type - create directly without provider queue
if data['scm_type'] == 'manual'
raise BadRequestError, _("Must specify name") unless data['name']
raise BadRequestError, _("Must specify manager_resource or ems_id") unless manager_id
# Create the script source directly
script_source = ConfigurationScriptSource.create!(
:name => data['name'],
:description => data['description'],
:manager_id => manager_id,
:scm_type => 'manual'
)
script_source
else
# Use provider queue for git and other scm_types
create_ems_resource(type, {'ems_id' => manager_id, 'name' => data['name']}, :supports => true) do |_manager, klass|
{:task_id => klass.create_in_provider_queue(manager_id, data.deep_symbolize_keys)}
end
end
end
def refresh_resource(type, id, _data)
api_resource(type, id, "Refreshing") do |config_script_src|
{:task_ids => EmsRefresh.queue_refresh_task(config_script_src)}
end
end
end
end