#
# save compiled hiera .yaml files
#
- def export_nodes(destination_directory = nil)
- dir = destination_directory || Path.named_path(:hiera_dir, @provider_dir)
- existing_files = Dir.glob(dir + '/*.yaml')
+ def export_nodes
+ existing_hiera = Dir.glob(Path.named_path([:hiera, '*'], @provider_dir))
+ existing_files = Dir.glob(Path.named_path([:node_files_dir, '*'], @provider_dir))
+ updated_hiera = []
updated_files = []
- @nodes.each do |name, node|
- filepath = "#{dir}/#{name}.yaml"
+ self.each_node do |node|
+ filepath = Path.named_path([:node_files_dir, node.name], @provider_dir)
updated_files << filepath
- Util::write_file!(filepath, node.dump)
+ hierapath = Path.named_path([:hiera, node.name], @provider_dir)
+ updated_hiera << hierapath
+ Util::write_file!(hierapath, node.dump)
end
- (existing_files - updated_files).each do |filepath|
+ (existing_hiera - updated_hiera).each do |filepath|
Util::remove_file!(filepath)
end
+ (existing_files - updated_files).each do |filepath|
+ Util::remove_directory!(filepath)
+ end
end
def export_secrets(destination_file = nil)
require 'digest/md5'
require 'paint'
+require 'fileutils'
module LeapCli
end
end
+ def remove_directory!(filepath)
+ filepath = Path.named_path(filepath)
+ if filepath !~ /^#{Regexp.escape(Path.provider)}/ || filepath =~ /\.\./
+ raise "sanity check on rm -r did not pass for #{filepath}"
+ end
+ if File.directory?(filepath)
+ FileUtils.rm_r(filepath)
+ log :removed, filepath
+ end
+ end
+
def write_file!(filepath, contents)
filepath = Path.named_path(filepath)
ensure_dir File.dirname(filepath)