smart_proxy_dynflow_core 0.1.7 → 0.1.8

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: c84339e46cc155734611a210fb6322994a1f81c7
4
- data.tar.gz: be3d332a59589edaa862a08241e04a24910dc823
3
+ metadata.gz: d9fe367597def9db9fbd344fb30b4dd9c5d19435
4
+ data.tar.gz: 9db49d78b52c33ae93481ffa39ba66cd8bacb1c7
5
5
  SHA512:
6
- metadata.gz: 10fd1a252607ae0a5f45e29a01336f84d75776e92ff4300fb4981e6b1f78d72e8ae2c32a57d76763f81f19389a0352dca62599af92e631639903fed17dfc85f1
7
- data.tar.gz: 9e176bfa52d6f2ba282ada99839d04eaf03b5dc84285c3dd26136022efcc48775b1ba5a6a0748cf3efcad3d1b510f5a26719ac2c0792fb17ae4c56b3d735b86d
6
+ metadata.gz: fa39c7be9ff794204f60c6ace3a8e307d67316bd65c0f8a5da88423a4632b6358d9a8f405c3b94bf53c4448b415b6682e68de73330a435518448bf5f722920e9
7
+ data.tar.gz: 80e21a265765399083b5636fb1231471c67306ad6a0006af59caa50d80b1312c3c9ee650bcc07bc0337f86cb36c8609fb6d9f9a05561861a76db3a0cbe779cdc
@@ -39,3 +39,7 @@
39
39
 
40
40
  # Log level, one of UNKNOWN, FATAL, ERROR, WARN, INFO, DEBUG
41
41
  # :log_level: ERROR
42
+
43
+ # Maximum age of execution plans to keep before having them cleaned
44
+ # by the execution plan cleaner (in seconds), defaults to 24 hours
45
+ # :execution_plan_cleaner_age: 86400
@@ -10,3 +10,4 @@ require 'smart_proxy_dynflow_core/api'
10
10
  SmartProxyDynflowCore::Core.after_initialize do |dynflow_core|
11
11
  ForemanTasksCore.dynflow_setup(dynflow_core.world)
12
12
  end
13
+ SmartProxyDynflowCore::Core.register_silencer_matchers ForemanTasksCore.silent_dead_letter_matchers
@@ -7,13 +7,14 @@ module SmartProxyDynflowCore
7
7
 
8
8
  before do
9
9
  logger = Log.instance
10
- authorize_with_ssl_client
10
+ authorize_with_token || authorize_with_ssl_client
11
11
  content_type :json
12
12
  end
13
13
 
14
14
  post "/tasks/?" do
15
15
  params = MultiJson.load(request.body.read)
16
- trigger_task(::Dynflow::Utils.constantize(params['action_name']), params['action_input']).to_json
16
+ trigger_task(::Dynflow::Utils.constantize(params['action_name']),
17
+ params['action_input'].merge(:callback_host => callback_host(params, request))).to_json
17
18
  end
18
19
 
19
20
  post "/tasks/:task_id/cancel" do |task_id|
@@ -27,5 +28,16 @@ module SmartProxyDynflowCore
27
28
  get "/tasks/count" do
28
29
  tasks_count(params['state']).to_json
29
30
  end
31
+
32
+ post "/tasks/:task_id/done" do |task_id|
33
+ data = MultiJson.load(request.body.read)
34
+ complete_task(task_id, data)
35
+ end
36
+
37
+ private
38
+
39
+ def callback_host(params, request)
40
+ params.fetch('action_input', {})['proxy_url'] || request.env.values_at('HTTP_X_FORWARDED_FOR', 'HTTP_HOST').compact.first
41
+ end
30
42
  end
31
43
  end
@@ -42,6 +42,10 @@ module SmartProxyDynflowCore
42
42
  config.auto_rescue = true
43
43
  config.logger_adapter = logger_adapter
44
44
  config.persistence_adapter = persistence_adapter
45
+ config.execution_plan_cleaner = execution_plan_cleaner
46
+ # TODO: There has to be a better way
47
+ matchers = config.silent_dead_letter_matchers.call().concat(self.class.silencer_matchers)
48
+ config.silent_dead_letter_matchers = matchers
45
49
  yield config if block_given?
46
50
  end
47
51
  end
@@ -54,6 +58,14 @@ module SmartProxyDynflowCore
54
58
  end
55
59
  end
56
60
 
61
+ def execution_plan_cleaner
62
+ proc do |world|
63
+ age = Settings.instance.execution_plan_cleaner_age
64
+ options = { :poll_interval => age, :max_age => age }
65
+ ::Dynflow::Actors::ExecutionPlanCleaner.new(world, options)
66
+ end
67
+ end
68
+
57
69
  class << self
58
70
  attr_reader :instance
59
71
 
@@ -64,6 +76,14 @@ module SmartProxyDynflowCore
64
76
  @instance
65
77
  end
66
78
 
79
+ def silencer_matchers
80
+ @matchers ||= []
81
+ end
82
+
83
+ def register_silencer_matchers(matchers)
84
+ silencer_matchers.concat matchers
85
+ end
86
+
67
87
  def web_console
68
88
  require 'dynflow/web'
69
89
  dynflow_console = ::Dynflow::Web.setup do
@@ -4,6 +4,22 @@ module SmartProxyDynflowCore
4
4
  SmartProxyDynflowCore::Core.world
5
5
  end
6
6
 
7
+ def authorize_with_token
8
+ if request.env.key? 'HTTP_AUTHORIZATION'
9
+ if defined?(::ForemanTasksCore)
10
+ auth = request.env['HTTP_AUTHORIZATION']
11
+ basic_prefix = /\ABasic /
12
+ if !auth.to_s.empty? && auth =~ basic_prefix &&
13
+ ForemanTasksCore::OtpManager.authenticate(auth.gsub(basic_prefix, ''))
14
+ Log.instance.debug('authorized with token')
15
+ return true
16
+ end
17
+ end
18
+ halt 403, MultiJson.dump(:error => 'Invalid username or password supplied')
19
+ end
20
+ false
21
+ end
22
+
7
23
  def authorize_with_ssl_client
8
24
  if %w(yes on 1).include? request.env['HTTPS'].to_s
9
25
  if request.env['SSL_CLIENT_CERT'].to_s.empty?
@@ -46,5 +62,11 @@ module SmartProxyDynflowCore
46
62
  tasks = world.persistence.find_execution_plans(filter)
47
63
  { :count => tasks.count, :state => state }
48
64
  end
65
+
66
+ def complete_task(task_id, params)
67
+ world.event(task_id,
68
+ params['step_id'].to_i,
69
+ ::ForemanTasksCore::Runner::ExternalEvent.new(params))
70
+ end
49
71
  end
50
72
  end
@@ -40,13 +40,15 @@ module SmartProxyDynflowCore
40
40
  :plugins => {},
41
41
  :pid_file => '/var/run/foreman-proxy/smart_proxy_dynflow_core.pid',
42
42
  :daemonize => false,
43
+ :execution_plan_cleaner_age => 60 * 60 * 24,
43
44
  :loaded => false
44
45
  }
45
46
 
46
47
  PROXY_SETTINGS = [:ssl_ca_file, :ssl_certificate, :ssl_private_key, :foreman_url,
47
48
  :foreman_ssl_ca, :foreman_ssl_cert, :foreman_ssl_key,
48
49
  :log_file, :log_level, :ssl_disabled_ciphers]
49
- PLUGIN_SETTINGS = [:database, :core_url, :console_auth]
50
+ PLUGIN_SETTINGS = [:database, :core_url, :console_auth,
51
+ :execution_plan_cleaner_age]
50
52
 
51
53
  def initialize(settings = {})
52
54
  super(DEFAULT_SETTINGS.merge(settings))
@@ -16,6 +16,7 @@ module SmartProxyDynflowCore
16
16
  config.exit_on_terminate = false
17
17
  config.auto_terminate = false
18
18
  config.logger_adapter = ::Dynflow::LoggerAdapters::Simple.new $stderr, DYNFLOW_TESTING_LOG_LEVEL
19
+ config.execution_plan_cleaner = nil
19
20
  block.call(config) if block
20
21
  end
21
22
  end
@@ -1,3 +1,3 @@
1
1
  module SmartProxyDynflowCore
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |gem|
30
30
  gem.add_development_dependency('rack-test', '~> 0')
31
31
  gem.add_development_dependency('rubocop', '0.32.1')
32
32
 
33
- gem.add_runtime_dependency('foreman-tasks-core', '>= 0.1')
34
- gem.add_runtime_dependency('dynflow', "~> 0.8.4")
33
+ gem.add_runtime_dependency('dynflow', "~> 0.8.29")
34
+ gem.add_runtime_dependency('foreman-tasks-core', '>= 0.1.7')
35
35
  gem.add_runtime_dependency('sequel')
36
36
  gem.add_runtime_dependency('sqlite3')
37
37
  gem.add_runtime_dependency('sinatra', '~> 1.4')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dynflow_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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-08-15 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,33 +109,33 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.32.1
111
111
  - !ruby/object:Gem::Dependency
112
- name: foreman-tasks-core
112
+ name: dynflow
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.1'
117
+ version: 0.8.29
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.1'
124
+ version: 0.8.29
125
125
  - !ruby/object:Gem::Dependency
126
- name: dynflow
126
+ name: foreman-tasks-core
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.8.4
131
+ version: 0.1.7
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.8.4
138
+ version: 0.1.7
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sequel
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  requirements: []
256
256
  rubyforge_project:
257
- rubygems_version: 2.4.5
257
+ rubygems_version: 2.6.12
258
258
  signing_key:
259
259
  specification_version: 4
260
260
  summary: Dynflow runtime for Foreman smart proxy