Class: Chef::Knife::BriefcaseGet

Inherits:
KnifeBriefcase::Knife
  • Object
show all
Defined in:
lib/chef/knife/briefcase_get.rb

Instance Method Summary collapse

Instance Method Details

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/knife/briefcase_get.rb', line 6

def run
  encrypted = Chef::DataBagItem.load(data_bag_name, @name_args[0]).
    raw_data['content']

  begin
    crypto.verify(GPGME::Data.from_str(encrypted)) do |sig|
      if sig.valid?
        Chef::Log.info(sig.to_s)
      else
        Chef::Log.error(sig.to_s)
        exit 1                  # TODO: --force
      end
    end
  rescue
    Chef::Log.error("Cannot verify signature: #{$!}")
    exit 1
  end

  if file
    crypto.decrypt(GPGME::Data.from_str(encrypted), :output => File.open(file, 'w+'))
  else
    stdout.write(crypto.decrypt(GPGME::Data.from_str(encrypted)))
  end
rescue GPGME::Error::DecryptFailed
  Chef::Log.fatal("Decryption failed")
  exit 1
end