Class: ExperellaProxy::Configuration
- Inherits:
-
Object
- Object
- ExperellaProxy::Configuration
- Defined in:
- lib/experella-proxy/configuration.rb
Overview
The Configuration loader
The config specifies following DSL options
backend
Takes an hash defining a backend_server, see {BackendServer}
set_logger
specifies the Logger used by the program. The Logger must support debug/info/warn/error/fatal functions
set_proxy
Add proxy as Hash with :host => "string-ip/domain" and :proxy => Fixnum
The proxy will listen on every host:port hash added with this function.
set_timeout
Time as float when an idle persistent connection gets closed (no receive/send events occured)
set_error_pages
Add html error-pages to the proxy, requires 2 arguments
1st arg: the error code as Fixnum
2nd arg: path to an error page html file relative to the config file directory
Currently 404 and 503 error codes are supported
Defined Under Namespace
Classes: NoConfigError
Instance Attribute Summary collapse
-
#backends ⇒ Object
readonly
Returns the value of attribute backends.
-
#error_pages ⇒ Object
readonly
Returns the value of attribute error_pages.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#on_event ⇒ Object
readonly
Returns the value of attribute on_event.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#backend(backend_options) ⇒ Object
Adds a BackendServer specified in the config file to #backends It allows some syntactic sugar to pass :host_port as an abbrev of host and port keys separated by ‘:’.
-
#initialize(options = {}) ⇒ Configuration
constructor
The Configuration.
-
#join_config_path(filename) ⇒ String
Return filenames fullpath relative to configfile directory.
-
#read_config_file(configfile) ⇒ Boolean
Opens the given config file and evaluates it’s contents DSL.
-
#set_error_pages(key, page_path) ⇒ Object
Loads the Errorpages specified in the config file.
-
#set_logger(logger) ⇒ Object
Sets the global Logger object specified in the config file.
- #set_on_event(lambda) ⇒ Object
-
#set_proxy(proxy) ⇒ Object
Adds a Proxy specified in the config file to #proxy.
-
#set_timeout(to) ⇒ Object
Sets the Connection timeout specified in the config file.
Constructor Details
#initialize(options = {}) ⇒ Configuration
The Configuration
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/experella-proxy/configuration.rb', line 54 def initialize(={}) @backends = [] @proxy = [] @error_pages = { 404 => "", 503 => "" } @on_event = lambda{ |name, data| } = { :timeout => 15.0, :logger => Logger.new($stdout) } = .reduce({}){ |memo, (k, v)| memo[k.to_sym] = v; memo } = .merge() .each do |k, v| instance_variable_set("@#{k}", v) end read_config_file(@configfile) if @configfile ExperellaProxy.config = self end |
Instance Attribute Details
#backends ⇒ Object (readonly)
Returns the value of attribute backends.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def backends @backends end |
#error_pages ⇒ Object (readonly)
Returns the value of attribute error_pages.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def error_pages @error_pages end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def logger @logger end |
#on_event ⇒ Object (readonly)
Returns the value of attribute on_event.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def on_event @on_event end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def proxy @proxy end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
46 47 48 |
# File 'lib/experella-proxy/configuration.rb', line 46 def timeout @timeout end |
Instance Method Details
#backend(backend_options) ⇒ Object
Adds a BackendServer specified in the config file to #backends It allows some syntactic sugar to pass :host_port as an abbrev of host and port keys separated by ‘:’.
99 100 101 102 103 104 105 106 107 |
# File 'lib/experella-proxy/configuration.rb', line 99 def backend() host_port = .delete(:host_port) if host_port host, port = host_port.split(":") [:host] = host [:port] = port end @backends << end |
#join_config_path(filename) ⇒ String
Return filenames fullpath relative to configfile directory
73 74 75 |
# File 'lib/experella-proxy/configuration.rb', line 73 def join_config_path(filename) File.(File.join(File.dirname(@configfile), filename)) end |
#read_config_file(configfile) ⇒ Boolean
Opens the given config file and evaluates it’s contents DSL
81 82 83 84 85 86 87 88 89 |
# File 'lib/experella-proxy/configuration.rb', line 81 def read_config_file(configfile) unless File.exist?(configfile) puts "error reading #{configfile}" raise NoConfigError.new("unable to read config file #{configfile}") end content = File.read(configfile) instance_eval(content) true end |
#set_error_pages(key, page_path) ⇒ Object
Loads the Errorpages specified in the config file
currently 404 and 503 errors are supported
150 151 152 |
# File 'lib/experella-proxy/configuration.rb', line 150 def set_error_pages(key, page_path) @error_pages[key] = File.read(join_config_path(page_path)) end |
#set_logger(logger) ⇒ Object
Sets the global Logger object specified in the config file
Logger can be any object that responds to Ruby Loggers debug, info, warn, error, fatal functions
124 125 126 |
# File 'lib/experella-proxy/configuration.rb', line 124 def set_logger(logger) @logger = logger end |
#set_on_event(lambda) ⇒ Object
109 110 111 |
# File 'lib/experella-proxy/configuration.rb', line 109 def set_on_event(lambda) @on_event = lambda end |
#set_proxy(proxy) ⇒ Object
Adds a Proxy specified in the config file to #proxy
Multiple proxies can be added with multiple calls. Needs a Hash containing :host => “domain/ip”, :port => fixnum
136 137 138 139 140 141 142 |
# File 'lib/experella-proxy/configuration.rb', line 136 def set_proxy(proxy) if proxy[:options] && proxy[:options][:tls] proxy[:options][:private_key_file] = join_config_path(proxy[:options][:private_key_file]) proxy[:options][:cert_chain_file] = join_config_path(proxy[:options][:cert_chain_file]) end @proxy << proxy end |
#set_timeout(to) ⇒ Object
Sets the ExperellaProxy::Connection timeout specified in the config file
115 116 117 |
# File 'lib/experella-proxy/configuration.rb', line 115 def set_timeout(to) @timeout = to end |