lib/conf/default.rb in rsence-2.0.0.6.pre vs lib/conf/default.rb in rsence-2.0.0.7.pre
- old
+ new
@@ -11,28 +11,31 @@
require 'rubygems'
require 'rack'
require 'yaml'
if RUBY_VERSION.to_f >= 1.9
- # Encoding.default_external = Encoding::BINARY
- # Encoding.default_internal = Encoding::BINARY
+ # --
+ # Ruby 1.9 encoding defaults.
+ # This is clearly not enough but a good start for fixing the encoding madness.
+ # ++
+ Encoding.default_external = Encoding::BINARY
+ Encoding.default_internal = Encoding::BINARY
+ # --
+ # Ruby 1.9 doesn't have String#each anymore.
+ # This is a backwards-compatible work-around.
+ # ++
class String
def each
self.split($/).each { |e| yield e }
end
end
end
-# Legacy:
-LIB_PATHS = []
-PIDPATH = File.join(SERVER_PATH,'var','run')
-LOGPATH = File.join(SERVER_PATH,'var','log')
-def load_legacy( local_config_file_path )
- require local_config_file_path[0..-4]
-end
-
+# Configuration handles config files and such.
class Configuration
+
+ # Method for combining two arrays
def array_merge( target, source )
source.each do |item|
unless target.include?(item)
if item.class == Array
sub_arr = []
@@ -46,10 +49,12 @@
target.push( item )
end
end
end
end
+
+ # Method for combining two hashes.
def hash_merge( target, source )
source.each do |key,item|
if not target.has_key?key or target[key] != item
if item.class == Array
target[key] = [] unless target.has_key?(key)
@@ -61,122 +66,117 @@
target[key] = item
end
end
end
end
- def wizard
- puts "Please answer the following questions, blank lines equal to the default in brackets:"
- require 'conf/wizard'
- if File.directory?( File.join( Dir.pwd, 'conf' ) )
- wizard_conf_file = File.join( Dir.pwd, 'conf', 'local_conf.yaml' )
- else
- wizard_conf_file = File.join( SERVER_PATH, 'conf', 'local_conf.yaml' )
- end
- wizard_config_data = ConfigWizard.new(config).run( wizard_conf_file )
- config.merge!( wizard_config_data )
- end
+
+ # The args structure comes from RSence::ARGVParser
+ # The dont_expand_path is for special cases, when
+ # Configuration is used without running RSence.
def initialize( args, dont_expand_path=false )
+
## Paths for log and pid files
pidpath = File.join( args[:env_path], 'run' )
logpath = File.join( args[:env_path], 'log' )
+ # The default configuration path, this one is distributed with the system.
yaml_conf_path = File.join( SERVER_PATH, 'conf', 'default_conf.yaml' )
+ # Parses the default configuration from yaml first.
+ # This is used as the basis for overriding the defaults in various other config files.
+ config = YAML.load( File.read( yaml_conf_path ) )
+
+ # The default strings for various messages, this one is distributed with the system.
yaml_strings_path = File.join( SERVER_PATH, 'conf', 'default_strings.yaml' )
strings = YAML.load( File.read( yaml_strings_path ) )
- ## Global configuration hash
- config = YAML.load( File.read( yaml_conf_path ) )
+ # Transporter-specific strings are set.
config[:transporter_conf][:messages] = strings[:messages][:transporter]
+ # Makes the distribution 'js' directory containing the client core the
+ # first client package source directory.
config[:client_pkg][:src_dirs].unshift( File.join( SERVER_PATH, 'js' ) )
+ # The distributed standard plugins are in this directory.
default_plugins_path = File.join( SERVER_PATH, 'plugins' )
unless config[:plugin_paths].include? default_plugins_path
config[:plugin_paths].push( default_plugins_path )
end
- ## Paths of server libraries
- lib_paths = [
- ## already included in launch.rb; override this one in local config, if needed
- #File.join( SERVER_PATH, 'lib' )
- ]
+ # Paths to add to $LOAD_PATH after all configuration files are read.
+ lib_paths = []
- ## Create default local configuratation override file, if it does not exist:
+ # List of configuration files to look for.
local_config_file_paths = [
File.join(SERVER_PATH,'conf','local_conf.yaml'),
'/etc/rsence/config.yaml',
File.expand_path('~/.rsence/config.yaml'),
- File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.yaml' ),
- # File.join( Dir.pwd, 'conf', 'local_conf.yaml' ),
- File.join(SERVER_PATH,'conf','local_conf.rb'),
- # File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.rb' ),
- # File.join( Dir.pwd, 'conf', 'local_conf.rb' )
+ File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.yaml' )
]
+ # Add the additional config files optionally specified in ARGVParser
args[:conf_files].each do |conf_file|
local_config_file_paths.push( conf_file )
end
+ # Loads the configuration files
local_config_file_paths.each do |local_config_file_path|
if File.exists? local_config_file_path and File.file? local_config_file_path
if local_config_file_path.end_with? '.yaml'
puts "loading config file: #{local_config_file_path}" if args[:verbose]
local_conf = YAML.load( File.read( local_config_file_path ) )
unless local_conf.class == Hash
warn "invalid configuration file: #{local_config_file_path.inspect}"
next
end
hash_merge( config, local_conf )
- elsif local_config_file_path.end_with? '.rb'
- warn "WARNING: '.rb' configuration files are deprecated!"
- # Legacy work-arounds
- prev_pidpath = PIDPATH
- prev_logpath = LOGPATH
- # /Legacy work-arounds
- load_legacy( local_config_file_path )
- # Legacy work-arounds
- pidpath = PIDPATH if PIDPATH != prev_pidpath
- logpath = LOGPATH if LOGPATH != prev_logpath
- # /Legacy work-arounds
else
- warn "Only Yaml and Ruby configuration files are allowed at this time."
+ warn "Only Yaml configuration files are supported."
end
end
end
+ # Adds the plugins directory of the environment
+ # to the configuration automatically
env_plugins_path = File.expand_path( 'plugins', args[:env_path] )
unless config[:plugin_paths].include? env_plugins_path
config[:plugin_paths].push( env_plugins_path )
end
+
+ # At this point, configuration files are read and ready.
+
puts "plugin paths: #{config[:plugin_paths].inspect}" if args[:debug]
+ # Override configuration options with command-line-options.
config[:trace] = true if args[:trace_js]
config[:debug_mode] = true if args[:debug]
config[:http_server][:latency] = args[:latency]
config[:http_server][:port] = args[:port] if args[:port]
config[:http_server][:bind_address] = args[:addr] if args[:addr]
config[:http_server][:rack_require] = args[:server] if args[:server]
config[:session_conf][:reset_sessions] = true if args[:reset_ses]
+ config[:client_pkg][:no_obfuscation] = true if args[:client_pkg_no_obfuscation]
+ config[:client_pkg][:no_whitespace_removal] = true if args[:client_pkg_no_whitespace_removal]
+
+ # Sets the default pid and log paths used by the HTTPDaemon
config[:daemon][:pid_fn] = File.join(pidpath, "rsence.pid") unless config[:daemon].has_key?(:pid_fn)
config[:daemon][:log_fn] = File.join(logpath, "rsence") unless config[:daemon].has_key?(:log_fn)
+ # Check database path for sqlite databases.
if config[:database][:ses_db].start_with?('sqlite://') and not dont_expand_path
db_url = File.expand_path( config[:database][:ses_db].split('sqlite://')[1], args[:env_path] )
config[:database][:ses_db] = "sqlite://#{db_url}"
end
- ## Broker configuration
+ # Sets the various standard url prefixes:
[ ## POST-requests
# broker_key # default_uri
# The default responder for transporter requests.
[ :x, File.join(config[:base_url],'x') ],
# The default responder for cookie-enabled "handshake" transporter requests
[ :hello, File.join(config[:base_url],'hello') ],
- # The default responder for SOAP -requests
- [ :soap, File.join(config[:base_url],'SOAP') ],
# The default responder for file uploads
[ :u, File.join(config[:base_url],'U') ],
## GET-requests
# broker_key # default_uri
@@ -197,32 +197,31 @@
].each do |broker_key, default_uri|
unless config[:broker_urls].has_key?( broker_key )
config[:broker_urls][broker_key] = default_uri
end
end
- # if RUBY_VERSION.to_f >= 1.9
- # config[:no_gzip] = true
- # end
+
+ if RUBY_VERSION.to_f >= 1.9
+ # The encodings mess up compression when using ruby1.9
+ warn "Disabling gzip support for ruby 1.9" if args[:debug]
+ config[:no_gzip] = true
+ end
+
# The default address of the index_html plugin
unless config[:index_html].has_key?(:respond_address)
config[:index_html][:respond_address] = File.join(config[:base_url])
end
- config[:client_pkg][:no_obfuscation] = true if args[:client_pkg_no_obfuscation]
- config[:client_pkg][:no_whitespace_removal] = true if args[:client_pkg_no_whitespace_removal]
-
## Uses the lib paths as search paths
+ lib_paths.merge( config[:lib_paths] ) if config.has_key?(:lib_paths)
lib_paths.each do |lib_path|
$LOAD_PATH << lib_path
end
- ## Legacy:
- LIB_PATHS.each do |lib_path|
- $LOAD_PATH << lib_path
- end
-
@config = config
end
+
attr_reader :config
+
end