foreman-tasks-core 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9545fcacabab85924de6070358ad45b18b8ce0a
4
- data.tar.gz: cf563160a416cd39d7e921a10d1168293988cfc4
3
+ metadata.gz: 60626ab500ca601999a9a845896d3c63d1301a58
4
+ data.tar.gz: 6cc3e17337595942c43cd8b0a62357d235342e06
5
5
  SHA512:
6
- metadata.gz: 1f662ebb982a6545dbf65fbe8e54b97928105ec1c8e9338207ca610e486fdf706aba2a326f090c3f9ff18217b09d2f970a0aafb8719d217b802b9a429f3cdbb1
7
- data.tar.gz: a94805c8b5ce1762fc22f4d69aa0aa9ed3e93d729b46a460ef016792ab284a166055e554c59c6440b812b00355f9c1b94322ff941d7dafffb34818aa3a64187d
6
+ metadata.gz: 35ebbd1505b08a114a69469bc084194ffe5c8cfbcdabda2f2486e87cf81266917fba5efa6e715b30d283718796d0c72dad650a92daf79d125dbc5eee35a0101b
7
+ data.tar.gz: 85264cc1e14b06e715b08a1cedcfd1044cbf32442f7f09b6fae5375e684b72d513cc24d8aaafb0a3d81b47816a595ec6c8a072da09220ac22ede4d0e1a825f0b
@@ -0,0 +1,31 @@
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[username] = otp.to_s
10
+ end
11
+
12
+ def drop_otp(username, password)
13
+ passwords.delete(username) if passwords[username] == password
14
+ end
15
+
16
+ def passwords
17
+ @password ||= {}
18
+ end
19
+
20
+ def authenticate(hash)
21
+ plain = Base64.decode64(hash)
22
+ username, otp = plain.split(':', 2)
23
+ drop_otp(username, otp)
24
+ end
25
+
26
+ def tokenize(username, password)
27
+ Base64.strict_encode64("#{username}:#{password}")
28
+ end
29
+ end
30
+ end
31
+ 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.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
@@ -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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-tasks-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Common code used both at Forman and Foreman proxy regarding tasks
@@ -21,6 +21,7 @@ files:
21
21
  - LICENSE
22
22
  - lib/foreman_tasks_core.rb
23
23
  - lib/foreman_tasks_core/continuous_output.rb
24
+ - lib/foreman_tasks_core/otp_manager.rb
24
25
  - lib/foreman_tasks_core/runner.rb
25
26
  - lib/foreman_tasks_core/runner/action.rb
26
27
  - lib/foreman_tasks_core/runner/base.rb