aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-01 01:07:27 -0700
committerelijah <elijah@riseup.net>2012-11-01 01:07:27 -0700
commit57287ae1d4151ec453ec9d33fafe4f1a4ced37e0 (patch)
treefe63a8de11c41d247fc3634277bc49c1ca7cd689 /lib/leap_cli/config
parentf339e7b94ab8920fd1e271c50145b5d2d1a8ac9d (diff)
downloadleap_cli-57287ae1d4151ec453ec9d33fafe4f1a4ced37e0.tar.gz
leap_cli-57287ae1d4151ec453ec9d33fafe4f1a4ced37e0.tar.bz2
x.509 support -- added certificate authority creation and server cert creation
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/manager.rb23
-rw-r--r--lib/leap_cli/config/object.rb6
2 files changed, 12 insertions, 17 deletions
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 246b79f..72958dd 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -8,7 +8,7 @@ module LeapCli
#
class Manager
- attr_reader :services, :tags, :nodes, :provider
+ attr_reader :services, :tags, :nodes, :provider, :common
##
## IMPORT EXPORT
@@ -18,11 +18,11 @@ module LeapCli
# load .json configuration files
#
def load(provider_dir=Path.provider)
- @services = load_all_json(Path.named_path( [:service_config, '*'], provider_dir ))
- @tags = load_all_json(Path.named_path( [:tag_config, '*'], provider_dir ))
- @common = load_all_json(Path.named_path( :common_config, provider_dir ))['common']
- @provider = load_all_json(Path.named_path( :provider_config, provider_dir ))['provider']
- @nodes = load_all_json(Path.named_path( [:node_config, '*'], provider_dir ))
+ @services = load_all_json(Path.named_path([:service_config, '*'], provider_dir))
+ @tags = load_all_json(Path.named_path([:tag_config, '*'], provider_dir))
+ @nodes = load_all_json(Path.named_path([:node_config, '*'], provider_dir))
+ @common = load_json(Path.named_path(:common_config, provider_dir))
+ @provider = load_json(Path.named_path(:provider_config, provider_dir))
Util::assert!(@provider, "Failed to load provider.json")
Util::assert!(@common, "Failed to load common.json")
@@ -105,10 +105,10 @@ module LeapCli
private
- def load_all_json(pattern, config_type = :class)
+ def load_all_json(pattern)
results = Config::ObjectList.new
Dir.glob(pattern).each do |filename|
- obj = load_json(filename, config_type)
+ obj = load_json(filename)
if obj
name = File.basename(filename).sub(/\.json$/,'')
obj['name'] ||= name
@@ -118,9 +118,7 @@ module LeapCli
results
end
- def load_json(filename, config_type)
- #log2 { filename.sub(/^#{Regexp.escape(Path.root)}/,'') }
-
+ def load_json(filename)
#
# read file, strip out comments
# (File.read(filename) would be faster, but we like ability to have comments)
@@ -133,9 +131,8 @@ module LeapCli
end
end
- # parse json, and flatten hash
+ # parse json
begin
- #hash = Oj.load(buffer.string) || {}
hash = JSON.parse(buffer.string, :object_class => Hash, :array_class => Array) || {}
rescue SyntaxError => exc
log0 'Error in file "%s":' % filename
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index e044353..06a4fef 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -79,8 +79,6 @@ module LeapCli
end
elsif self.has_key?(key)
evaluate_value(key)
- elsif @node != self
- @node.get!(key)
else
raise NoMethodError.new(key, "No method '#{key}' for #{self.class}")
end
@@ -110,7 +108,7 @@ module LeapCli
#
def deep_merge!(object)
object.each do |key,new_value|
- old_value = self[key]
+ old_value = self.fetch key, nil
if old_value.is_a?(Hash) || new_value.is_a?(Hash)
# merge hashes
value = Config::Object.new(@manager, @node)
@@ -152,7 +150,7 @@ module LeapCli
else
if value =~ /^= (.*)$/
begin
- value = eval($1, self.send(:binding))
+ value = eval($1, @node.send(:binding))
self[key] = value
rescue SystemStackError => exc
puts "STACK OVERFLOW, BAILING OUT"