foreman-tasks-core 0.3.2 → 0.3.3

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
  SHA256:
3
- metadata.gz: 7c036a816a81a10ce427600ce920c1aa98c59bb2c317dcba1662f906941d00e0
4
- data.tar.gz: 3e74db375442e42f0ad7e7f5887d1cd5ab79b311d86c1389f24fb5d168146a70
3
+ metadata.gz: abcc4c01c4d9f9fb4a7e005541412aade04c1b81e748895f6df4f8f43773c4e7
4
+ data.tar.gz: f96d41808af6bd9d397d3de0373fd419dec70be99d511a3b79e5115c5d8788f5
5
5
  SHA512:
6
- metadata.gz: 7c68ff530abb93733509feb1201d74c7588b1edc3e90c6caf2fd54fce11aedeb760595c2ce3fcf8f208fe5eafbc7bca00aecec08ee4b28d0b1e438c6b81938d1
7
- data.tar.gz: f1e5baa029323687099e055874464d1710ddbcc8488207fcb64bdc5f5682ff90311c8db6fbf5ce6eb372a4d9eb821df51ac26a5e151bbc6d4551983a896e6f82
6
+ metadata.gz: 9b9a6cf299314a66b853709061ad0c5c8a19f09b2d873432ff0ceb585c830fa712ac2723324dfced9c6317ab4505dcb44ca1b0ca51f442a3813dc8c3aa618702
7
+ data.tar.gz: 8ba43deac4f52417c549aafda4ef9b82e38598bca121a3ae3d33609a6ce14594a676a409b4882f367a95f7226d72bc19655262e0b9cc4140cd5ba3d0c1ae27df
@@ -17,10 +17,15 @@ module ForemanTasksCore
17
17
  @password ||= {}
18
18
  end
19
19
 
20
- def authenticate(hash)
20
+ def authenticate(hash, expected_user: nil, clear: true)
21
21
  plain = Base64.decode64(hash)
22
22
  username, otp = plain.split(':', 2)
23
- drop_otp(username, otp)
23
+ if expected_user
24
+ return false unless expected_user == username
25
+ end
26
+ password_matches = passwords[username] == otp
27
+ passwords.delete(username) if clear && password_matches
28
+ password_matches
24
29
  end
25
30
 
26
31
  def tokenize(username, password)
@@ -22,6 +22,13 @@ module ForemanTasksCore
22
22
  generate_updates
23
23
  end
24
24
 
25
+ # by default, external event just causes the refresh to be triggered: this allows the descendants
26
+ # of the Base to add custom logic to process the external events.
27
+ # Similarly as `run_refresh`, it's expected to return updates to be dispatched.
28
+ def external_event(_event)
29
+ run_refresh
30
+ end
31
+
25
32
  def start
26
33
  raise NotImplementedError
27
34
  end
@@ -69,10 +76,18 @@ module ForemanTasksCore
69
76
  end
70
77
 
71
78
  def generate_updates
72
- return {} if @continuous_output.empty? && @exit_status.nil?
79
+ return no_update if @continuous_output.empty? && @exit_status.nil?
73
80
  new_data = @continuous_output
74
81
  @continuous_output = ForemanTasksCore::ContinuousOutput.new
75
- { @suspended_action => Runner::Update.new(new_data, @exit_status) }
82
+ new_update(new_data, @exit_status)
83
+ end
84
+
85
+ def no_update
86
+ {}
87
+ end
88
+
89
+ def new_update(data, exit_status)
90
+ { @suspended_action => Runner::Update.new(data, exit_status) }
76
91
  end
77
92
 
78
93
  def initialize_continuous_outputs
@@ -37,17 +37,19 @@ module ForemanTasksCore
37
37
 
38
38
  def refresh_runner
39
39
  @logger.debug("refresh runner #{@runner.id}")
40
- updates = @runner.run_refresh
40
+ dispatch_updates(@runner.run_refresh)
41
+ ensure
42
+ @refresh_planned = false
43
+ plan_next_refresh
44
+ end
41
45
 
46
+ def dispatch_updates(updates)
42
47
  updates.each { |receiver, update| (receiver || @suspended_action) << update }
43
48
 
44
49
  # This is a workaround when the runner does not accept the suspended action
45
50
  main_key = updates.keys.any?(&:nil?) ? nil : @suspended_action
46
51
  main_process = updates[main_key]
47
52
  finish if main_process && main_process.exit_status
48
- ensure
49
- @refresh_planned = false
50
- plan_next_refresh
51
53
  end
52
54
 
53
55
  def timeout_runner
@@ -77,8 +79,8 @@ module ForemanTasksCore
77
79
  finish_termination
78
80
  end
79
81
 
80
- def external_event(_event)
81
- refresh_runner
82
+ def external_event(event)
83
+ dispatch_updates(@runner.external_event(event))
82
84
  end
83
85
 
84
86
  private
@@ -1,3 +1,3 @@
1
1
  module ForemanTasksCore
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
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.3.2
4
+ version: 0.3.3
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: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynflow
@@ -77,8 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.7.6
80
+ rubygems_version: 3.0.3
82
81
  signing_key:
83
82
  specification_version: 4
84
83
  summary: Common code used both at Forman and Foreman proxy regarding tasks