Class: Chef::Knife::TarsnapKeyExport

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::Tarsnap::Core
Defined in:
lib/chef/knife/tarsnap_key_export.rb

Instance Method Summary collapse

Methods included from Chef::Knife::Tarsnap::Core

#canonicalize, #fetch_key, #fetch_node, included, #is_a_tarsnap_node?, #keygen_tool, #pending_nodes, #remove_pending_node, #tarsnap_data_bag, #tarsnap_nodes, #tarsnap_password, #tarsnap_tool, #tarsnap_username

Instance Method Details

#confirm_overwrite?(file) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chef/knife/tarsnap_key_export.rb', line 53

def confirm_overwrite?(file)
  return true if config[:yes]

  if File.exists?(file)
    stdout.print "Overwrite #{file}? (Y/N) "
    answer = stdin.readline
    answer.chomp!
    case answer
    when "Y", "y"
      true
    when "N", "n"
      self.msg("Skipping #{file}")
      false
    else
      self.msg("I have no idea what to do with #{answer}")
      self.msg("Just say Y or N, please.")
      confirm(question)
    end
  end
  true
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/knife/tarsnap_key_export.rb', line 33

def run

  begin
    Dir.mkdir(config[:directory], 0700)
  rescue Errno::EEXIST => e
    # continue...
  end

  tarsnap_nodes.each do |n|
    keyfile = File.join(config[:directory], "#{n}.key")
    if confirm_overwrite?(keyfile)
      ui.msg "Exporting #{keyfile}"
      File.write(keyfile, fetch_key(n))
    end
  end

  ui.msg "Export finished!"

end