foreman-tasks 0.11.0 → 0.11.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -4
- data/.rubocop_todo.yml +0 -3
- data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +13 -7
- data/app/controllers/foreman_tasks/tasks_controller.rb +5 -5
- data/app/lib/actions/middleware/hide_secrets.rb +11 -0
- data/app/lib/actions/middleware/keep_current_user.rb +1 -1
- data/app/lib/actions/proxy_action.rb +8 -0
- data/app/models/foreman_tasks/lock.rb +1 -1
- data/app/models/foreman_tasks/recurring_logic.rb +2 -2
- data/app/models/foreman_tasks/task.rb +1 -1
- data/app/models/foreman_tasks/task_group.rb +1 -1
- data/app/models/foreman_tasks/task_group_member.rb +1 -1
- data/app/models/foreman_tasks/triggering.rb +1 -1
- data/deploy/foreman-tasks.sysconfig +0 -1
- data/lib/foreman_tasks/engine.rb +1 -0
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/recurring_logics_controller_test.rb +2 -2
- data/test/controllers/api/tasks_controller_test.rb +2 -4
- data/test/foreman_tasks_test_helper.rb +1 -0
- data/test/support/dummy_task_group.rb +4 -0
- data/test/unit/actions/action_with_sub_plans_test.rb +0 -2
- data/test/unit/actions/proxy_action_test.rb +24 -1
- data/test/unit/recurring_logic_test.rb +11 -0
- data/test/unit/task_groups_test.rb +0 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b2dd645da0ebd3edca99e961dc24554fa56f679
|
4
|
+
data.tar.gz: 0e013856f470f68c6b5e0ed7f11feee290f0e4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8ca3871234b226b1e2d2843e6cdc59c4cbf712f8a8c942e478b304b7e07330aa5407bc55b159f90023970a55bfe0ffe9817473613dc3dc223847487eb4ba97
|
7
|
+
data.tar.gz: 50362b2a751157e3f8132ce4759f3262a389fa7c154bef924eecbfe9d2bf362809eb05c54c111da9188cc725b8a096f35d0b392cf4d4b66e43397a776792fbac
|
data/.rubocop.yml
CHANGED
@@ -43,10 +43,6 @@ Rails/SkipsModelValidations:
|
|
43
43
|
Style/SymbolArray:
|
44
44
|
Enabled: false
|
45
45
|
|
46
|
-
# for compatibility with Foreman 1.15
|
47
|
-
Rails/ApplicationRecord:
|
48
|
-
Enabled: false
|
49
|
-
|
50
46
|
Style/FormatString:
|
51
47
|
Enabled: false
|
52
48
|
|
@@ -62,6 +58,9 @@ Rails/ReversibleMigration:
|
|
62
58
|
|
63
59
|
Metrics/BlockLength:
|
64
60
|
Exclude:
|
61
|
+
- config/routes.rb
|
62
|
+
- lib/foreman_remote_execution/engine.rb
|
63
|
+
- test/**/*
|
65
64
|
- lib/foreman_tasks/tasks/**/*
|
66
65
|
|
67
66
|
Naming/FileName:
|
data/.rubocop_todo.yml
CHANGED
@@ -3,22 +3,28 @@ module ForemanTasks
|
|
3
3
|
module Parameters
|
4
4
|
module Triggering
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
include Foreman::Controller::Parameters::KeepParam
|
7
6
|
|
8
7
|
class_methods do
|
9
8
|
def triggering_params_filter
|
10
9
|
Foreman::ParameterFilter.new(::ForemanTasks::Triggering).tap do |filter|
|
11
|
-
filter.permit_by_context(
|
12
|
-
|
13
|
-
|
10
|
+
filter.permit_by_context(
|
11
|
+
[
|
12
|
+
:mode,
|
13
|
+
:start_at,
|
14
|
+
:start_before,
|
15
|
+
*::ForemanTasks::Triggering::PARAMS,
|
16
|
+
:days_of_week => {},
|
17
|
+
:time => {},
|
18
|
+
:end_time => {}
|
19
|
+
],
|
20
|
+
:nested => true
|
21
|
+
)
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
|
18
26
|
def triggering_params
|
19
|
-
|
20
|
-
self.class.triggering_params_filter.filter_params(params, parameter_filter_context, :triggering)
|
21
|
-
end
|
27
|
+
self.class.triggering_params_filter.filter_params(params, parameter_filter_context, :triggering)
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -42,7 +42,7 @@ module ForemanTasks
|
|
42
42
|
else
|
43
43
|
flash[:warning] = _('The task cannot be cancelled at the moment.')
|
44
44
|
end
|
45
|
-
|
45
|
+
redirect_back(:fallback_location => foreman_tasks_task_path(task))
|
46
46
|
end
|
47
47
|
|
48
48
|
def abort
|
@@ -52,7 +52,7 @@ module ForemanTasks
|
|
52
52
|
else
|
53
53
|
flash[:warning] = _('The task cannot be aborted at the moment.')
|
54
54
|
end
|
55
|
-
|
55
|
+
redirect_back(:fallback_location => foreman_tasks_task_path(task))
|
56
56
|
end
|
57
57
|
|
58
58
|
def resume
|
@@ -63,7 +63,7 @@ module ForemanTasks
|
|
63
63
|
else
|
64
64
|
flash[:warning] = _('The execution has to be resumable.')
|
65
65
|
end
|
66
|
-
|
66
|
+
redirect_back(:fallback_location => foreman_tasks_task_path(task))
|
67
67
|
end
|
68
68
|
|
69
69
|
def unlock
|
@@ -75,7 +75,7 @@ module ForemanTasks
|
|
75
75
|
else
|
76
76
|
flash[:warning] = _('The execution has to be paused.')
|
77
77
|
end
|
78
|
-
|
78
|
+
redirect_back(:fallback_location => foreman_tasks_task_path(task))
|
79
79
|
end
|
80
80
|
|
81
81
|
def force_unlock
|
@@ -83,7 +83,7 @@ module ForemanTasks
|
|
83
83
|
task.state = :stopped
|
84
84
|
task.save!
|
85
85
|
flash[:notice] = _('The task resources were unlocked with force.')
|
86
|
-
|
86
|
+
redirect_back(:fallback_location => foreman_tasks_task_path(task))
|
87
87
|
end
|
88
88
|
|
89
89
|
# we need do this to make the Foreman helpers working properly
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Actions
|
2
|
+
module Middleware
|
3
|
+
class HideSecrets < ::Dynflow::Middleware
|
4
|
+
def present
|
5
|
+
action.input[:secrets] = 'Secrets hidden' if action.input.key?(:secrets)
|
6
|
+
action.output[:secrets] = 'Secrets hidden' if action.output.key?(:secrets)
|
7
|
+
pass
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -47,7 +47,7 @@ module Actions
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def restore_curent_user
|
50
|
-
User.current = User.unscoped.find(action.input[:current_user_id])
|
50
|
+
User.current = User.unscoped.find(action.input[:current_user_id]) if action.input[:current_user_id].present?
|
51
51
|
yield
|
52
52
|
ensure
|
53
53
|
User.current = nil
|
@@ -3,6 +3,8 @@ module Actions
|
|
3
3
|
include ::Dynflow::Action::Cancellable
|
4
4
|
include ::Dynflow::Action::Timeouts
|
5
5
|
|
6
|
+
middleware.use ::Actions::Middleware::HideSecrets
|
7
|
+
|
6
8
|
class CallbackData
|
7
9
|
attr_reader :data
|
8
10
|
|
@@ -93,6 +95,12 @@ module Actions
|
|
93
95
|
# @override to put custom logic on event handling
|
94
96
|
def on_data(data)
|
95
97
|
output[:proxy_output] = data
|
98
|
+
wipe_secrets!
|
99
|
+
end
|
100
|
+
|
101
|
+
def wipe_secrets!
|
102
|
+
input.delete(:secrets)
|
103
|
+
output.delete(:secrets)
|
96
104
|
end
|
97
105
|
|
98
106
|
# @override String name of an action to be triggered on server
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ForemanTasks
|
2
2
|
require 'parse-cron'
|
3
3
|
|
4
|
-
class RecurringLogic <
|
4
|
+
class RecurringLogic < ApplicationRecord
|
5
5
|
include Authorizable
|
6
6
|
|
7
7
|
belongs_to :task_group
|
@@ -11,7 +11,7 @@ module ForemanTasks
|
|
11
11
|
if Rails::VERSION::MAJOR < 4
|
12
12
|
has_many :task_groups, :through => :tasks, :uniq => true
|
13
13
|
else
|
14
|
-
has_many :task_groups, -> {
|
14
|
+
has_many :task_groups, -> { distinct }, :through => :tasks
|
15
15
|
end
|
16
16
|
|
17
17
|
scoped_search :on => :id, :complete_value => false, :validator => ScopedSearch::Validators::INTEGER
|
data/lib/foreman_tasks/engine.rb
CHANGED
@@ -116,6 +116,7 @@ module ForemanTasks
|
|
116
116
|
initializer 'foreman_tasks.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
|
117
117
|
ForemanTasks.dynflow.require!
|
118
118
|
::ForemanTasks.dynflow.config.on_init do |world|
|
119
|
+
world.middleware.use Actions::Middleware::KeepCurrentUser
|
119
120
|
ForemanTasksCore.dynflow_setup(world)
|
120
121
|
end
|
121
122
|
end
|
@@ -22,7 +22,7 @@ module ForemanRecurringLogic
|
|
22
22
|
|
23
23
|
describe 'GET /api/recurring_logics/:id' do
|
24
24
|
it 'searches for recurring logic' do
|
25
|
-
get :show, :id => @recurring_logic.id
|
25
|
+
get :show, params: { :id => @recurring_logic.id }
|
26
26
|
assert_response :success
|
27
27
|
assert_template 'api/recurring_logics/show'
|
28
28
|
end
|
@@ -30,7 +30,7 @@ module ForemanRecurringLogic
|
|
30
30
|
|
31
31
|
describe 'POST /api/recurring_logics/:id/cancel' do
|
32
32
|
it 'cancels recurring logic' do
|
33
|
-
post :cancel, :id => @recurring_logic.id
|
33
|
+
post :cancel, params: { :id => @recurring_logic.id }
|
34
34
|
assert_response :success
|
35
35
|
@recurring_logic.reload
|
36
36
|
assert @recurring_logic.state == 'cancelled'
|
@@ -14,15 +14,13 @@ module ForemanTasks
|
|
14
14
|
describe 'GET /api/tasks/show' do
|
15
15
|
it 'searches for task' do
|
16
16
|
task = FactoryBot.create(:dynflow_task, :user_create_task)
|
17
|
-
get :show, :id => task.id
|
17
|
+
get :show, params: { :id => task.id }
|
18
18
|
assert_response :success
|
19
19
|
assert_template 'api/tasks/show'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'POST /tasks/callback' do
|
24
|
-
self.use_transactional_fixtures = false
|
25
|
-
|
26
24
|
it 'passes the data to the corresponding action' do
|
27
25
|
Support::DummyProxyAction.reset
|
28
26
|
|
@@ -37,7 +35,7 @@ module ForemanTasks
|
|
37
35
|
task.result.must_equal 'pending'
|
38
36
|
|
39
37
|
callback = Support::DummyProxyAction.proxy.log[:trigger_task].first[1][:callback]
|
40
|
-
post :callback, 'callback' => callback, 'data' => { 'result' => 'success' }
|
38
|
+
post :callback, params: { 'callback' => callback, 'data' => { 'result' => 'success' } }
|
41
39
|
triggered.finished.wait(5)
|
42
40
|
|
43
41
|
task.reload
|
@@ -5,12 +5,17 @@ module ForemanTasks
|
|
5
5
|
describe Actions::ProxyAction do
|
6
6
|
include ::Dynflow::Testing
|
7
7
|
|
8
|
+
let(:secrets) do
|
9
|
+
{ 'logins' => { 'admin' => 'changeme', 'root' => 'toor' } }
|
10
|
+
end
|
11
|
+
|
8
12
|
before do
|
9
13
|
Support::DummyProxyAction.reset
|
10
14
|
@action = create_and_plan_action(Support::DummyProxyAction,
|
11
15
|
Support::DummyProxyAction.proxy,
|
12
16
|
'Proxy::DummyAction',
|
13
|
-
'foo' => 'bar'
|
17
|
+
'foo' => 'bar',
|
18
|
+
'secrets' => secrets)
|
14
19
|
@action = run_action(@action)
|
15
20
|
end
|
16
21
|
|
@@ -19,6 +24,7 @@ module ForemanTasks
|
|
19
24
|
proxy_call = Support::DummyProxyAction.proxy.log[:trigger_task].first
|
20
25
|
expected_call = ['Proxy::DummyAction',
|
21
26
|
{ 'foo' => 'bar',
|
27
|
+
'secrets' => secrets,
|
22
28
|
'connection_options' =>
|
23
29
|
{ 'retry_interval' => 15, 'retry_count' => 4, 'timeout' => 60 },
|
24
30
|
'proxy_url' => 'proxy.example.com',
|
@@ -86,6 +92,23 @@ module ForemanTasks
|
|
86
92
|
proc { action = run_stubbed_action.call action }.must_raise(Errno::ECONNREFUSED)
|
87
93
|
action.state.must_equal :error
|
88
94
|
end
|
95
|
+
|
96
|
+
it 'hides secrets' do
|
97
|
+
triggered = ForemanTasks.dynflow.world.trigger(Support::DummyProxyAction,
|
98
|
+
Support::DummyProxyAction.proxy,
|
99
|
+
'Proxy::DummyAction',
|
100
|
+
'foo' => 'bar',
|
101
|
+
'secrets' => secrets)
|
102
|
+
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
103
|
+
task.input[:secrets].must_equal 'Secrets hidden'
|
104
|
+
triggered.future.wait # Wait for the task to get triggered before leaving the test
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'wipes secrets' do
|
108
|
+
@action.input[:secrets].must_equal secrets
|
109
|
+
action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
|
110
|
+
refute action.input.key?(:secrets)
|
111
|
+
end
|
89
112
|
end
|
90
113
|
end
|
91
114
|
end
|
@@ -88,6 +88,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
88
88
|
recurring_logic.start(::Support::DummyDynflowAction)
|
89
89
|
end
|
90
90
|
|
91
|
+
it 'has a task group associated to all tasks that were created as part of the recurring logic' do
|
92
|
+
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
93
|
+
recurring_logic.save
|
94
|
+
recurring_logic.task_group.must_be_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup
|
95
|
+
task = FactoryBot.build(:dynflow_task, :user_create_task)
|
96
|
+
task.task_groups << Support::DummyTaskGroup.new
|
97
|
+
task.save!
|
98
|
+
recurring_logic.task_group.tasks << task
|
99
|
+
recurring_logic.task_groups.must_include(*task.task_groups)
|
100
|
+
end
|
101
|
+
|
91
102
|
it 'can be created from triggering' do
|
92
103
|
triggering = FactoryBot.build(:triggering, :recurring, :end_time_limited)
|
93
104
|
logic = ForemanTasks::RecurringLogic.new_from_triggering(triggering)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks-core
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- app/lib/actions/helpers/lock.rb
|
138
138
|
- app/lib/actions/helpers/with_continuous_output.rb
|
139
139
|
- app/lib/actions/helpers/with_delegated_action.rb
|
140
|
+
- app/lib/actions/middleware/hide_secrets.rb
|
140
141
|
- app/lib/actions/middleware/inherit_task_groups.rb
|
141
142
|
- app/lib/actions/middleware/keep_current_user.rb
|
142
143
|
- app/lib/actions/middleware/rails_executor_wrap.rb
|
@@ -241,6 +242,7 @@ files:
|
|
241
242
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
242
243
|
- test/support/dummy_dynflow_action.rb
|
243
244
|
- test/support/dummy_proxy_action.rb
|
245
|
+
- test/support/dummy_task_group.rb
|
244
246
|
- test/unit/actions/action_with_sub_plans_test.rb
|
245
247
|
- test/unit/actions/proxy_action_test.rb
|
246
248
|
- test/unit/cleaner_test.rb
|
@@ -288,6 +290,7 @@ test_files:
|
|
288
290
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
289
291
|
- test/support/dummy_dynflow_action.rb
|
290
292
|
- test/support/dummy_proxy_action.rb
|
293
|
+
- test/support/dummy_task_group.rb
|
291
294
|
- test/unit/actions/action_with_sub_plans_test.rb
|
292
295
|
- test/unit/actions/proxy_action_test.rb
|
293
296
|
- test/unit/cleaner_test.rb
|