Skip to content
This repository has been archived by the owner on Jun 29, 2019. It is now read-only.

Commit

Permalink
more config
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydpick committed Jan 22, 2016
1 parent e125b1d commit f2eb592
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module Uphold
require 'bundler/setup'
Bundler.require(:default)

@root = File.dirname(File.expand_path(__FILE__))
Dir["#{@root}/lib/helpers/*.rb"].sort.each { |file| require file }
Dir["#{@root}/lib/*.rb"].sort.each { |file| require file }
ROOT = File.dirname(File.expand_path(__FILE__))
Dir["#{ROOT}/lib/helpers/*.rb"].sort.each { |file| require file }
Dir["#{ROOT}/lib/*.rb"].sort.each { |file| require file }

@config = Config.load_global
UPHOLD = Config.load_global

include Logging
logger.level = Logger.const_get(@config[:log_level])
logger.level = Logger.const_get(UPHOLD[:log_level])
logger.info 'Starting Uphold'

Docker.url = @config[:docker_url]
Docker.url = UPHOLD[:docker_url]
logger.debug "Docker URL - '#{Docker.url}'"
end
19 changes: 15 additions & 4 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Config
def initialize(config)
fail unless config
yaml = YAML.load_file(File.join('/etc', 'uphold', 'conf.d', config))
yaml.merge!(file: File.basename(config, '.yml'))
@yaml = Config.deep_convert(yaml)
fail unless valid?
logger.info "Loaded config '#{@yaml[:name]}' from '#{config}'"
logger.debug "Loaded config '#{@yaml[:name]}' from '#{config}'"
@yaml = supplement
end

def valid?
valid = true
valid = false if @yaml[:enabled] != true
valid = false unless Config.engines.any? { |e| e[:name] == @yaml[:engine][:type] }
valid = false unless Config.transports.any? { |e| e[:name] == @yaml[:transport][:type] }
valid
Expand All @@ -28,16 +28,27 @@ def supplement
@yaml
end

def self.load_configs
Dir['/etc/uphold/conf.d/*.yml'].sort.map do |file|
new(File.basename(file)).yaml
end
end

def self.load_global
yaml = YAML.load_file(File.join('/', 'etc', 'uphold', 'uphold.yml'))
yaml = deep_convert(yaml)
yaml[:log_level] ||= 'INFO'
yaml[:docker_url] ||= 'unix:///var/run/docker.sock'
yaml[:docker_container] ||= 'uphold-tester'
yaml[:docker_tag] ||= 'latest'
yaml[:docker_mounts] ||= []
yaml[:config_path] ||= '/etc/uphold'
yaml[:docker_log_path] ||= '/var/log/uphold'
yaml
end

def self.load_engines
[Dir["#{@root}/lib/engines/*.rb"], Dir['/etc/uphold/engines/*.rb']].flatten.uniq.sort.each do |file|
[Dir["#{ROOT}/lib/engines/*.rb"], Dir['/etc/uphold/engines/*.rb']].flatten.uniq.sort.each do |file|
require file
basename = File.basename(file, '.rb')
add_engine name: basename, klass: Object.const_get("Uphold::Engines::#{File.basename(file, '.rb').capitalize}")
Expand All @@ -56,7 +67,7 @@ def self.add_engine(engine)
end

def self.load_transports
[Dir["#{@root}/lib/transports/*.rb"], Dir['/etc/uphold/transports/*.rb']].flatten.uniq.sort.each do |file|
[Dir["#{ROOT}/lib/transports/*.rb"], Dir['/etc/uphold/transports/*.rb']].flatten.uniq.sort.each do |file|
require file
basename = File.basename(file, '.rb')
add_transport name: basename, klass: Object.const_get("Uphold::Transports::#{File.basename(file, '.rb').capitalize}")
Expand Down

0 comments on commit f2eb592

Please sign in to comment.