lib/leap_cli/config/secrets.rb in leap_cli-1.7.4 vs lib/leap_cli/config/secrets.rb in leap_cli-1.8

- old
+ new

@@ -25,10 +25,19 @@ else set_without_block(*args) end end + # searches over all keys matching the regexp, checking to see if the value + # has been already used by any of them. + def taken?(regexp, value, environment) + self.keys.grep(regexp).each do |key| + return true if self.retrieve(key, environment) == value + end + return false + end + def set_without_block(key, value, environment) set_with_block(key, environment) {value} end def set_with_block(key, environment, &block) @@ -54,10 +63,14 @@ def dump_json(clean=false) pinned_env = LeapCli.leapfile.environment 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 end if self[environment].empty?