From 298ae98021443dabe98e6855436f24ad8ad12a99 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 9 Apr 2016 23:45:18 -0700 Subject: secrets: fix bug when secrets.json doesn't exist --- lib/leap_cli/config/environment.rb | 13 +++++++------ lib/leap_cli/config/secrets.rb | 6 +++++- lib/leap_cli/config/sources.rb | 11 +++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 lib/leap_cli/config/sources.rb diff --git a/lib/leap_cli/config/environment.rb b/lib/leap_cli/config/environment.rb index d8f34ea..3f0b3f3 100644 --- a/lib/leap_cli/config/environment.rb +++ b/lib/leap_cli/config/environment.rb @@ -32,6 +32,9 @@ module LeapCli; module Config def secrets; @@secrets; end def initialize(manager, name, search_dir, parent, options={}) + @@nodes ||= nil + @@secrets ||= nil + @manager = manager @name = name @@ -89,13 +92,11 @@ module LeapCli; module Config # shared: currently non-inheritable # load the first ones we find, and only those. # - @@nodes ||= begin - nodes = load_all_json(Path.named_path([:node_config, '*'], search_dir), Config::Node, options) - nodes.any? ? nodes : nil + if @@nodes.nil? || @@nodes.empty? + @@nodes = load_all_json(Path.named_path([:node_config, '*'], search_dir), Config::Node, options) end - @@secrets ||= begin - secrets = load_json(Path.named_path(:secrets_config, search_dir), Config::Secrets, options) - secrets.any? ? secrets : nil + if @@secrets.nil? || @@secrets.empty? + @@secrets = load_json(Path.named_path(:secrets_config, search_dir), Config::Secrets, options) end end diff --git a/lib/leap_cli/config/secrets.rb b/lib/leap_cli/config/secrets.rb index 8619b91..ca851c7 100644 --- a/lib/leap_cli/config/secrets.rb +++ b/lib/leap_cli/config/secrets.rb @@ -65,7 +65,11 @@ module LeapCli; module Config if clean self.each_key do |environment| if pinned_env.nil? || pinned_env == environment - self[environment].each_key do |key| + env = self[environment] + if env.nil? + raise StandardError.new("secrets.json file seems corrupted. No such environment '#{environment}'") + end + env.each_key do |key| unless @discovered_keys[environment] && @discovered_keys[environment][key] self[environment].delete(key) end diff --git a/lib/leap_cli/config/sources.rb b/lib/leap_cli/config/sources.rb new file mode 100644 index 0000000..aee860d --- /dev/null +++ b/lib/leap_cli/config/sources.rb @@ -0,0 +1,11 @@ +# encoding: utf-8 +# +# A class for the sources.json file +# + +module LeapCli + module Config + class Sources < Object + end + end +end -- cgit v1.2.3