class SmartProxyDynflowCore::Launcher

Constants

CIPHERS

Public Class Methods

launch!(options) click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 12
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 46
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 56
def install_usr1_trap
  trap(:USR1) do
    Log.reopen
  end
end
load_settings!(options = {}) click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 28
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 16
def start(options)
  Settings.instance.standalone = true
  load_settings!(options)
  install_usr1_trap
  Rack::Server.new(rack_settings).start do |_server|
    SmartProxyDynflowCore::Core.ensure_initialized
    ::SdNotify.ready
  end
  Log.instance.info "Finished shutting down"
  Logging.shutdown
end

Private Instance Methods

app() click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 75
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 81
def base_settings
  {
    :app => app,
    :Host => Settings.instance.listen,
    :Port => Settings.instance.port,
    :AccessLog => [],
    :Logger => Log.instance,
    :daemonize => Settings.instance.daemonize,
    :pid => Settings.instance.daemonize && Settings.instance.pid_file,
    :server => :webrick
  }
end
https_app() click to toggle source
# File lib/smart_proxy_dynflow_core/launcher.rb, line 94
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)
  ssl_options |= OpenSSL::SSL::OP_NO_TLSv1_1 if defined?(OpenSSL::SSL::OP_NO_TLSv1_1)

  Settings.instance.tls_disabled_versions&.each do |version|
    constant = OpenSSL::SSL.const_get("OP_NO_TLSv#{version.to_s.tr('.', '_')}") 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

  {
    :SSLEnable => true,
    :SSLVerifyClient => OpenSSL::SSL::VERIFY_PEER,
    :SSLPrivateKey => ssl_private_key,
    :SSLCertificate => ssl_certificate,
    :SSLCACertificateFile => Settings.instance.ssl_ca_file,
    :SSLCiphers => CIPHERS - SmartProxyDynflowCore::Settings.instance.ssl_disabled_ciphers,
    :SSLOptions => ssl_options
  }
end
https_enabled?() click to toggle source

rubocop:enable Metrics/PerceivedComplexity

# File lib/smart_proxy_dynflow_core/launcher.rb, line 126
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 146
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.each_key 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 64
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 138
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 130
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