class Object

Public Instance Methods

encrypted_for(node) click to toggle source
# File lib/chake.rb, line 33
def encrypted_for(node)
  encrypted_files = Dir.glob("**/files/{default,host-#{node}}/*.{asc,gpg}") + Dir.glob('**/files/*.{asc,gpg}')
  encrypted_files.each_with_object({}) do |key, hash|
    hash[key] = key.sub(/\.(asc|gpg)$/, '')
  end
end
if_files_changed(node, group_name, files) { || ... } click to toggle source
# File lib/chake.rb, line 58
def if_files_changed(node, group_name, files)
  return if files.empty?

  hash_io = IO.popen(%w[xargs sha1sum], 'w+')
  hash_io.puts(File.join(Chake.tmpdir, "#{node}.bootstrap"))
  files.sort.each { |f| hash_io.puts(f) }
  hash_io.close_write
  current_hash = hash_io.read

  hash_file = File.join(Chake.tmpdir, "#{node}.#{group_name}.sha1sum")
  hash_on_disk = nil
  hash_on_disk = File.read(hash_file) if File.exist?(hash_file)

  yield if current_hash != hash_on_disk
  FileUtils.mkdir_p(File.dirname(hash_file))
  File.write(hash_file, current_hash)
end
maybe_decrypt(node) { || ... } click to toggle source
# File lib/chake.rb, line 40
def maybe_decrypt(node)
  if node.needs_upload?
    return yield
  end

  files = encrypted_for(node.hostname)
  files.each do |encrypted, target|
    sh "gpg --use-agent --quiet --decrypt --output #{target} #{encrypted}"
  end
  begin
    yield
  ensure
    files.each do |_, target|
      Chake::Wipe.instance.wipe(target)
    end
  end
end
write_json_file(file, data) click to toggle source
# File lib/chake.rb, line 76
def write_json_file(file, data)
  File.chmod(0o600, file) if File.exist?(file)
  File.open(file, 'w', 0o600) do |f|
    f.write(JSON.pretty_generate(data))
    f.write("\n")
  end
end