From 8116e007cfd4dbee8282247348cf45473dcde45e Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 31 Aug 2016 14:54:46 -0700 Subject: added support for Let's Encrypt --- lib/leap_cli/config/manager.rb | 18 +++++++++++++----- lib/leap_cli/config/node_cert.rb | 4 ++-- lib/leap_cli/config/object.rb | 26 ++++++++++++++++++++++++++ lib/leap_cli/config/object_list.rb | 6 ++++++ 4 files changed, 47 insertions(+), 7 deletions(-) (limited to 'lib/leap_cli/config') diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index e39334c8..bdd5b255 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -405,15 +405,23 @@ module LeapCli end # - # returns a list of 'control' files for this node. - # a control file is like a service or a tag JSON file, but it contains - # raw ruby code that gets evaluated in the context of the node. - # Yes, this entirely breaks our functional programming model - # for JSON generation. + # Returns a list of 'control' files for this node. A control file is like + # a service or a tag JSON file, but it contains raw ruby code that gets + # evaluated in the context of the node. + # + # Yes, this entirely breaks our functional programming model for JSON + # generation. + # + # Control files are evaluated last, after everything else has run. # def control_files(node) files = [] [Path.provider_base, @provider_dir].each do |provider_dir| + # add common.rb + common = File.join(provider_dir, 'common.rb') + files << common if File.exist?(common) + + # add services/*.rb and tags/*.rb, as appropriate for this node [['services', :service_config], ['tags', :tag_config]].each do |attribute, path_sym| node[attribute].each do |attr_value| path = Path.named_path([path_sym, "#{attr_value}.rb"], provider_dir).sub(/\.json$/,'') diff --git a/lib/leap_cli/config/node_cert.rb b/lib/leap_cli/config/node_cert.rb index 64842ffa..da63d621 100644 --- a/lib/leap_cli/config/node_cert.rb +++ b/lib/leap_cli/config/node_cert.rb @@ -109,10 +109,10 @@ module LeapCli; module Config path = Path.relative_path([:commercial_cert, domain]) if cert.not_after < Time.now.utc Util.log :error, "the commercial certificate '#{path}' has EXPIRED! " + - "You should renew it with `leap cert csr --domain #{domain}`." + "You should renew it with `leap cert renew #{domain}`." elsif cert.not_after < Time.now.advance(:months => 2) Util.log :warning, "the commercial certificate '#{path}' will expire soon (#{cert.not_after}). "+ - "You should renew it with `leap cert csr --domain #{domain}`." + "You should renew it with `leap cert renew #{domain}`." end end end diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index b117c2f0..16c41999 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -153,6 +153,28 @@ module LeapCli end end + # + # works like Hash#store(key, value), but supports our nested dot notation, + # just like get() does. + # + def set(key, value) + key = key.to_s + # for keys with with '.' in them, we pop off the first part + # and recursively call ourselves. + if key =~ /\./ + keys = key.split('.') + parent_value = self.get!(keys.first) + if parent_value.is_a?(Config::Object) + parent_value.set(keys[1..-1].join('.'), value) + else + parent_value.store(keys[1..-1].join('.'), value) + end + else + self.store(key, value) + end + return nil + end + ## ## COPYING ## @@ -376,12 +398,16 @@ module LeapCli def fetch_value(key, context=@node) value = fetch(key, nil) if value.is_a?(String) && value =~ /^=/ + # strings prefix with '=' are evaluated as ruby code. if value =~ /^=> (.*)$/ value = evaluate_later(key, $1) elsif value =~ /^= (.*)$/ value = context.evaluate_ruby(key, $1) end self[key] = value + elsif value.is_a?(Proc) + # the value might be a proc, set by a 'control' file + self[key] = value.call end return value end diff --git a/lib/leap_cli/config/object_list.rb b/lib/leap_cli/config/object_list.rb index f9299a61..80f89d92 100644 --- a/lib/leap_cli/config/object_list.rb +++ b/lib/leap_cli/config/object_list.rb @@ -84,6 +84,12 @@ module LeapCli elsif operator == :not_equal && !value.include?(match_value) results[name] = config end + elsif match_value.is_a? Array + if operator == :equal && match_value.include?(value) + results[name] = config + elsif operator == :not_equal && !match_value.include?(value) + results[name] = config + end else if operator == :equal && value == match_value results[name] = config -- cgit v1.2.3