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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82c45ce63472dd3fa8bdc0d67753e06c71493fa9
4
- data.tar.gz: b45d72c387ea36571f352838cf56b356928f6aeb
3
+ metadata.gz: 3d379bbd4b42c3f19df598700caa7d9422a02d08
4
+ data.tar.gz: 10f0ab00bfcd18dbc8ea70c8611de636fb294115
5
5
  SHA512:
6
- metadata.gz: 7ca8912319a39eb83bbb1d278b0248ba4d285c7c930abfc2f7a203bc4e3485d2d770a228b41bb9e391b2df220a1eb979ad578b2968732766542daa0bde6338ff
7
- data.tar.gz: e6f3570c0d8aaa850c0d7a2c7e60f6168622e06c8ed5679dfc35f18c7f33ca821a9ccb3fe1e7840b2c85d98a5ef6e2cbf3f70cebd84e8859db7213d7b772000d
6
+ metadata.gz: 6892cf7b68616b44ce3fc6c888acd03b8f4e4c28da276ec31a4cf5204469219b64a68637e6b411c09575304bb220ec8b80a7d21221761da971877d698f35dd1f
7
+ data.tar.gz: 030c20e3aefbdfb774da37e4a6207fcf509fde61e49d48507a5f746f2938174b56dade4d65ed4ac5f1bbd94b8d704519c3cbce3f35c8c6506a43bd47997db1e9
@@ -2,6 +2,7 @@
2
2
  # that can be shared by the Foreman server and Foreman proxy
3
3
 
4
4
  require 'foreman_tasks_core/settings_loader'
5
+ require 'foreman_tasks_core/otp_manager'
5
6
 
6
7
  module ForemanTasksCore
7
8
  def self.dynflow_world
@@ -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, options = {})
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)
@@ -17,5 +17,12 @@ module ForemanTasksCore
17
17
  new(continuous_output, fatal ? 'EXCEPTION' : nil)
18
18
  end
19
19
  end
20
+
21
+ class ExternalEvent
22
+ attr_reader :data
23
+ def initialize(data = {})
24
+ @data = data
25
+ end
26
+ end
20
27
  end
21
28
  end
@@ -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 = 1
9
+ @refresh_interval = refresh_interval
10
10
  plan_next_tick
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module ForemanTasksCore
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
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.0
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-19 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- Common code used both at Forman and Foreman proxy regarding tasks
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.4.5
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