smart_proxy_dynflow_core 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.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/bundler.d/Gemfile.local.rb +2 -0
- data/config/settings.yml.example +2 -0
- data/deploy/smart_proxy_dynflow_core.init +95 -0
- data/deploy/smart_proxy_dynflow_core.service +14 -0
- data/lib/smart_proxy_dynflow_core.rb +1 -0
- data/lib/smart_proxy_dynflow_core/api.rb +1 -0
- data/lib/smart_proxy_dynflow_core/core.rb +6 -3
- data/lib/smart_proxy_dynflow_core/helpers.rb +2 -5
- data/lib/smart_proxy_dynflow_core/launcher.rb +9 -13
- data/lib/smart_proxy_dynflow_core/log.rb +54 -0
- data/lib/smart_proxy_dynflow_core/settings.rb +17 -3
- data/lib/smart_proxy_dynflow_core/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d120d38258eec260af438b2eadf540a2015236
|
4
|
+
data.tar.gz: a2d72f30ab1d4e7e31249f9273d5b630b4277966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67325b2dbb85f4c7a6cefcd61fc4e6b39ff529ae6478da19e32b583f347435f6cba301f9606ea6d7699557d218ac8e37701fee8009b4ec1dc9e8f24b70783183
|
7
|
+
data.tar.gz: f1ff5e54f435e69080a61c28727ec77ae68506e902bc8a3df36e170f6e827a8eb42c95093267b4d3a4a7175e8bdd813dcce454e7123e7411aba8b62e84de8803
|
data/Gemfile
CHANGED
@@ -3,11 +3,13 @@ source 'https://rubygems.org'
|
|
3
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
|
9
8
|
|
10
|
-
|
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
|
11
13
|
|
12
14
|
# load local gemfile
|
13
15
|
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local.rb')
|
data/config/settings.yml.example
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Init script for foreman smart proxy dynflow core service
|
4
|
+
#
|
5
|
+
# chkconfig: - 85 15
|
6
|
+
# description: Init script for foreman proxy dynflow core service
|
7
|
+
|
8
|
+
# Source function library.
|
9
|
+
. /etc/rc.d/init.d/functions
|
10
|
+
|
11
|
+
prog=smart_proxy_dynflow_core
|
12
|
+
RETVAL=0
|
13
|
+
SMART_PROXY_DYNFLOW_SCL_ROOT=/opt/theforeman/tfm/root
|
14
|
+
SMART_PROXY_DYNFLOW_CORE_PID=${SMART_PROXY_DYNFLOW_SCL_ROOT}/var/run/$prog/$prog.pid
|
15
|
+
SMART_PROXY_DYNFLOW_CORE_USER=${SMART_PROXY_DYNFLOW_CORE_USER:-foreman-proxy}
|
16
|
+
|
17
|
+
. /opt/theforeman/tfm/service-environment
|
18
|
+
. scl_source enable $TFM_SCLS_ENABLED
|
19
|
+
|
20
|
+
start() {
|
21
|
+
echo -n $"Starting $prog: "
|
22
|
+
daemon --user ${SMART_PROXY_DYNFLOW_CORE_USER} ${SMART_PROXY_DYNFLOW_SCL_ROOT}/usr/bin/smart_proxy_dynflow_core > /dev/null
|
23
|
+
RETVAL=$?
|
24
|
+
if [ $RETVAL = 0 ]
|
25
|
+
then
|
26
|
+
echo_success
|
27
|
+
else
|
28
|
+
echo_failure
|
29
|
+
fi
|
30
|
+
|
31
|
+
echo
|
32
|
+
return $RETVAL
|
33
|
+
}
|
34
|
+
|
35
|
+
stop() {
|
36
|
+
echo -n $"Stopping $prog: "
|
37
|
+
if [ -f ${SMART_PROXY_DYNFLOW_CORE_PID} ]; then
|
38
|
+
killproc -p ${SMART_PROXY_DYNFLOW_CORE_PID}
|
39
|
+
RETVAL=$?
|
40
|
+
else
|
41
|
+
echo -n $"$prog was not running.";
|
42
|
+
failure $"$prog was not running.";
|
43
|
+
echo
|
44
|
+
return 1
|
45
|
+
fi
|
46
|
+
echo
|
47
|
+
[ $RETVAL -eq 0 ] && rm -f ${SMART_PROXY_DYNFLOW_CORE_PID}
|
48
|
+
return $RETVAL
|
49
|
+
}
|
50
|
+
|
51
|
+
logrotate() {
|
52
|
+
echo -n $"Rotating logs for $prog: "
|
53
|
+
if [ -f ${SMART_PROXY_DYNFLOW_CORE_PID} ]; then
|
54
|
+
killproc -p ${SMART_PROXY_DYNFLOW_CORE_PID} $prog -USR1
|
55
|
+
RETVAL=$?
|
56
|
+
echo
|
57
|
+
else
|
58
|
+
echo -n $"$prog was not running.";
|
59
|
+
failure $"$prog was not running.";
|
60
|
+
echo
|
61
|
+
return 1
|
62
|
+
fi
|
63
|
+
return $RETVAL
|
64
|
+
}
|
65
|
+
|
66
|
+
# See how we were called.
|
67
|
+
case "$1" in
|
68
|
+
start)
|
69
|
+
start
|
70
|
+
;;
|
71
|
+
stop)
|
72
|
+
stop
|
73
|
+
;;
|
74
|
+
status)
|
75
|
+
echo -n "$prog"
|
76
|
+
status -p $SMART_PROXY_DYNFLOW_CORE_PID
|
77
|
+
RETVAL=$?
|
78
|
+
;;
|
79
|
+
restart)
|
80
|
+
stop
|
81
|
+
start
|
82
|
+
;;
|
83
|
+
condrestart)
|
84
|
+
stop
|
85
|
+
[ $? -eq 0 ] && start
|
86
|
+
;;
|
87
|
+
logrotate)
|
88
|
+
logrotate
|
89
|
+
;;
|
90
|
+
*)
|
91
|
+
echo $"Usage: $prog {start|stop|restart|condrestart|logrotate}"
|
92
|
+
exit 1
|
93
|
+
esac
|
94
|
+
|
95
|
+
exit $RETVAL
|
@@ -0,0 +1,14 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description=Foreman smart proxy dynflow core service
|
3
|
+
Documentation=https://github.com/theforeman/smart_proxy_dynflow
|
4
|
+
After=network.target remote-fs.target nss-lookup.target
|
5
|
+
|
6
|
+
[Service]
|
7
|
+
Type=simple
|
8
|
+
User=foreman-proxy
|
9
|
+
PIDFile=/opt/theforeman/tfm/root/var/run/smart_proxy_dynflow_core/smart_proxy_dynflow_core.pid
|
10
|
+
EnvironmentFile=/opt/theforeman/tfm/service-environment
|
11
|
+
ExecStart=/usr/bin/scl enable $TFM_SCLS_ENABLED -- /opt/theforeman/tfm/root/usr/bin/smart_proxy_dynflow_core
|
12
|
+
|
13
|
+
[Install]
|
14
|
+
WantedBy=multi-user.target
|
@@ -18,8 +18,7 @@ module SmartProxyDynflowCore
|
|
18
18
|
|
19
19
|
db_file = Settings.instance.database
|
20
20
|
if db_file.nil? || db_file.empty?
|
21
|
-
#
|
22
|
-
STDERR.puts "Could not open DB for dynflow at '#{db_file}', will keep data in memory. Restart will drop all dynflow data."
|
21
|
+
Log.instance.warn "Could not open DB for dynflow at '#{db_file}', will keep data in memory. Restart will drop all dynflow data."
|
23
22
|
else
|
24
23
|
db_conn_string += "/#{db_file}"
|
25
24
|
end
|
@@ -41,7 +40,11 @@ module SmartProxyDynflowCore
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def logger_adapter
|
44
|
-
|
43
|
+
if Settings.instance.standalone
|
44
|
+
Log::ProxyAdapter.new(Log.instance, Log.instance.level)
|
45
|
+
else
|
46
|
+
Log::ProxyAdapter.new(Proxy::LogBuffer::Decorator.instance, Log.instance.level)
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
class << self
|
@@ -8,14 +8,11 @@ module SmartProxyDynflowCore
|
|
8
8
|
if %w(yes on 1).include? request.env['HTTPS'].to_s
|
9
9
|
if request.env['SSL_CLIENT_CERT'].to_s.empty?
|
10
10
|
status 403
|
11
|
-
|
12
|
-
STDERR.puts "No client SSL certificate supplied"
|
11
|
+
Log.instance.error "No client SSL certificate supplied"
|
13
12
|
halt MultiJson.dump(:error => "No client SSL certificate supplied")
|
14
13
|
end
|
15
14
|
else
|
16
|
-
|
17
|
-
# logger.debug('require_ssl_client_verification: skipping, non-HTTPS request')
|
18
|
-
puts 'require_ssl_client_verification: skipping, non-HTTPS request'
|
15
|
+
Log.instance.debug 'require_ssl_client_verification: skipping, non-HTTPS request'
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
@@ -27,6 +27,7 @@ module SmartProxyDynflowCore
|
|
27
27
|
possible_config_dirs.select { |config_dir| File.directory? config_dir }.each do |config_dir|
|
28
28
|
break if load_config_dir(config_dir) && one_config
|
29
29
|
end
|
30
|
+
Settings.loaded!
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.route_mapping(rack_builder)
|
@@ -43,12 +44,10 @@ module SmartProxyDynflowCore
|
|
43
44
|
|
44
45
|
def rack_settings
|
45
46
|
settings = if https_enabled?
|
46
|
-
|
47
|
-
puts "Using HTTPS"
|
47
|
+
Log.instance.debug "Using HTTPS"
|
48
48
|
https_app
|
49
49
|
else
|
50
|
-
|
51
|
-
puts "Using HTTP"
|
50
|
+
Log.instance.debug "Using HTTP"
|
52
51
|
{}
|
53
52
|
end
|
54
53
|
settings.merge(base_settings)
|
@@ -65,7 +64,9 @@ module SmartProxyDynflowCore
|
|
65
64
|
:app => app,
|
66
65
|
:Host => Settings.instance.listen,
|
67
66
|
:Port => Settings.instance.port,
|
68
|
-
:daemonize => false
|
67
|
+
:daemonize => false,
|
68
|
+
:AccessLog => [[Log.log_file, WEBrick::AccessLog::COMMON_LOG_FORMAT]],
|
69
|
+
:Logger => Log.instance
|
69
70
|
}
|
70
71
|
end
|
71
72
|
|
@@ -94,26 +95,21 @@ module SmartProxyDynflowCore
|
|
94
95
|
def ssl_private_key
|
95
96
|
OpenSSL::PKey::RSA.new(File.read(Settings.instance.ssl_private_key))
|
96
97
|
rescue Exception => e
|
97
|
-
|
98
|
-
STDERR.puts "Unable to load private SSL key. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
99
|
-
# logger.error "Unable to load private SSL key. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
98
|
+
Log.instance.fatal "Unable to load private SSL key. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
100
99
|
raise e
|
101
100
|
end
|
102
101
|
|
103
102
|
def ssl_certificate
|
104
103
|
OpenSSL::X509::Certificate.new(File.read(Settings.instance.ssl_certificate))
|
105
104
|
rescue Exception => e
|
106
|
-
|
107
|
-
STDERR.puts "Unable to load SSL certificate. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
108
|
-
# logger.error "Unable to load SSL certificate. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
105
|
+
Log.instance.fatal "Unable to load SSL certificate. Are the values correct in settings.yml and do permissions allow reading?: #{e}"
|
109
106
|
raise e
|
110
107
|
end
|
111
108
|
|
112
109
|
def load_config_dir(dir)
|
113
110
|
settings_yml = File.join(dir, 'settings.yml')
|
114
111
|
if File.exist? settings_yml
|
115
|
-
|
116
|
-
puts "Loading settings from #{dir}"
|
112
|
+
Log.instance.debug "Loading settings from #{dir}"
|
117
113
|
Settings.load_global_settings settings_yml
|
118
114
|
Dir[File.join(dir, 'settings.d', '*.yml')].each { |path| Settings.load_plugin_settings(path) }
|
119
115
|
true
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'dynflow'
|
3
|
+
|
4
|
+
module SmartProxyDynflowCore
|
5
|
+
class Log < ::Logger
|
6
|
+
|
7
|
+
alias_method :write, :debug
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def instance
|
11
|
+
if @logger.nil?
|
12
|
+
@logger = Logger.new log_file
|
13
|
+
@logger.level = log_level
|
14
|
+
end
|
15
|
+
@logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def instance=(logger)
|
19
|
+
@logger = logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def reload!
|
23
|
+
@logger = nil
|
24
|
+
instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_level
|
28
|
+
if Settings.instance.loaded && Settings.instance.log_level
|
29
|
+
::Logger.const_get(Settings.instance.log_level.upcase)
|
30
|
+
else
|
31
|
+
Logger::WARN
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_file
|
36
|
+
if Settings.instance.loaded && Settings.instance.log_file
|
37
|
+
Settings.instance.log_file
|
38
|
+
else
|
39
|
+
$stdout
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ProxyAdapter < ::Dynflow::LoggerAdapters::Simple
|
45
|
+
def initialize(logger, level = Logger::DEBUG, formatters = [::Dynflow::LoggerAdapters::Formatters::Exception])
|
46
|
+
@logger = logger
|
47
|
+
@logger.level = level
|
48
|
+
@logger.formatter = method(:formatter).to_proc
|
49
|
+
@action_logger = apply_formatters ProgNameWrapper.new(@logger, ' action'), formatters
|
50
|
+
@dynflow_logger = apply_formatters ProgNameWrapper.new(@logger, 'dynflow'), formatters
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -15,9 +15,16 @@ module SmartProxyDynflowCore
|
|
15
15
|
:ssl_private_key => nil,
|
16
16
|
:ssl_certificate => nil,
|
17
17
|
:standalone => false,
|
18
|
-
:
|
18
|
+
:log_file => '/var/log/foreman-proxy/smart_proxy_dynflow_core.log',
|
19
|
+
:log_level => :ERROR,
|
20
|
+
:plugins => {},
|
21
|
+
:loaded => false
|
19
22
|
}
|
20
23
|
|
24
|
+
PROXY_SETTINGS = [:ssl_certificate, :ssl_ca_file, :ssl_private_key, :foreman_url,
|
25
|
+
:log_file, :log_level]
|
26
|
+
PLUGIN_SETTINGS = [:database, :core_url, :console_auth]
|
27
|
+
|
21
28
|
def initialize(settings = {})
|
22
29
|
super(DEFAULT_SETTINGS.merge(settings))
|
23
30
|
end
|
@@ -34,15 +41,22 @@ module SmartProxyDynflowCore
|
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
44
|
+
def self.loaded!
|
45
|
+
Settings.instance.loaded = true
|
46
|
+
Log.instance.info 'Settings loaded, reloading logger'
|
47
|
+
Log.reload!
|
48
|
+
end
|
49
|
+
|
37
50
|
def self.load_from_proxy(plugin)
|
38
|
-
|
51
|
+
PROXY_SETTINGS.each do |key|
|
39
52
|
SETTINGS[key] = Proxy::SETTINGS[key]
|
40
53
|
end
|
41
54
|
SETTINGS.callback_url = SETTINGS.foreman_url
|
42
|
-
|
55
|
+
PLUGIN_SETTINGS.each do |key|
|
43
56
|
SETTINGS[key] = plugin.settings[key]
|
44
57
|
end
|
45
58
|
SETTINGS.plugins.values.each { |plugin| plugin.load_settings_from_proxy }
|
59
|
+
Settings.loaded!
|
46
60
|
end
|
47
61
|
|
48
62
|
def self.load_plugin_settings(path)
|
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.0
|
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-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -192,7 +192,8 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description:
|
195
|
+
description: |2
|
196
|
+
Use the Dynflow inside Foreman smart proxy
|
196
197
|
email:
|
197
198
|
- inecas@redhat.com
|
198
199
|
executables: []
|
@@ -202,8 +203,11 @@ files:
|
|
202
203
|
- Gemfile
|
203
204
|
- LICENSE
|
204
205
|
- bin/smart_proxy_dynflow_core
|
206
|
+
- bundler.d/Gemfile.local.rb
|
205
207
|
- bundler.d/dynflow.rb
|
206
208
|
- config/settings.yml.example
|
209
|
+
- deploy/smart_proxy_dynflow_core.init
|
210
|
+
- deploy/smart_proxy_dynflow_core.service
|
207
211
|
- lib/smart_proxy_dynflow_core.rb
|
208
212
|
- lib/smart_proxy_dynflow_core/api.rb
|
209
213
|
- lib/smart_proxy_dynflow_core/bundler_helper.rb
|
@@ -211,6 +215,7 @@ files:
|
|
211
215
|
- lib/smart_proxy_dynflow_core/core.rb
|
212
216
|
- lib/smart_proxy_dynflow_core/helpers.rb
|
213
217
|
- lib/smart_proxy_dynflow_core/launcher.rb
|
218
|
+
- lib/smart_proxy_dynflow_core/log.rb
|
214
219
|
- lib/smart_proxy_dynflow_core/settings.rb
|
215
220
|
- lib/smart_proxy_dynflow_core/testing.rb
|
216
221
|
- lib/smart_proxy_dynflow_core/version.rb
|
@@ -234,9 +239,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
239
|
version: '0'
|
235
240
|
requirements: []
|
236
241
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.4.
|
242
|
+
rubygems_version: 2.4.5
|
238
243
|
signing_key:
|
239
244
|
specification_version: 4
|
240
245
|
summary: Dynflow runtime for Foreman smart proxy
|
241
246
|
test_files: []
|
242
|
-
has_rdoc:
|