smart_proxy_dynflow 0.0.7 → 0.1.0

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.

Potentially problematic release.


This version of smart_proxy_dynflow might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f221eefabe56231e87a47f714392de1ed7950a71
4
- data.tar.gz: 28285f63711d4a1d09870fed5eb370f50c0018ed
3
+ metadata.gz: 70eb62fce2c543540e5d04d827b1ec194bfac33a
4
+ data.tar.gz: 14c6c306bba19a1cd0713d9dcc3e2a511cf7d939
5
5
  SHA512:
6
- metadata.gz: 4576962a886a5796893d6aab6abe8c93880012bf1ddfb35f0d6054e74807ef43e050b05ca9b6239f5939a1f398834cb6fff17b4081eb175aeced8a2719f78f2d
7
- data.tar.gz: a489339da001945d82eecbe42ab6293d60b19df310d8b672348b79e8fcd5a4fa69a53d45343c261b9fb2fbca88f7e5b5b5492ee4f3e618078f6b117b996b448d
6
+ metadata.gz: 34d9077cc156dc410786f2631036814e41e4994b2566f5e383fc989c80e47bfc94a9e57c4b846ab2418fc511fc225d10376e2708148af15f89ac9a8464cdbe5b
7
+ data.tar.gz: 4589e4d45eeddc1dd04740d419cd15ff47afd50b70934183c2477f93573e8816ed16333721e825881faadce4e0976a67cf1c7038d4c98e0b44b7989c5b8cb869
data/Gemfile CHANGED
@@ -1,8 +1,16 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec :name => 'smart_proxy_dynflow_core'
4
4
 
5
5
  group :development do
6
- gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy", :branch => "develop"
7
6
  gem 'pry'
8
7
  end
8
+
9
+ group :test do
10
+ gem 'smart_proxy_dynflow', :path => '.'
11
+ gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy", :branch => "develop"
12
+ end
13
+
14
+ # load local gemfile
15
+ local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local.rb')
16
+ self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
@@ -0,0 +1,2 @@
1
+ gem 'pry'
2
+ gem 'smart_proxy_remote_execution_ssh_core', :path => '../smart_proxy_remote_execution_ssh'
@@ -1,31 +1,34 @@
1
+ require 'sinatra/base'
2
+ require 'proxy/helpers'
3
+ require 'sinatra/authorization'
1
4
  module Proxy
2
5
  class Dynflow
3
6
  class Api < ::Sinatra::Base
4
7
  helpers ::Proxy::Helpers
5
8
  helpers ::Proxy::Dynflow::Helpers
9
+ extend ::Sinatra::Authorization
6
10
 
7
11
  authorize_with_trusted_hosts
8
12
  authorize_with_ssl_client
9
13
 
10
14
  before do
15
+ logger = Proxy::LogBuffer::Decorator.instance
11
16
  content_type :json
12
17
  end
13
18
 
14
- post "/tasks/?" do
15
- params = parse_json_body
16
- trigger_task(::Dynflow::Utils.constantize(params['action_name']), params['action_input']).to_json
19
+ post "/tasks/callback" do
20
+ response = Proxy::Dynflow::Callback::Request.send_to_foreman_tasks(request.body.read)
21
+ logger.info "Callback to foreman #{response.code} - #{response}"
22
+ status response.code
23
+ body response.body
17
24
  end
18
25
 
19
- post "/tasks/:task_id/cancel" do |task_id|
20
- cancel_task(task_id).to_json
26
+ post "/*" do
27
+ relay_request
21
28
  end
22
29
 
23
- get "/tasks/:task_id/status" do |task_id|
24
- task_status(task_id).to_json
25
- end
26
-
27
- get "/tasks/count" do
28
- tasks_count(params['state']).to_json
30
+ get "/*" do
31
+ relay_request
29
32
  end
30
33
  end
31
34
  end
@@ -4,8 +4,7 @@ module Proxy
4
4
  class Dynflow
5
5
  module Callback
6
6
  class Request < Proxy::HttpRequest::ForemanRequest
7
- def callback(callback, data)
8
- payload = { :callback => callback, :data => data }.to_json
7
+ def callback(payload)
9
8
  response = send_request(request_factory.create_post('foreman_tasks/api/tasks/callback', payload))
10
9
  if response.code != "200"
11
10
  raise "Failed performing callback to Foreman server: #{response.code} #{response.body}"
@@ -13,28 +12,32 @@ module Proxy
13
12
  response
14
13
  end
15
14
 
16
- def self.send_to_foreman_tasks(callback, data)
17
- self.new.callback(callback, data)
15
+ def self.send_to_foreman_tasks(payload)
16
+ self.new.callback(payload)
18
17
  end
19
18
  end
20
19
 
21
- class Action < ::Dynflow::Action
22
- def plan(callback, data)
23
- plan_self(:callback => callback, :data => data)
20
+ class Core < Proxy::HttpRequest::ForemanRequest
21
+ def uri
22
+ @uri ||= URI.parse Proxy::Dynflow::Plugin.settings.core_url
24
23
  end
25
24
 
26
- def run
27
- Callback::Request.send_to_foreman_tasks(input[:callback], input[:data])
25
+ def relay(request, from, to)
26
+ path = request.path.gsub(from, to)
27
+ Proxy::LogBuffer::Decorator.instance.debug "Proxy request from #{request.host_with_port}#{request.path} to #{uri.to_s}#{path}"
28
+ req = case request.env['REQUEST_METHOD']
29
+ when 'GET'
30
+ request_factory.create_get path, request.env['rack.request.query_hash']
31
+ when 'POST'
32
+ request_factory.create_post path, request.body.read
33
+ end
34
+ response = send_request req
35
+ Proxy::LogBuffer::Decorator.instance.debug "Proxy request status #{response.code} - #{response}"
36
+ response
28
37
  end
29
- end
30
-
31
- module PlanHelper
32
- def plan_with_callback(input)
33
- input = input.dup
34
- callback = input.delete('callback')
35
38
 
36
- planned_action = plan_self(input)
37
- plan_action(::Proxy::Dynflow::Callback::Action, callback, planned_action.output) if callback
39
+ def self.relay(request, from, to)
40
+ self.new.relay request, from, to
38
41
  end
39
42
  end
40
43
  end
@@ -1,34 +1,11 @@
1
1
  module Proxy
2
2
  class Dynflow
3
3
  module Helpers
4
- def world
5
- Proxy::Dynflow.world
6
- end
7
-
8
- def trigger_task(*args)
9
- triggered = world.trigger(*args)
10
- { :task_id => triggered.id }
11
- end
12
-
13
- def cancel_task(task_id)
14
- execution_plan = world.persistence.load_execution_plan(task_id)
15
- cancel_events = execution_plan.cancel
16
- { :task_id => task_id, :canceled_steps_count => cancel_events.size }
17
- end
18
-
19
- def task_status(task_id)
20
- ep = world.persistence.load_execution_plan(task_id)
21
- ep.to_hash.merge(:actions => ep.actions.map(&:to_hash))
22
- rescue KeyError => e
23
- status 404
24
- {}
25
- end
26
-
27
- def tasks_count(state)
28
- state ||= 'all'
29
- filter = state != 'all' ? { :filters => { :state => [state] } } : {}
30
- tasks = world.persistence.find_execution_plans(filter)
31
- { :count => tasks.count, :state => state }
4
+ def relay_request(from = /^\/dynflow/, to = '')
5
+ response = Proxy::Dynflow::Callback::Core.relay(request, from, to)
6
+ content_type response.content_type
7
+ status response.code
8
+ body response.body
32
9
  end
33
10
  end
34
11
  end
@@ -1,10 +1,6 @@
1
1
  require 'smart_proxy_dynflow/api'
2
2
 
3
3
  map "/dynflow" do
4
- map '/console' do
5
- run Proxy::Dynflow.web_console
6
- end
7
-
8
4
  map '/'do
9
5
  run Proxy::Dynflow::Api
10
6
  end
@@ -0,0 +1,8 @@
1
+ require 'smart_proxy_dynflow_core/api'
2
+ require 'smart_proxy_dynflow_core/launcher'
3
+
4
+ SmartProxyDynflowCore::Settings.load_from_proxy(p)
5
+
6
+ map "/dynflow" do
7
+ SmartProxyDynflowCore::Launcher.route_mapping(self)
8
+ end
@@ -1,11 +1,21 @@
1
+ require 'proxy/log'
2
+ require 'proxy/pluggable'
3
+ require 'proxy/plugin'
4
+
1
5
  class Proxy::Dynflow
2
6
  class Plugin < Proxy::Plugin
3
- http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__))
4
- https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__))
7
+ rackup_path = begin
8
+ require 'smart_proxy_dynflow_core'
9
+ 'http_config_with_executor.ru'
10
+ rescue LoadError
11
+ 'http_config.ru'
12
+ end
13
+ http_rackup_path File.expand_path(rackup_path, File.expand_path("../", __FILE__))
14
+ https_rackup_path File.expand_path(rackup_path, File.expand_path("../", __FILE__))
5
15
 
6
16
  settings_file "dynflow.yml"
7
- default_settings :database => '/var/lib/foreman-proxy/dynflow/dynflow.sqlite'
8
17
  default_settings :console_auth => true
18
+ default_settings :core_url => 'http://localhost:8008'
9
19
  plugin :dynflow, Proxy::Dynflow::VERSION
10
20
  end
11
21
  end
@@ -0,0 +1,10 @@
1
+ module Proxy
2
+ class Dynflow
3
+ class ProxyAdapter < ::Dynflow::LoggerAdapters::Simple
4
+ def initialize(logger, level = Logger::DEBUG, formatters = [Formatters::Exception])
5
+ super(nil, level, formatters)
6
+ @logger = logger
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  class Dynflow
3
- VERSION = '0.0.7'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -1,94 +1,5 @@
1
- require 'dynflow'
2
-
3
1
  require 'smart_proxy_dynflow/version'
4
2
  require 'smart_proxy_dynflow/plugin'
5
3
  require 'smart_proxy_dynflow/callback'
6
4
  require 'smart_proxy_dynflow/helpers'
7
-
8
- class Proxy::Dynflow
9
- attr_accessor :world
10
-
11
- def initialize
12
- @world = create_world
13
- end
14
-
15
- def create_world(&block)
16
- config = default_world_config(&block)
17
- ::Dynflow::World.new(config)
18
- end
19
-
20
- def persistence_conn_string
21
- db_conn_string = 'sqlite:/'
22
-
23
- db_file = Proxy::Dynflow::Plugin.settings.database
24
- if db_file.nil? || db_file.empty?
25
- Proxy::Log.logger.warn "Could not open DB for dynflow at '#{db_file}', will keep data in memory. Restart will drop all dynflow data."
26
- else
27
- db_conn_string += "/#{db_file}"
28
- end
29
-
30
- ENV['DYNFLOW_DB_CONN_STRING'] || db_conn_string
31
- end
32
-
33
- def persistence_adapter
34
- ::Dynflow::PersistenceAdapters::Sequel.new persistence_conn_string
35
- end
36
-
37
- def default_world_config
38
- ::Dynflow::Config.new.tap do |config|
39
- config.auto_rescue = true
40
- config.logger_adapter = logger_adapter
41
- config.persistence_adapter = persistence_adapter
42
- yield config if block_given?
43
- end
44
- end
45
-
46
- def logger_adapter
47
- ::Dynflow::LoggerAdapters::Simple.new $stderr, 0
48
- end
49
-
50
- class << self
51
- attr_reader :instance
52
-
53
- def ensure_initialized
54
- return @instance if @instance
55
- @instance = Proxy::Dynflow.new
56
- after_initialize_blocks.each(&:call)
57
- @instance
58
- end
59
-
60
- def web_console
61
- require 'dynflow/web'
62
- dynflow_console = ::Dynflow::Web.setup do
63
- # we can't use the proxy's after_actionvation hook, as
64
- # it happens before the Daemon forks the process (including
65
- # closing opened file descriptors)
66
- # TODO: extend smart proxy to enable hooks that happen after
67
- # the forking
68
-
69
- if Proxy::Dynflow::Plugin.settings.console_auth
70
- authorize_with_trusted_hosts
71
- authorize_with_ssl_client
72
- end
73
-
74
- Proxy::Dynflow.ensure_initialized
75
- set :world, Proxy::Dynflow.world
76
- end
77
- dynflow_console
78
- end
79
-
80
- def world
81
- instance.world
82
- end
83
-
84
- def after_initialize(&block)
85
- after_initialize_blocks << block
86
- end
87
-
88
- private
89
-
90
- def after_initialize_blocks
91
- @after_initialize_blocks ||= []
92
- end
93
- end
94
- end
5
+ require 'smart_proxy_dynflow/api'
@@ -2,3 +2,4 @@
2
2
  :enabled: true
3
3
  :database: /var/lib/foreman-proxy/dynflow/dynflow.sqlite
4
4
  :console_auth: true
5
+ :core_url: 'http://127.0.0.1:8008'
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dynflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
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: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack-test
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
@@ -108,48 +108,6 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.32.1
111
- - !ruby/object:Gem::Dependency
112
- name: dynflow
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: 0.8.4
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ~>
123
- - !ruby/object:Gem::Version
124
- version: 0.8.4
125
- - !ruby/object:Gem::Dependency
126
- name: sequel
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: sqlite3
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '>='
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
111
  description: |2
154
112
  Use the Dynflow inside Foreman smart proxy
155
113
  email:
@@ -160,14 +118,16 @@ extra_rdoc_files: []
160
118
  files:
161
119
  - Gemfile
162
120
  - LICENSE
121
+ - bundler.d/Gemfile.local.rb
163
122
  - bundler.d/dynflow.rb
164
123
  - lib/smart_proxy_dynflow.rb
165
124
  - lib/smart_proxy_dynflow/api.rb
166
125
  - lib/smart_proxy_dynflow/callback.rb
167
126
  - lib/smart_proxy_dynflow/helpers.rb
168
127
  - lib/smart_proxy_dynflow/http_config.ru
128
+ - lib/smart_proxy_dynflow/http_config_with_executor.ru
169
129
  - lib/smart_proxy_dynflow/plugin.rb
170
- - lib/smart_proxy_dynflow/testing.rb
130
+ - lib/smart_proxy_dynflow/proxy_adapter.rb
171
131
  - lib/smart_proxy_dynflow/version.rb
172
132
  - settings.d/dynflow.yml.example
173
133
  homepage: https://github.com/theforeman/smart_proxy_dynflow
@@ -180,17 +140,17 @@ require_paths:
180
140
  - lib
181
141
  required_ruby_version: !ruby/object:Gem::Requirement
182
142
  requirements:
183
- - - '>='
143
+ - - ">="
184
144
  - !ruby/object:Gem::Version
185
145
  version: '0'
186
146
  required_rubygems_version: !ruby/object:Gem::Requirement
187
147
  requirements:
188
- - - '>='
148
+ - - ">="
189
149
  - !ruby/object:Gem::Version
190
150
  version: '0'
191
151
  requirements: []
192
152
  rubyforge_project:
193
- rubygems_version: 2.4.8
153
+ rubygems_version: 2.4.5
194
154
  signing_key:
195
155
  specification_version: 4
196
156
  summary: Dynflow runtime for Foreman smart proxy
@@ -1,28 +0,0 @@
1
- require 'dynflow/testing'
2
-
3
- unless defined? DYNFLOW_TESTING_LOG_LEVEL
4
- DYNFLOW_TESTING_LOG_LEVEL = 4
5
- end
6
-
7
- module Proxy
8
- class Dynflow
9
- # Helper for usage in other dependent plugins that need Dynflow
10
- # related things, such as testing instance of world etc.
11
- module Testing
12
- class << self
13
- def create_world(&block)
14
- Proxy::Dynflow::Plugin.settings.database = nil
15
- Proxy::Dynflow.ensure_initialized
16
- Proxy::Dynflow.instance.create_world do |config|
17
- config.exit_on_terminate = false
18
- config.auto_terminate = false
19
- config.logger_adapter = ::Dynflow::LoggerAdapters::Simple.new $stderr, DYNFLOW_TESTING_LOG_LEVEL
20
- block.call(config) if block
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
-
28
- Concurrent.disable_at_exit_handlers!