diff options
author | elijah <elijah@riseup.net> | 2014-06-27 17:19:51 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-06-27 17:19:51 -0700 |
commit | 09a82209f3a40e75caf966ba41b17da1a9ced146 (patch) | |
tree | 586cfdff7b8d42736ab6559c917b9d2fce4b130c /lib | |
parent | 6da0270db08f734f2d586a0fc957875e86485549 (diff) | |
download | leap_cli-09a82209f3a40e75caf966ba41b17da1a9ced146.tar.gz leap_cli-09a82209f3a40e75caf966ba41b17da1a9ced146.tar.bz2 |
leap list improvements: lazy evaluation; don't bomb on ConfigError; remove requirements.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/leap_cli.rb | 1 | ||||
-rw-r--r-- | lib/leap_cli/commands/list.rb | 9 | ||||
-rw-r--r-- | lib/leap_cli/commands/pre.rb | 18 | ||||
-rw-r--r-- | lib/leap_cli/config/manager.rb | 10 | ||||
-rw-r--r-- | lib/leap_cli/config/object.rb | 75 | ||||
-rw-r--r-- | lib/leap_cli/exceptions.rb | 3 | ||||
-rw-r--r-- | lib/leap_cli/requirements.rb | 19 |
7 files changed, 55 insertions, 80 deletions
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb index 18a15a1..aa17655 100644 --- a/lib/leap_cli.rb +++ b/lib/leap_cli.rb @@ -9,7 +9,6 @@ require 'leap/platform' require 'leap_cli/version' require 'leap_cli/constants' -require 'leap_cli/requirements' require 'leap_cli/exceptions' require 'leap_cli/leapfile' diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb index 5b84113..be9163b 100644 --- a/lib/leap_cli/commands/list.rb +++ b/lib/leap_cli/commands/list.rb @@ -15,15 +15,15 @@ module LeapCli; module Commands c.flag 'print', :desc => 'What attributes to print (optional)' c.switch 'disabled', :desc => 'Include disabled nodes in the list.', :negatable => false c.action do |global_options,options,args| + # don't rely on default manager(), because we want to pass custom options to load() + manager = LeapCli::Config::Manager.new if global_options[:color] colors = ['cyan', 'white'] else colors = [nil, nil] end puts - if options['disabled'] - manager.load(:include_disabled => true) # reload, with disabled nodes - end + manager.load(:include_disabled => options['disabled'], :continue_on_error => true) if options['print'] print_node_properties(manager.filter(args), options['print']) else @@ -45,7 +45,6 @@ module LeapCli; module Commands properties = properties.split(',') max_width = nodes.keys.inject(0) {|max,i| [i.size,max].max} nodes.each_node do |node| - node.evaluate value = properties.collect{|prop| if node[prop].nil? "null" @@ -68,7 +67,7 @@ module LeapCli; module Commands @colors = colors end def run - tags = @tag_list.keys.sort + tags = @tag_list.keys.select{|tag| tag !~ /^_/}.sort # sorted list of tags, excluding _partials max_width = [20, (tags+[@heading]).inject(0) {|max,i| [i.size,max].max}].max table :border => false do row :color => @colors[0] do diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb index 4b62b5b..835eada 100644 --- a/lib/leap_cli/commands/pre.rb +++ b/lib/leap_cli/commands/pre.rb @@ -32,11 +32,6 @@ module LeapCli; module Commands # set verbosity # LeapCli.log_level = global[:verbose].to_i - if LeapCli.log_level > 1 - ENV['GLI_DEBUG'] = "true" - else - ENV['GLI_DEBUG'] = "false" - end # # load Leapfile @@ -68,18 +63,7 @@ module LeapCli; module Commands log_version LeapCli.log_in_color = global[:color] - # - # load all the nodes everything - # - manager - - # - # check requirements - # - REQUIREMENTS.each do |key| - assert_config! key - end - + true end private diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 1831de7..21dafd1 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -131,7 +131,15 @@ module LeapCli # apply control files @nodes.each do |name, node| control_files(node).each do |file| - node.instance_eval File.read(file), file, 1 + begin + node.eval_file file + rescue ConfigError => exc + if options[:continue_on_error] + exc.log + else + raise exc + end + end end end end diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index ef66757..cfa07cb 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -202,6 +202,10 @@ module LeapCli end end + def eval_file(filename) + evaluate_ruby(filename, File.read(filename)) + end + protected # @@ -242,45 +246,42 @@ module LeapCli # (`key` is just passed for debugging purposes) # def evaluate_ruby(key, value) - result = nil - if LeapCli.log_level >= 2 - result = self.instance_eval(value) - else - begin - result = self.instance_eval(value) - rescue SystemStackError => exc - Util::log 0, :error, "while evaluating node '#{self.name}'" - Util::log 0, "offending key: #{key}", :indent => 1 - Util::log 0, "offending string: #{value}", :indent => 1 - Util::log 0, "STACK OVERFLOW, BAILING OUT. There must be an eval loop of death (variables with circular dependencies).", :indent => 1 - raise SystemExit.new(1) - rescue FileMissing => exc - Util::bail! do - if exc.options[:missing] - Util::log :missing, exc.options[:missing].gsub('$node', self.name).gsub('$file', exc.path) - else - Util::log :error, "while evaluating node '#{self.name}'" - Util::log "offending key: #{key}", :indent => 1 - Util::log "offending string: #{value}", :indent => 1 - Util::log "error message: no file '#{exc}'", :indent => 1 - end - end - rescue AssertionFailed => exc - Util.bail! do - Util::log :failed, "assertion while evaluating node '#{self.name}'" - Util::log 'assertion: %s' % exc.assertion, :indent => 1 - Util::log "offending key: #{key}", :indent => 1 - end - rescue SyntaxError, StandardError => exc - Util::bail! do - Util::log :error, "while evaluating node '#{self.name}'" - Util::log "offending key: #{key}", :indent => 1 - Util::log "offending string: #{value}", :indent => 1 - Util::log "error message: #{exc.inspect}", :indent => 1 - end + self.instance_eval(value, key, 1) + rescue ConfigError => exc + raise exc # pass through + rescue SystemStackError => exc + Util::log 0, :error, "while evaluating node '#{self.name}'" + Util::log 0, "offending key: #{key}", :indent => 1 + Util::log 0, "offending string: #{value}", :indent => 1 + Util::log 0, "STACK OVERFLOW, BAILING OUT. There must be an eval loop of death (variables with circular dependencies).", :indent => 1 + raise SystemExit.new(1) + rescue FileMissing => exc + Util::bail! do + if exc.options[:missing] + Util::log :missing, exc.options[:missing].gsub('$node', self.name).gsub('$file', exc.path) + else + Util::log :error, "while evaluating node '#{self.name}'" + Util::log "offending key: #{key}", :indent => 1 + Util::log "offending string: #{value}", :indent => 1 + Util::log "error message: no file '#{exc}'", :indent => 1 end + raise exc if LeapCli.log_level >= 2 + end + rescue AssertionFailed => exc + Util.bail! do + Util::log :failed, "assertion while evaluating node '#{self.name}'" + Util::log 'assertion: %s' % exc.assertion, :indent => 1 + Util::log "offending key: #{key}", :indent => 1 + raise exc if LeapCli.log_level >= 2 + end + rescue SyntaxError, StandardError => exc + Util::bail! do + Util::log :error, "while evaluating node '#{self.name}'" + Util::log "offending key: #{key}", :indent => 1 + Util::log "offending string: #{value}", :indent => 1 + Util::log "error message: #{exc.inspect}", :indent => 1 + raise exc if LeapCli.log_level >= 2 end - return result end private diff --git a/lib/leap_cli/exceptions.rb b/lib/leap_cli/exceptions.rb index 27993c2..24a0fa7 100644 --- a/lib/leap_cli/exceptions.rb +++ b/lib/leap_cli/exceptions.rb @@ -6,6 +6,9 @@ module LeapCli @node = node super(msg) end + def log + Util.log(0, :error, "in node `#{@node.name}`: " + self.message) + end end class FileMissing < StandardError diff --git a/lib/leap_cli/requirements.rb b/lib/leap_cli/requirements.rb deleted file mode 100644 index f1f0952..0000000 --- a/lib/leap_cli/requirements.rb +++ /dev/null @@ -1,19 +0,0 @@ -# run 'rake update-requirements' to generate this file. -module LeapCli - REQUIREMENTS = [ - "provider.ca.name", - "provider.ca.server_certificates.bit_size", - "provider.ca.server_certificates.digest", - "provider.ca.server_certificates.life_span", - "common.x509.use", - "provider.domain", - "provider.name", - "provider.ca.server_certificates.bit_size", - "provider.ca.server_certificates.digest", - "provider.ca.name", - "provider.ca.bit_size", - "provider.ca.life_span", - "provider.ca.client_certificates.unlimited_prefix", - "provider.ca.client_certificates.limited_prefix" - ] -end |