foreman-tasks-core 0.2.0 → 0.2.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/lib/foreman_tasks_core.rb +1 -0
- data/lib/foreman_tasks_core/otp_manager.rb +28 -0
- data/lib/foreman_tasks_core/runner/action.rb +7 -0
- data/lib/foreman_tasks_core/runner/dispatcher.rb +17 -3
- data/lib/foreman_tasks_core/runner/update.rb +7 -0
- data/lib/foreman_tasks_core/ticker.rb +2 -2
- data/lib/foreman_tasks_core/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d379bbd4b42c3f19df598700caa7d9422a02d08
|
4
|
+
data.tar.gz: 10f0ab00bfcd18dbc8ea70c8611de636fb294115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6892cf7b68616b44ce3fc6c888acd03b8f4e4c28da276ec31a4cf5204469219b64a68637e6b411c09575304bb220ec8b80a7d21221761da971877d698f35dd1f
|
7
|
+
data.tar.gz: 030c20e3aefbdfb774da37e4a6207fcf509fde61e49d48507a5f746f2938174b56dade4d65ed4ac5f1bbd94b8d704519c3cbce3f35c8c6506a43bd47997db1e9
|
data/lib/foreman_tasks_core.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module ForemanTasksCore
|
5
|
+
class OtpManager
|
6
|
+
class << self
|
7
|
+
def generate_otp(username)
|
8
|
+
otp = SecureRandom.hex
|
9
|
+
@passwords ||= {}
|
10
|
+
@passwords[username] = otp.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def drop_otp(username, password)
|
14
|
+
@passwords.delete(username) if @passwords[username] == password
|
15
|
+
end
|
16
|
+
|
17
|
+
def authenticate(hash)
|
18
|
+
plain = Base64.decode64(hash)
|
19
|
+
username, otp = plain.split(':', 2)
|
20
|
+
drop_otp(username, otp)
|
21
|
+
end
|
22
|
+
|
23
|
+
def tokenize(username, password)
|
24
|
+
Base64.strict_encode64("#{username}:#{password}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -10,6 +10,8 @@ module ForemanTasksCore
|
|
10
10
|
init_run
|
11
11
|
when Runner::Update
|
12
12
|
process_update(event)
|
13
|
+
when Runner::ExternalEvent
|
14
|
+
process_external_event(event)
|
13
15
|
when ::Dynflow::Action::Cancellable::Cancel
|
14
16
|
kill_run
|
15
17
|
else
|
@@ -52,6 +54,11 @@ module ForemanTasksCore
|
|
52
54
|
output[:exit_status] = update.exit_status
|
53
55
|
end
|
54
56
|
|
57
|
+
def process_external_event(event)
|
58
|
+
runner_dispatcher.external_event(output[:runner_id], event)
|
59
|
+
suspend
|
60
|
+
end
|
61
|
+
|
55
62
|
def process_update(update)
|
56
63
|
output[:result].concat(update.continuous_output.raw_outputs)
|
57
64
|
if update.exit_status
|
@@ -10,7 +10,7 @@ module ForemanTasksCore
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class RunnerActor < ::Dynflow::Actor
|
13
|
-
def initialize(dispatcher, suspended_action, runner, clock, logger,
|
13
|
+
def initialize(dispatcher, suspended_action, runner, clock, logger, _options = {})
|
14
14
|
@dispatcher = dispatcher
|
15
15
|
@clock = clock
|
16
16
|
@ticker = dispatcher.ticker
|
@@ -18,7 +18,6 @@ module ForemanTasksCore
|
|
18
18
|
@suspended_action = suspended_action
|
19
19
|
@runner = runner
|
20
20
|
@finishing = false
|
21
|
-
@refresh_interval = options[:refresh_interval] || 1
|
22
21
|
end
|
23
22
|
|
24
23
|
def on_envelope(*args)
|
@@ -74,6 +73,10 @@ module ForemanTasksCore
|
|
74
73
|
finish_termination
|
75
74
|
end
|
76
75
|
|
76
|
+
def external_event(_event)
|
77
|
+
refresh_runner
|
78
|
+
end
|
79
|
+
|
77
80
|
private
|
78
81
|
|
79
82
|
def set_timeout
|
@@ -100,7 +103,7 @@ module ForemanTasksCore
|
|
100
103
|
@mutex = Mutex.new
|
101
104
|
@clock = clock
|
102
105
|
@logger = logger
|
103
|
-
@ticker = ::ForemanTasksCore::Ticker.spawn('dispatcher-ticker', @clock, @logger)
|
106
|
+
@ticker = ::ForemanTasksCore::Ticker.spawn('dispatcher-ticker', @clock, @logger, refresh_interval)
|
104
107
|
@runner_actors = {}
|
105
108
|
@runner_suspended_actions = {}
|
106
109
|
end
|
@@ -147,10 +150,21 @@ module ForemanTasksCore
|
|
147
150
|
end
|
148
151
|
end
|
149
152
|
|
153
|
+
def external_event(runner_id, external_event)
|
154
|
+
synchronize do
|
155
|
+
runner_actor = @runner_actors[runner_id]
|
156
|
+
runner_actor.tell([:external_event, external_event]) if runner_actor
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
150
160
|
def handle_command_exception(*args)
|
151
161
|
synchronize { _handle_command_exception(*args) }
|
152
162
|
end
|
153
163
|
|
164
|
+
def refresh_interval
|
165
|
+
1
|
166
|
+
end
|
167
|
+
|
154
168
|
private
|
155
169
|
|
156
170
|
def _finish(runner_id)
|
@@ -2,11 +2,11 @@ module ForemanTasksCore
|
|
2
2
|
class Ticker < ::Dynflow::Actor
|
3
3
|
attr_reader :clock
|
4
4
|
|
5
|
-
def initialize(clock, logger)
|
5
|
+
def initialize(clock, logger, refresh_interval)
|
6
6
|
@clock = clock
|
7
7
|
@logger = logger
|
8
8
|
@events = []
|
9
|
-
@refresh_interval =
|
9
|
+
@refresh_interval = refresh_interval
|
10
10
|
plan_next_tick
|
11
11
|
end
|
12
12
|
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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: 2017-07-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: 'Common code used both at Forman and Foreman proxy regarding tasks
|
14
|
+
|
15
|
+
'
|
15
16
|
email:
|
16
17
|
- inecas@redhat.com
|
17
18
|
executables: []
|
@@ -21,6 +22,7 @@ files:
|
|
21
22
|
- LICENSE
|
22
23
|
- lib/foreman_tasks_core.rb
|
23
24
|
- lib/foreman_tasks_core/continuous_output.rb
|
25
|
+
- lib/foreman_tasks_core/otp_manager.rb
|
24
26
|
- lib/foreman_tasks_core/runner.rb
|
25
27
|
- lib/foreman_tasks_core/runner/action.rb
|
26
28
|
- lib/foreman_tasks_core/runner/base.rb
|
@@ -50,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
52
|
version: '0'
|
51
53
|
requirements: []
|
52
54
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.6.11
|
54
56
|
signing_key:
|
55
57
|
specification_version: 4
|
56
58
|
summary: Common code used both at Forman and Foreman proxy regarding tasks
|