]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
fix bug with vanishing secrets
authorelijah <elijah@riseup.net>
Thu, 31 Jan 2013 06:25:37 +0000 (22:25 -0800)
committerelijah <elijah@riseup.net>
Thu, 31 Jan 2013 06:25:37 +0000 (22:25 -0800)
lib/leap_cli/commands/compile.rb
lib/leap_cli/config/manager.rb
lib/leap_cli/config/secrets.rb

index df2149d0a45072a813eda88bbe38e7fef584cdd2..0e645d6c6160ae0514be099405306215b546f184 100644 (file)
@@ -15,7 +15,7 @@ module LeapCli
 
       # export generated files
       manager.export_nodes(nodes)
-      manager.export_secrets
+      manager.export_secrets(nodes.nil?) # only do a "clean" export if we are examining all the nodes
     end
 
     def update_compiled_ssh_configs
index 5fc4499189c98aa1a88674175ddab647ce054a42..5a82526fdbffa3c349fa7dff268aa27264258311 100644 (file)
@@ -90,10 +90,9 @@ module LeapCli
         end
       end
 
-      def export_secrets(destination_file = nil)
+      def export_secrets(clean_unused_secrets = false)
         if @secrets.any?
-          file_path = destination_file || Path.named_path(:secrets_config, @provider_dir)
-          Util.write_file!(file_path, @secrets.dump_json + "\n")
+          Util.write_file!([:secrets_config, @provider_dir], @secrets.dump_json(clean_unused_secrets) + "\n")
         end
       end
 
index 00d0cd6d1779f2dd37c82be050be57238d3475ce..491870d338ffed559093ddb9d69ce9f7cc1cc452 100644 (file)
@@ -20,13 +20,23 @@ module LeapCli; module Config
       self[key] ||= value
     end
 
-    def dump_json
-      self.each_key do |key|
-        unless @discovered_keys[key]
-          self.delete(key)
+    #
+    # if only_discovered_keys is true, then we will only export
+    # those secrets that have been discovered and the prior ones will be cleaned out.
+    #
+    # this should only be triggered when all nodes have been processed, otherwise
+    # secrets that are actually in use will get mistakenly removed.
+    #
+    #
+    def dump_json(only_discovered_keys=false)
+      if only_discovered_keys
+        self.each_key do |key|
+          unless @discovered_keys[key]
+            self.delete(key)
+          end
         end
       end
-      super
+      super()
     end
   end