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',
    :callback_url => 'https://127.0.0.1:8443',
    :console_auth => true,
    :foreman_url => 'http://127.0.0.1:3000',
    :listen => '127.0.0.1',
    :port => '8008',
    :use_https => false,
    :ssl_ca_file => nil,
    :ssl_private_key => nil,
    :ssl_certificate => nil,
    :standalone => false,
    :plugins => {}
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Settings

Returns a new instance of Settings.



21
22
23
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 21

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

Class Method Details

.instanceObject



25
26
27
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 25

def self.instance
  SmartProxyDynflowCore::SETTINGS
end

.load_from_proxy(plugin) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 37

def self.load_from_proxy(plugin)
  [:ssl_certificate, :ssl_ca_file, :ssl_private_key, :foreman_url].each do |key|
    SETTINGS[key] = Proxy::SETTINGS[key]
  end
  SETTINGS.callback_url = SETTINGS.foreman_url
  [:database, :core_url, :console_auth].each do |key|
    SETTINGS[key] = plugin.settings[key]
  end
  SETTINGS.plugins.values.each { |plugin| plugin.load_settings_from_proxy }
end

.load_global_settings(path) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 29

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

.load_plugin_settings(path) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 48

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

Instance Method Details

#[](key) ⇒ Object



59
60
61
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 59

def [](key)
  self.send key
end

#[]=(key, value) ⇒ Object



63
64
65
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 63

def []=(key, value)
  self.send "#{key}=", value
end

#to_hObject



67
68
69
# File 'lib/smart_proxy_dynflow_core/settings.rb', line 67

def to_h
  marshal_dump
end