class SmartProxyDynflowCore::Launcher
Public Class Methods
launch!(options)
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 8 def self.launch!(options) self.new.start options end
route_mapping(rack_builder)
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 37 def self.route_mapping(rack_builder) rack_builder.map '/console' do run Core.web_console end rack_builder.map '/' do run Api end end
Public Instance Methods
install_usr1_trap()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 47 def install_usr1_trap trap(:USR1) do Log.instance.roll_log end end
load_settings!(options = {})
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 19 def load_settings!(options = {}) config_dir, one_config = options.values_at(:config_dir, :one_config) possible_config_dirs = [ '/etc/smart_proxy_dynflow_core', File.expand_path('~/.config/smart_proxy_dynflow_core'), File.join(File.dirname(__FILE__), '..', '..', 'config'), ] possible_config_dirs << config_dir if config_dir BundlerHelper.require_groups(:default) possible_config_dirs.reverse! if one_config possible_config_dirs.select { |config_dir| File.directory? config_dir }.each do |config_dir| break if load_config_dir(config_dir) && one_config end Settings.instance.daemonize = options[:daemonize] if options.key?(:daemonize) Settings.instance.pid_file = options[:pid_file] if options.key?(:pid_file) Settings.loaded! end
start(options)
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 12 def start(options) load_settings!(options) Settings.instance.standalone = true install_usr1_trap Rack::Server.new(rack_settings).start end
Private Instance Methods
app()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 66 def app Rack::Builder.new do SmartProxyDynflowCore::Launcher.route_mapping(self) end end
base_settings()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 72 def base_settings { :app => app, :Host => Settings.instance.listen, :Port => Settings.instance.port, :AccessLog => [[Log.instance, WEBrick::AccessLog::COMMON_LOG_FORMAT]], :Logger => Log.instance, :daemonize => Settings.instance.daemonize, :pid => Settings.instance.pid_file, :server => :webrick } end
https_app()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 85 def https_app ssl_options = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] ssl_options |= OpenSSL::SSL::OP_CIPHER_SERVER_PREFERENCE if defined?(OpenSSL::SSL::OP_CIPHER_SERVER_PREFERENCE) # This is required to disable SSLv3 on Ruby 1.8.7 ssl_options |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2) ssl_options |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3) ssl_options |= OpenSSL::SSL::OP_NO_TLSv1 if defined?(OpenSSL::SSL::OP_NO_TLSv1) if Settings.instance.tls_disabled_versions Settings.instance.tls_disabled_versions.each do |version| constant = OpenSSL::SSL.const_get("OP_NO_TLSv#{version.to_s.gsub(/\./, '_')}") rescue nil if constant Log.instance.info "TLSv#{version} will be disabled." ssl_options |= constant else Log.instance.warn "TLSv#{version} was not found." end end end { :SSLEnable => true, :SSLVerifyClient => OpenSSL::SSL::VERIFY_PEER, :SSLPrivateKey => ssl_private_key, :SSLCertificate => ssl_certificate, :SSLCACertificateFile => Settings.instance.ssl_ca_file, :SSLOptions => ssl_options } end
https_enabled?()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 116 def https_enabled? Settings.instance.use_https end
load_config_dir(dir)
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 134 def load_config_dir(dir) settings_yml = File.join(dir, 'settings.yml') if File.exist? settings_yml Log.instance.debug "Loading settings from #{dir}" Settings.load_global_settings settings_yml Dir[File.join(dir, 'settings.d', '*.yml')].each { |path| Settings.load_plugin_settings(path) } true end ForemanTasksCore::SettingsLoader.settings_registry.keys.each do |settings_keys| settings = settings_keys.inject({}) do |h, settings_key| if SETTINGS.plugins.key?(settings_key.to_s) h.merge(SETTINGS.plugins[settings_key.to_s].to_h) else h end end ForemanTasksCore::SettingsLoader.setup_settings(settings_keys.first, settings) end end
rack_settings()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 55 def rack_settings settings = if https_enabled? Log.instance.debug "Using HTTPS" https_app else Log.instance.debug "Using HTTP" {} end settings.merge(base_settings) end
ssl_certificate()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 127 def ssl_certificate OpenSSL::X509::Certificate.new(File.read(Settings.instance.ssl_certificate)) rescue Exception => e Log.instance.fatal "Unable to load SSL certificate. Are the values correct in settings.yml and do permissions allow reading?: #{e}" raise e end
ssl_private_key()
click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 120 def ssl_private_key OpenSSL::PKey::RSA.new(File.read(Settings.instance.ssl_private_key)) rescue Exception => e Log.instance.fatal "Unable to load private SSL key. Are the values correct in settings.yml and do permissions allow reading?: #{e}" raise e end