foreman_remote_execution 16.0.3 → 16.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/job_templates_controller.rb +2 -1
  3. data/app/controllers/cockpit_controller.rb +2 -2
  4. data/app/controllers/job_invocations_controller.rb +28 -1
  5. data/app/controllers/template_invocations_controller.rb +1 -1
  6. data/app/helpers/hosts_extensions_helper.rb +1 -1
  7. data/app/lib/actions/remote_execution/run_host_job.rb +5 -28
  8. data/app/models/concerns/foreman_remote_execution/host_extensions.rb +7 -1
  9. data/app/models/job_template.rb +5 -0
  10. data/app/models/{ssh_execution_provider.rb → script_execution_provider.rb} +2 -4
  11. data/config/initializers/inflections.rb +0 -1
  12. data/config/routes.rb +1 -0
  13. data/lib/foreman_remote_execution/engine.rb +10 -257
  14. data/lib/foreman_remote_execution/plugin.rb +246 -0
  15. data/lib/foreman_remote_execution/version.rb +1 -1
  16. data/test/functional/api/v2/job_invocations_controller_test.rb +1 -1
  17. data/test/functional/api/v2/job_templates_controller_test.rb +29 -0
  18. data/test/unit/actions/run_host_job_test.rb +1 -1
  19. data/test/unit/job_invocation_report_template_test.rb +6 -6
  20. data/test/unit/remote_execution_provider_test.rb +19 -19
  21. data/webpack/JobInvocationDetail/CheckboxesActions.js +196 -0
  22. data/webpack/JobInvocationDetail/{JobInvocationHostTableToolbar.js → DropdownFilter.js} +3 -6
  23. data/webpack/JobInvocationDetail/JobInvocationConstants.js +7 -7
  24. data/webpack/JobInvocationDetail/JobInvocationDetail.scss +32 -0
  25. data/webpack/JobInvocationDetail/JobInvocationHostTable.js +221 -91
  26. data/webpack/JobInvocationDetail/JobInvocationSelectors.js +30 -3
  27. data/webpack/JobInvocationDetail/JobInvocationSystemStatusChart.js +8 -22
  28. data/webpack/JobInvocationDetail/JobInvocationToolbarButtons.js +20 -27
  29. data/webpack/JobInvocationDetail/OpenAllInvocationsModal.js +118 -0
  30. data/webpack/JobInvocationDetail/TemplateInvocation.js +54 -24
  31. data/webpack/JobInvocationDetail/TemplateInvocationComponents/TemplateActionButtons.js +8 -10
  32. data/webpack/JobInvocationDetail/TemplateInvocationPage.js +1 -1
  33. data/webpack/JobInvocationDetail/__tests__/MainInformation.test.js +1 -1
  34. data/webpack/JobInvocationDetail/__tests__/TableToolbarActions.test.js +202 -0
  35. data/webpack/JobInvocationDetail/__tests__/TemplateInvocation.test.js +34 -28
  36. data/webpack/JobInvocationDetail/index.js +64 -31
  37. data/webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js +26 -7
  38. data/webpack/react_app/components/TargetingHosts/TargetingHostsLabelsRow.scss +1 -1
  39. metadata +9 -7
  40. data/webpack/JobInvocationDetail/OpenAlInvocations.js +0 -111
  41. data/webpack/JobInvocationDetail/__tests__/OpenAlInvocations.test.js +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40f170b56effb3a3f7f415ac040d45242641bc3210266bf723d957a4337e8aa2
4
- data.tar.gz: c6a8e5a792629049aa8e40fdc2a3b6b20cc182af3e0e3d1578e5e3614525e7d0
3
+ metadata.gz: f0af6a4d6d568edd8bf5d878940d19f72d3f2b2ad2c67e767cd7764e2287ba3f
4
+ data.tar.gz: 5b7f5b64a90c38b6b65df711be7bf93c586c73400386c96c6ae280285b4a9349
5
5
  SHA512:
6
- metadata.gz: 7b47defe2e23b8ce3ac1ebc08164749d7c2a03a133f78dfcb702c76cd4f434786b0dbeceb72c2d7ca47cedbd5d1f688175b9e0680245eac4e1064f9739d2b68c
7
- data.tar.gz: c0d069ef4dde5b1a07cb38b60f0dcc7218487cc58a5a2961039f2603517a2fdc5060b603b4a13b5ff4c659a13b9b25eb836b59e5e3d6efbe1e69202364cc0f87
6
+ metadata.gz: 408d5714fba95e7213fa42c2510021231cd2d5c61b7ecc502a0d76c96ca80f97758e03928da5a1c1acc9547fe4fcbfbe2f836991954b78a09cbe7b6ef0644e95
7
+ data.tar.gz: c0468bdebd334affe636a1aa34dff3689707084a0d0f141b05c0a09428f6700aa48b1a43b2e9e61262d8bd8968ab4c22b3d1ab68ad48cf8527b930989fac8994
@@ -108,8 +108,9 @@ module Api
108
108
  param :id, :identifier, :required => true
109
109
  param_group :job_template_clone, :as => :create
110
110
  def clone
111
+ original = @job_template
111
112
  @job_template = @job_template.clone
112
- load_vars_from_template
113
+ @job_template.cloned_from = original
113
114
  @job_template.name = job_template_params[:name]
114
115
  process_response @job_template.save
115
116
  end
@@ -2,7 +2,7 @@ class CockpitController < ApplicationController
2
2
  before_action :find_resource, :only => [:host_ssh_params]
3
3
 
4
4
  def host_ssh_params
5
- render :json => SSHExecutionProvider.ssh_params(@host)
5
+ render :json => ScriptExecutionProvider.ssh_params(@host)
6
6
  end
7
7
 
8
8
  def redirect
@@ -10,7 +10,7 @@ class CockpitController < ApplicationController
10
10
 
11
11
  redir_url = URI.parse(params[:redirect_uri])
12
12
 
13
- cockpit_url = SSHExecutionProvider.cockpit_url_for_host('')
13
+ cockpit_url = ScriptExecutionProvider.cockpit_url_for_host('')
14
14
  redir_url.query = if redir_url.hostname == URI.join(Setting[:foreman_url], cockpit_url).hostname
15
15
  "access_token=#{request.session_options[:id]}"
16
16
  else
@@ -149,6 +149,33 @@ class JobInvocationsController < ApplicationController
149
149
  render :json => {:job_invocations => job_invocations}
150
150
  end
151
151
 
152
+ def list_jobs_hosts
153
+ @job_invocation = resource_base.find(params[:id])
154
+ hosts = @job_invocation.targeting.hosts.authorized(:view_hosts, Host)
155
+ hosts = hosts.search_for(params[:search])
156
+ template_invocations_task_by_hosts = {}
157
+ hosts.each do |host|
158
+ template_invocation = @job_invocation.template_invocations.find { |template_inv| template_inv.host_id == host.id }
159
+ next unless template_invocation
160
+ template_invocation_task = template_invocation.run_host_job_task
161
+ template_invocations_task_by_hosts[host.id] =
162
+ {
163
+ :host_name => host.name,
164
+ :id => host.id,
165
+ :task => template_invocation_task.attributes.merge({cancellable: template_invocation_task.cancellable? }),
166
+ :permissions => {
167
+ :view_foreman_tasks => authorized_for(:permission => :view_foreman_tasks, :auth_object => template_invocation_task),
168
+ :cancel_job_invocations => authorized_for(:permission => :cancel_job_invocations, :auth_object => @job_invocation),
169
+ :execute_jobs => authorized_for(controller: :job_invocations, action: :create) && (!host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts)),
170
+ },
171
+ }
172
+ end
173
+
174
+ render json: {
175
+ :template_invocations_task_by_hosts => template_invocations_task_by_hosts,
176
+ }
177
+ end
178
+
152
179
  private
153
180
 
154
181
  def action_permission
@@ -159,7 +186,7 @@ class JobInvocationsController < ApplicationController
159
186
  'create'
160
187
  when 'cancel'
161
188
  'cancel'
162
- when 'chart', 'preview_job_invocations_per_host'
189
+ when 'chart', 'preview_job_invocations_per_host', 'list_jobs_hosts'
163
190
  'view'
164
191
  else
165
192
  super
@@ -48,7 +48,7 @@ class TemplateInvocationsController < ApplicationController
48
48
 
49
49
  auto_refresh = @job_invocation.task.try(:pending?)
50
50
  finished = @job_invocation.status_label == 'failed' || @job_invocation.status_label == 'succeeded' || @job_invocation.status_label == 'cancelled'
51
- render :json => { :output => lines, :preview => template_invocation_preview(@template_invocation, @host), :proxy => proxy, :input_values => transformed_input_values, :job_invocation_description => @job_invocation.description, :task_id => @template_invocation_task.id, :task_cancellable => @template_invocation_task.cancellable?, :host_name => @host.name, :permissions => {
51
+ render :json => { :output => lines, :preview => template_invocation_preview(@template_invocation, @host), :proxy => proxy, :input_values => transformed_input_values, :job_invocation_description => @job_invocation.description, :task => @template_invocation_task.attributes.merge({cancellable: @template_invocation_task.cancellable? }), :host_name => @host.name, :permissions => {
52
52
  :view_foreman_tasks => User.current.allowed_to?(:view_foreman_tasks),
53
53
  :cancel_job_invocations => User.current.allowed_to?(:cancel_job_invocations),
54
54
  :execute_jobs => User.current.allowed_to?(:create_job_invocations) && (!@host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts)),
@@ -44,7 +44,7 @@ module HostsExtensionsHelper
44
44
  def web_console_button(host, *_args)
45
45
  return if !authorized_for(permission: 'cockpit_hosts', auth_object: host) || !can_execute_on_infrastructure_host?(host)
46
46
 
47
- url = SSHExecutionProvider.cockpit_url_for_host(host.name)
47
+ url = ScriptExecutionProvider.cockpit_url_for_host(host.name)
48
48
  url ? link_to(_('Web Console'), url, :class => 'btn btn-default', :id => :'web-console-button', :target => '_new') : nil
49
49
  end
50
50
 
@@ -70,7 +70,7 @@ module Actions
70
70
  .merge(additional_options)
71
71
 
72
72
  plan_delegated_action(proxy, provider.proxy_action_class, action_options, proxy_action_class: ::Actions::RemoteExecution::ProxyAction)
73
- plan_self :with_event_logging => true
73
+ plan_self
74
74
  end
75
75
 
76
76
  def finalize(*args)
@@ -127,32 +127,6 @@ module Actions
127
127
  end
128
128
 
129
129
  def fill_continuous_output(continuous_output)
130
- if input[:with_event_logging]
131
- continuous_output_from_template_invocation_events(continuous_output)
132
- return
133
- end
134
-
135
- delegated_output.fetch('result', []).each do |raw_output|
136
- continuous_output.add_raw_output(raw_output)
137
- end
138
-
139
- final_timestamp = (continuous_output.last_timestamp || task.ended_at).to_f + 1
140
-
141
- if task.state == 'stopped' && task.result == 'cancelled'
142
- continuous_output.add_output(_('Job cancelled by user'), 'debug', final_timestamp)
143
- else
144
- fill_planning_errors_to_continuous_output(continuous_output) unless exit_status
145
- end
146
- if exit_status
147
- continuous_output.add_output(_('Exit status: %s') % exit_status, 'stdout', final_timestamp)
148
- elsif run_step&.error
149
- continuous_output.add_output(_('Job finished with error') + ": #{run_step.error.exception_class} - #{run_step.error.message}", 'debug', final_timestamp)
150
- end
151
- rescue => e
152
- continuous_output.add_exception(_('Error loading data from proxy'), e)
153
- end
154
-
155
- def continuous_output_from_template_invocation_events(continuous_output)
156
130
  begin
157
131
  # Trigger reload
158
132
  delegated_output unless task.state == 'stopped'
@@ -160,6 +134,7 @@ module Actions
160
134
  # This is enough, the error will get shown using add_exception at the end of the method
161
135
  end
162
136
 
137
+ # Show the outputs which are already stored in the database
163
138
  task.template_invocation.template_invocation_events.order(:timestamp).find_each do |output|
164
139
  if output.event_type == 'exit'
165
140
  continuous_output.add_output(_('Exit status: %s') % output.event, 'stdout', output.timestamp)
@@ -167,11 +142,13 @@ module Actions
167
142
  continuous_output.add_raw_output(output.as_raw_continuous_output)
168
143
  end
169
144
  end
145
+
146
+ # Attach the exception at the end
170
147
  continuous_output.add_exception(_('Error loading data from proxy'), e) if e
171
148
  end
172
149
 
173
150
  def exit_status
174
- input[:with_event_logging] ? task.template_invocation.template_invocation_events.find_by(event_type: 'exit')&.event : delegated_output[:exit_status]
151
+ task.template_invocation.template_invocation_events.find_by(event_type: 'exit')&.event
175
152
  end
176
153
 
177
154
  def host_id
@@ -28,6 +28,8 @@ module ForemanRemoteExecution
28
28
  end
29
29
  }
30
30
 
31
+ after_build :reset_host_proxy_invocations
32
+
31
33
  def search_by_job_invocation(key, operator, value)
32
34
  if key == 'job_invocation.result'
33
35
  operator = operator == '=' ? 'IN' : 'NOT IN'
@@ -46,8 +48,12 @@ module ForemanRemoteExecution
46
48
  end
47
49
  end
48
50
 
51
+ def reset_host_proxy_invocations
52
+ HostProxyInvocation.where(host_id: self.id).delete_all
53
+ end
54
+
49
55
  def cockpit_url
50
- SSHExecutionProvider.cockpit_url_for_host(self.name)
56
+ ScriptExecutionProvider.cockpit_url_for_host(self.name)
51
57
  end
52
58
 
53
59
  def execution_status(options = {})
@@ -129,6 +129,11 @@ class JobTemplate < ::Template
129
129
  end
130
130
  end
131
131
 
132
+ def clone
133
+ deep_clone(:include => [:effective_user, :foreign_input_sets, :organizations, :locations],
134
+ :except => [:name, :locked])
135
+ end
136
+
132
137
  def provider
133
138
  RemoteExecutionProvider.provider_for(provider_type)
134
139
  end
@@ -40,7 +40,7 @@ class ScriptExecutionProvider < RemoteExecutionProvider
40
40
  proxy = proxy_for_cockpit(host)
41
41
  {
42
42
  :hostname => find_ip_or_hostname(host),
43
- :proxy => proxy.class == Symbol ? proxy : proxy.url,
43
+ :proxy => proxy.instance_of?(Symbol) ? proxy : proxy.url,
44
44
  :ssh_user => ssh_user(host),
45
45
  :ssh_port => ssh_port(host),
46
46
  :ssh_password => ssh_password(host),
@@ -50,7 +50,7 @@ class ScriptExecutionProvider < RemoteExecutionProvider
50
50
  end
51
51
 
52
52
  def cockpit_url_for_host(host)
53
- Setting[:remote_execution_cockpit_url] % { :host => host } if Setting[:remote_execution_cockpit_url].present?
53
+ format(Setting[:remote_execution_cockpit_url], host: host) if Setting[:remote_execution_cockpit_url].present?
54
54
  end
55
55
 
56
56
  def proxy_feature
@@ -76,5 +76,3 @@ class ScriptExecutionProvider < RemoteExecutionProvider
76
76
  end
77
77
  end
78
78
  end
79
-
80
- SSHExecutionProvider = ScriptExecutionProvider
@@ -1,6 +1,5 @@
1
1
  Rails.autoloaders.each do |autoloader|
2
2
  autoloader.inflector.inflect(
3
- 'ssh_execution_provider' => 'SSHExecutionProvider',
4
3
  'remote_execution_ssh' => 'RemoteExecutionSSH'
5
4
  )
6
5
  end
data/config/routes.rb CHANGED
@@ -35,6 +35,7 @@ Rails.application.routes.draw do
35
35
  get 'auto_complete_search'
36
36
  end
37
37
  member do
38
+ get 'hosts', to: 'job_invocations#list_jobs_hosts'
38
39
  post 'cancel'
39
40
  end
40
41
  end
@@ -7,13 +7,14 @@ module ForemanRemoteExecution
7
7
  # Precompile any JS or CSS files under app/assets/
8
8
  # If requiring files from each other, list them explicitly here to avoid precompiling the same
9
9
  # content twice.
10
- assets_to_precompile =
11
- Dir.chdir(root) do
10
+ def self.assets_to_precompile
11
+ assets = Dir.chdir(root) do
12
12
  Dir['app/assets/javascripts/**/*'].map do |f|
13
13
  f.split(File::SEPARATOR, 4).last
14
14
  end
15
15
  end
16
- assets_to_precompile += %w(foreman_remote_execution/foreman_remote_execution.css)
16
+ assets << 'foreman_remote_execution/foreman_remote_execution.css'
17
+ end
17
18
 
18
19
  # Add any db migrations
19
20
  initializer 'foreman_remote_execution.load_app_instance_data' do |app|
@@ -34,260 +35,16 @@ module ForemanRemoteExecution
34
35
 
35
36
  initializer 'foreman_remote_execution.register_plugin', before: :finisher_hook do |app|
36
37
  app.reloader.to_prepare do
37
- Foreman::Plugin.register :foreman_remote_execution do
38
- requires_foreman '>= 3.15'
39
- register_global_js_file 'global'
40
- register_gettext
41
-
42
- apipie_documented_controllers ["#{ForemanRemoteExecution::Engine.root}/app/controllers/api/v2/*.rb"]
43
- ApipieDSL.configuration.dsl_classes_matchers += [
44
- "#{ForemanRemoteExecution::Engine.root}/app/lib/foreman_remote_execution/renderer/**/*.rb",
45
- ]
46
- automatic_assets(false)
47
- precompile_assets(*assets_to_precompile)
48
-
49
- # Add settings to a Remote Execution category
50
- settings do
51
- category :remote_execution, N_('Remote Execution') do
52
- setting 'remote_execution_fallback_proxy',
53
- type: :boolean,
54
- description: N_('Search the host for any proxy with Remote Execution, useful when the host has no subnet or the subnet does not have an execution proxy'),
55
- default: false,
56
- full_name: N_('Fallback to Any Proxy')
57
- setting 'remote_execution_global_proxy',
58
- type: :boolean,
59
- description: N_('Search for remote execution proxy outside of the proxies assigned to the host. The search will be limited to the host\'s organization and location.'),
60
- default: true,
61
- full_name: N_('Enable Global Proxy')
62
- setting 'remote_execution_ssh_user',
63
- type: :string,
64
- description: N_('Default user to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_user.'),
65
- default: 'root',
66
- full_name: N_('SSH User')
67
- setting 'remote_execution_effective_user',
68
- type: :string,
69
- description: N_('Default user to use for executing the script. If the user differs from the SSH user, su or sudo is used to switch the user.'),
70
- default: 'root',
71
- full_name: N_('Effective User')
72
- setting 'remote_execution_effective_user_method',
73
- type: :string,
74
- description: N_('What command should be used to switch to the effective user. One of %s') % ::SSHExecutionProvider::EFFECTIVE_USER_METHODS.inspect,
75
- default: 'sudo',
76
- full_name: N_('Effective User Method'),
77
- collection: proc { Hash[::SSHExecutionProvider::EFFECTIVE_USER_METHODS.map { |method| [method, method] }] }
78
- setting 'remote_execution_effective_user_password',
79
- type: :string,
80
- description: N_('Effective user password'),
81
- default: '',
82
- full_name: N_('Effective user password'),
83
- encrypted: true
84
- setting 'remote_execution_sync_templates',
85
- type: :boolean,
86
- description: N_('Whether we should sync templates from disk when running db:seed.'),
87
- default: true,
88
- full_name: N_('Sync Job Templates')
89
- setting 'remote_execution_ssh_port',
90
- type: :integer,
91
- description: N_('Port to use for SSH communication. Default port 22. You may override per host by setting a parameter called remote_execution_ssh_port.'),
92
- default: 22,
93
- full_name: N_('SSH Port')
94
- setting 'remote_execution_connect_by_ip',
95
- type: :boolean,
96
- description: N_('Should the ip addresses on host interfaces be preferred over the fqdn? '\
97
- 'It is useful when DNS not resolving the fqdns properly. You may override this per host by setting a parameter called remote_execution_connect_by_ip. '\
98
- 'For dual-stacked hosts you should consider the remote_execution_connect_by_ip_prefer_ipv6 setting'),
99
- default: false,
100
- full_name: N_('Connect by IP')
101
- setting 'remote_execution_connect_by_ip_prefer_ipv6',
102
- type: :boolean,
103
- description: N_('When connecting using ip address, should the IPv6 addresses be preferred? '\
104
- 'If no IPv6 address is set, it falls back to IPv4 automatically. You may override this per host by setting a parameter called remote_execution_connect_by_ip_prefer_ipv6. '\
105
- 'By default and for compatibility, IPv4 will be preferred over IPv6 by default'),
106
- default: false,
107
- full_name: N_('Prefer IPv6 over IPv4')
108
- setting 'remote_execution_ssh_password',
109
- type: :string,
110
- description: N_('Default password to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_password'),
111
- default: nil,
112
- full_name: N_('Default SSH password'),
113
- encrypted: true
114
- setting 'remote_execution_ssh_key_passphrase',
115
- type: :string,
116
- description: N_('Default key passphrase to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_key_passphrase'),
117
- default: nil,
118
- full_name: N_('Default SSH key passphrase'),
119
- encrypted: true
120
- setting 'remote_execution_cleanup_working_dirs',
121
- type: :boolean,
122
- description: N_('When enabled, working directories will be removed after task completion. You may override this per host by setting a parameter called remote_execution_cleanup_working_dirs.'),
123
- default: true,
124
- full_name: N_('Cleanup working directories')
125
- setting 'remote_execution_cockpit_url',
126
- type: :string,
127
- description: N_('Where to find the Cockpit instance for the Web Console button. By default, no button is shown.'),
128
- default: nil,
129
- full_name: N_('Cockpit URL')
130
- setting 'remote_execution_form_job_template',
131
- type: :string,
132
- description: N_('Choose a job template that is pre-selected in job invocation form'),
133
- default: 'Run Command - Script Default',
134
- full_name: N_('Form Job Template'),
135
- collection: proc { Hash[JobTemplate.unscoped.map { |template| [template.name, template.name] }] }
136
- setting 'remote_execution_job_invocation_report_template',
137
- type: :string,
138
- description: N_('Select a report template used for generating a report for a particular remote execution job'),
139
- default: 'Job - Invocation Report',
140
- full_name: N_('Job Invocation Report Template'),
141
- collection: proc { ForemanRemoteExecution.job_invocation_report_templates_select }
142
- setting 'remote_execution_time_to_pickup',
143
- type: :integer,
144
- description: N_('Time in seconds within which the host has to pick up a job. If the job is not picked up within this limit, the job will be cancelled. Defaults to 1 day. Applies only to pull-mqtt based jobs.'),
145
- default: 24 * 60 * 60,
146
- full_name: N_('Time to pickup')
147
- end
148
- end
149
-
150
- # Add permissions
151
- security_block :foreman_remote_execution do
152
- permission :view_job_templates, { :job_templates => [:index, :show, :revision, :auto_complete_search, :auto_complete_job_category, :preview, :export],
153
- :'api/v2/job_templates' => [:index, :show, :revision, :export],
154
- :'api/v2/template_inputs' => [:index, :show],
155
- :'api/v2/foreign_input_sets' => [:index, :show],
156
- :ui_job_wizard => [:categories, :template, :resources, :job_invocation]}, :resource_type => 'JobTemplate'
157
- permission :create_job_templates, { :job_templates => [:new, :create, :clone_template, :import],
158
- :'api/v2/job_templates' => [:create, :clone, :import] }, :resource_type => 'JobTemplate'
159
- permission :edit_job_templates, { :job_templates => [:edit, :update],
160
- :'api/v2/job_templates' => [:update],
161
- :'api/v2/template_inputs' => [:create, :update, :destroy],
162
- :'api/v2/foreign_input_sets' => [:create, :update, :destroy]}, :resource_type => 'JobTemplate'
163
- permission :view_remote_execution_features, { :remote_execution_features => [:index, :show],
164
- :'api/v2/remote_execution_features' => [:index, :show, :available_remote_execution_features]},
165
- :resource_type => 'RemoteExecutionFeature'
166
- permission :edit_remote_execution_features, { :remote_execution_features => [:update],
167
- :'api/v2/remote_execution_features' => [:update ]}, :resource_type => 'RemoteExecutionFeature'
168
- permission :destroy_job_templates, { :job_templates => [:destroy],
169
- :'api/v2/job_templates' => [:destroy] }, :resource_type => 'JobTemplate'
170
- permission :lock_job_templates, { :job_templates => [:lock, :unlock] }, :resource_type => 'JobTemplate'
171
- permission :create_job_invocations, { :job_invocations => [:new, :create, :legacy_create, :refresh, :rerun, :preview_hosts],
172
- 'api/v2/job_invocations' => [:create, :rerun] }, :resource_type => 'JobInvocation'
173
- permission :view_job_invocations, { :job_invocations => [:index, :chart, :show, :auto_complete_search, :preview_job_invocations_per_host], :template_invocations => [:show, :show_template_invocation_by_host],
174
- 'api/v2/job_invocations' => [:index, :show, :output, :raw_output, :outputs, :hosts] }, :resource_type => 'JobInvocation'
175
- permission :view_template_invocations, { :template_invocations => [:show, :template_invocation_preview, :show_template_invocation_by_host],
176
- 'api/v2/template_invocations' => [:template_invocations], :ui_job_wizard => [:job_invocation] }, :resource_type => 'TemplateInvocation'
177
- permission :create_template_invocations, {}, :resource_type => 'TemplateInvocation'
178
- permission :execute_jobs_on_infrastructure_hosts, {}, :resource_type => 'JobInvocation'
179
- permission :cancel_job_invocations, { :job_invocations => [:cancel], 'api/v2/job_invocations' => [:cancel] }, :resource_type => 'JobInvocation'
180
- # this permissions grants user to get auto completion hints when setting up filters
181
- permission :filter_autocompletion_for_template_invocation, { :template_invocations => [ :auto_complete_search, :index ] },
182
- :resource_type => 'TemplateInvocation'
183
- permission :cockpit_hosts, { 'cockpit' => [:redirect, :host_ssh_params] }, :resource_type => 'Host'
184
- end
185
-
186
- USER_PERMISSIONS = [
187
- :view_job_templates,
188
- :view_job_invocations,
189
- :create_job_invocations,
190
- :create_template_invocations,
191
- :view_hosts,
192
- :view_smart_proxies,
193
- :view_remote_execution_features,
194
- ].freeze
195
- MANAGER_PERMISSIONS = USER_PERMISSIONS + [
196
- :cancel_job_invocations,
197
- :destroy_job_templates,
198
- :edit_job_templates,
199
- :create_job_templates,
200
- :lock_job_templates,
201
- :view_audit_logs,
202
- :filter_autocompletion_for_template_invocation,
203
- :edit_remote_execution_features,
204
- ]
205
-
206
- # Add a new role called 'Remote Execution User ' if it doesn't exist
207
- role 'Remote Execution User', USER_PERMISSIONS, 'Role with permissions to run remote execution jobs against hosts'
208
- role 'Remote Execution Manager', MANAGER_PERMISSIONS, 'Role with permissions to manage job templates, remote execution features, cancel jobs and view audit logs'
209
-
210
- add_all_permissions_to_default_roles(except: [:execute_jobs_on_infrastructure_hosts])
211
- add_permissions_to_default_roles({
212
- Role::MANAGER => [:execute_jobs_on_infrastructure_hosts],
213
- Role::SITE_MANAGER => USER_PERMISSIONS + [:execute_jobs_on_infrastructure_hosts],
214
- })
215
-
216
- # add menu entry
217
- menu :top_menu, :job_templates,
218
- url_hash: { controller: :job_templates, action: :index },
219
- caption: N_('Job Templates'),
220
- parent: :hosts_menu,
221
- after: :provisioning_templates
222
- menu :admin_menu, :remote_execution_features,
223
- url_hash: { controller: :remote_execution_features, action: :index },
224
- caption: N_('Remote Execution Features'),
225
- parent: :administer_menu,
226
- after: :bookmarks
227
-
228
- menu :top_menu, :job_invocations,
229
- url_hash: { controller: :job_invocations, action: :index },
230
- caption: N_('Jobs'),
231
- parent: :monitor_menu,
232
- after: :audits
233
-
234
- menu :labs_menu, :job_invocations_detail,
235
- url_hash: { controller: :job_invocations, action: :show },
236
- caption: N_('Job invocations detail'),
237
- parent: :lab_features_menu,
238
- url: '/experimental/job_invocations_detail/1'
239
-
240
- register_custom_status HostStatus::ExecutionStatus
241
- # add dashboard widget
242
- # widget 'foreman_remote_execution_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
243
- widget 'dashboard/latest-jobs', :name => N_('Latest Jobs'), :sizex => 6, :sizey => 1
244
-
245
- parameter_filter Subnet, :remote_execution_proxies, :remote_execution_proxy_ids => []
246
- parameter_filter Nic::Interface do |ctx|
247
- ctx.permit :execution
248
- end
249
-
250
- register_graphql_query_field :job_invocations, '::Types::JobInvocation', :collection_field
251
- register_graphql_query_field :job_invocation, '::Types::JobInvocation', :record_field
252
-
253
- register_graphql_mutation_field :create_job_invocation, ::Mutations::JobInvocations::Create
254
-
255
- extend_template_helpers ForemanRemoteExecution::RendererMethods
256
-
257
- extend_rabl_template 'api/v2/smart_proxies/main', 'api/v2/smart_proxies/pubkey'
258
- extend_rabl_template 'api/v2/interfaces/main', 'api/v2/interfaces/execution_flag'
259
- extend_rabl_template 'api/v2/subnets/show', 'api/v2/subnets/remote_execution_proxies'
260
- extend_rabl_template 'api/v2/hosts/main', 'api/v2/host/main'
261
- parameter_filter ::Subnet, :remote_execution_proxy_ids
262
-
263
- describe_host do
264
- multiple_actions_provider :rex_hosts_multiple_actions
265
- overview_buttons_provider :rex_host_overview_buttons
266
- end
267
-
268
- # Extend Registration module
269
- extend_allowed_registration_vars :remote_execution_interface
270
- extend_allowed_registration_vars :setup_remote_execution_pull
271
- ForemanTasks.dynflow.eager_load_actions!
272
- extend_observable_events(
273
- ::Dynflow::Action.descendants.select do |klass|
274
- klass <= ::Actions::ObservableAction
275
- end.map(&:namespaced_event_names) +
276
- RemoteExecutionFeature.all.pluck(:label).flat_map do |label|
277
- [::Actions::RemoteExecution::RunHostJob, ::Actions::RemoteExecution::RunHostsJob].map do |klass|
278
- klass.feature_job_event_names(label)
279
- end
280
- end
281
- )
282
- end
38
+ # Allow plugin registration to call application code once on boot
39
+ require_relative 'plugin'
283
40
  end
284
41
  end
285
42
 
286
43
  initializer 'foreman_remote_execution.assets.precompile' do |app|
287
- app.config.assets.precompile += assets_to_precompile
44
+ app.config.assets.precompile += Engine.assets_to_precompile
288
45
  end
289
46
  initializer 'foreman_remote_execution.configure_assets', group: :assets do
290
- SETTINGS[:foreman_remote_execution] = { assets: { precompile: assets_to_precompile } }
47
+ SETTINGS[:foreman_remote_execution] = { assets: { precompile: Engine.assets_to_precompile } }
291
48
  end
292
49
 
293
50
  # Include concerns in this config.to_prepare block
@@ -300,8 +57,7 @@ module ForemanRemoteExecution
300
57
  # e.g. having ProvisioningTemplate < Template, adding has_many :template_inputs to Template from concern
301
58
  # Template.reflect_on_association :template_inputs # => <#Association...
302
59
  # ProvisioningTemplate.reflect_on_association :template_inputs # => nil
303
- require_dependency 'job_template'
304
- (Template.descendants + [Template]).each { |klass| klass.send(:include, ForemanRemoteExecution::TemplateExtensions) }
60
+ (Template.descendants + [JobTemplate, Template]).each { |klass| klass.send(:include, ForemanRemoteExecution::TemplateExtensions) }
305
61
  Template.prepend ForemanRemoteExecution::TemplateOverrides
306
62
 
307
63
  (Taxonomy.descendants + [Taxonomy]).each { |klass| klass.send(:include, ForemanRemoteExecution::TaxonomyExtensions) }
@@ -323,12 +79,9 @@ module ForemanRemoteExecution
323
79
  Subnet.include ForemanRemoteExecution::SubnetExtensions
324
80
 
325
81
  ::Api::V2::InterfacesController.include Api::V2::InterfacesControllerExtensions
326
- # We need to explicitly force to load the Task model due to Rails loader
327
- # having issues with resolving it to Rake::Task otherwise
328
- require_dependency 'foreman_tasks/task'
329
82
  ForemanTasks::Task.include ForemanRemoteExecution::ForemanTasksTaskExtensions
330
83
  ForemanTasks::Cleaner.include ForemanRemoteExecution::ForemanTasksCleanerExtensions
331
- RemoteExecutionProvider.register(:SSH, ::SSHExecutionProvider)
84
+ RemoteExecutionProvider.register(:SSH, ::ScriptExecutionProvider)
332
85
  RemoteExecutionProvider.register(:script, ::ScriptExecutionProvider)
333
86
 
334
87
  ForemanRemoteExecution.register_rex_feature