Class: SmartProxyDynflowCore::Settings

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/smart_proxy_dynflow_core/settings.rb

Constant Summary collapse

DEFAULT_SETTINGS =
{
  :database => '/var/lib/foreman-proxy/dynflow/dynflow.sqlite',
  :foreman_url => 'https://127.0.0.1:3000',
  :console_auth => true,
  :listen => '127.0.0.1',
  :port => '8008',
  :use_https => false,
  :ssl_ca_file => nil,
  :ssl_private_key => nil,
  :ssl_certificate => nil,
  :ssl_disabled_ciphers => [],
  :tls_disabled_versions => [],
  :foreman_ssl_ca => nil,
  :foreman_ssl_key => nil,
  :foreman_ssl_cert => nil,
  :standalone => false,
  :log_file => '/var/log/foreman-proxy/smart_proxy_dynflow_core.log',
  :log_level => :ERROR,
  :plugins => {},
  :pid_file => '/var/run/foreman-proxy/smart_proxy_dynflow_core.pid',
  :daemonize => false,
  :execution_plan_cleaner_age => 60 * 60 * 24,
  :loaded => false
}.freeze
PROXY_SETTINGS =
i[ssl_ca_file ssl_certificate ssl_private_key foreman_url
foreman_ssl_ca foreman_ssl_cert foreman_ssl_key
log_file log_level ssl_disabled_ciphers].freeze
PLUGIN_SETTINGS =
i[database core_url console_auth
execution_plan_cleaner_age].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenStruct

#[], #[]=, #to_h

Constructor Details

#initialize(settings = {}) ⇒ Settings

Returns a new instance of Settings.



53
54
55
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 53

def initialize(settings = {})
  super(DEFAULT_SETTINGS.merge(settings))
end

Class Method Details

.instanceObject



57
58
59
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 57

def self.instance
  SmartProxyDynflowCore::SETTINGS
end

.load_from_proxy(plugin) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 75

def self.load_from_proxy(plugin)
  plugin_class = if Proxy::VERSION >= '1.16.0'
                   plugin
                 else
                   # DEPRECATION: Remove this branch when dropping support for smart-proxy < 1.16
                   plugin[:class]
                 end
  settings = plugin_class.settings.to_h
  PROXY_SETTINGS.each do |key|
    SETTINGS[key] = Proxy::SETTINGS[key]
  end
  PLUGIN_SETTINGS.each do |key|
    SETTINGS[key] = settings[key] if settings.key?(key)
  end
  SETTINGS.plugins.values.each(&:load_settings_from_proxy)
  Settings.loaded!
end

.load_global_settings(path) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 61

def self.load_global_settings(path)
  if File.exist? File.join(path)
    YAML.load_file(path).each do |key, value|
      SETTINGS[key] = value
    end
  end
end

.load_plugin_settings(path) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 93

def self.load_plugin_settings(path)
  settings = YAML.load_file(path)
  name = File.basename(path).gsub(/\.yml$/, '')
  if SETTINGS.plugins.key? name
    settings = SETTINGS.plugins[name].to_h.merge(settings)
  end
  SETTINGS.plugins[name] = OpenStruct.new settings
end

.loaded!Object



69
70
71
72
73
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 69

def self.loaded!
  Settings.instance.loaded = true
  Log.instance.info 'Settings loaded, reloading logger'
  Log.reload!
end